Redirecting to

Find String Roots

In mathematics, the N-th root of a number M, is a number K such that K^N=M, i.e. KKK...K=M where k is multiplied N times.
Given a string S you have to find the maximum N such that the N-th root of S exists.
For ex :
If S= "sumsumsumsum", for N=2 the string T="sumsum" is the N-th root of S, While for N=4 its N-th root is T= "sum".
The actual answer would be 4, because there is no N-th root of S="sumsumsumsum" for N>4.

Note that for N=1 any string S is the N-th root of itself.
Input Format
One line containing a non empty string S.
Output Format
Output a single line with the greatest integer N such that there exists a string T that concatenated N times is equal to S.
Question Video
1<= length of string <= 10^5
Sample Input
Sample Output

  • Asked in Companies
  • Related Topics

Video Solution

Code Solution

Id Name