For starters, that code isn't right, because it doesn't take into account the fact that your "string" is cyclic.
I tested the code with about 20 different inputs (S string) and it has given me the right answer each time, could you give me an example that the code might not work for.. Maybe I'm thinking in just one direction. I'm not shifting the string to check if it is cyclic or not, I'm doing something similar to what you asked in question 1 to which I think the answer would be N-1 worst case scenario.
Basically here's what i designed the code to do:
It gets all the factors of string length (let's take 'abcabc' as an example, it'll return 1, 2, 3 and 6)
Now we start with 1, the first factor, so the code compares 'a' to 'b' and since they are different 1 is eliminated.
Next factor is 2, so the code compares 'ab' to 'ca' and since they are different 2 is eliminated.
Next factor is 3, so we compare 'abc' to 'abc', match is found and since we have reached the end of the string we have an answer which is string length divided by 3.. So final answer is 2, which is the right answer .
(If there were 3 more characters say 'abcabcxxx', 'abc' would have been compared again to xxx and answer printed only if it were a match otherwise the code would have moved on to the next factor)
I hope it makes sense, it would be a big help if you gave an example for which the code might not work except empty string, I haven't tested for it.