#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define ss(x) scanf("%d",&x)
const int maxn=1000000+5;
char s[maxn];
int f[maxn];
int n;
int main()
{
while(true)
{
scanf("%s",s);
if(s[0]=='.') break;
int n=(int)strlen(s);
f[0]=f[1]=0;
rep(i,1,n-1){
int j=f[i];
while(j&&s[i]!=s[j]) j=f[j];
f[i+1]=(s[i]==s[j])?j+1:0;
}
int ans=1;
if(f[n]&&n%(n-f[n])==0) ans=n/(n-f[n]);
printf("%d\n",ans==0?1:ans);
}
return 0;
}
POJ 2406 Power Strings(KMP循环节)
最新推荐文章于 2020-07-27 11:12:39 发布