String Algorithms (KMP, Z, Rolling Hash, Trie)
You are given a string s. Find the smallest length p such that p divides |s| and s is the first p characters repeated |s| / p times. If no shorter unit exists, the answer is |s|.
One line: the string s.
Print one integer: the smallest such length p.
1 <= |s| <= 1000000 Only lowercase letters a to z.
1000 ms256 MB
abcabcabc
3
The string is abc repeated three times.
abcabcab
8
The string is not a whole number of repeats of anything shorter.