Each test case is a line of input representing s, a string of printable characters. For each s you should print the largest n such that s = a^n for some string a. The length of s will be at least 1 and will not exceed 1 million characters. A line containing a period follows the last test case.
Sample Input
abcd aaaa ababab .
Output for Sample Input
1 4 3
#include<stdio.h>
ResponderEliminar#include<string.h>
long a[1000005],i,j,n,l;
char cd[1000002];
int main(){
a[0]=-1;
while(gets(cd)){
if(cd[0]=='.')
break;
l=strlen(cd);
j=0;
for(i=1;i<l;i++){
while(j!=-1){
if(cd[i]==cd[j]){
j++;
break;
}else{
j=a[j];
}
}
if(j==-1)
j++;
a[i+1]=j;
}
n=l-a[l];
if(n>0){
n=l/n;
printf("%ld\n",n);
}else if (l==2&&cd[0]==cd[1]){
printf("2\n");
}else{
printf("1\n");
}
}
}