注意判断剩下的一节是否能够被n整除
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
const int maxn=1000010;
int next[maxn],n;
char s[maxn];
void get_next()
{
int j=0,k=-1;
next[0]=-1;
while(j<=n)
{
if(k==-1||s[j]==s[k])
{
j++;k++;
next[j]=k;
}
else k=next[k];
}
}
int main() {
while(~scanf("%s",s))
{
if(s[0]=='.')break;
n=strlen(s);
get_next();
if(n%(n-next[n])==0)//判断是否能被n整除
printf("%d\n",n/(n-next[n]));
else printf("1\n");
}
return 0;
}