kmp,根据next数组的性质如果有答案的话就是n/(n-(ne[n]+1)),否则是1
搬来打算用SA后来发现必须用DC3就没写
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1000005;
int n,ne[N];
char s[N];
int main()
{
while(scanf("%s",s)&&s[0]!='.')
{
n=strlen(s);
ne[0]=-1;
for(int i=1,j=-1;i<n;i++)
{
while(j!=-1&&s[i]!=s[j+1])
j=ne[j];
if(s[i]==s[j+1])
j++;
ne[i]=j;
}
ne[n]=ne[n-1]+1;
if(n%(n-ne[n])==0)
printf("%d
",n/(n-ne[n]));
else
puts("1");
}
return 0;
}