最小覆盖子串长度为n-next[n] ,n为字符串长度。如果恰好覆盖就为n/(n-next[n]),否则为1.
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char name[1000010];
int nex[1000010];
void getnext()
{
memset(nex,0,sizeof(nex));
nex[0]=-1;
int j=-1,k=0;
int len=strlen(name);
while(k<len)
{
if(j==-1||name[j]==name[k])
{
j++;k++;
nex[k]=j;
}
else
j=nex[j];
}
}
int main()
{
while(scanf("%s",name),strcmp(".",name)!=0)
{
getnext();
int l=strlen(name);
if(l%(l-nex[l])==0)
printf("%d\n",l/(l-nex[l]));
else
printf("1\n");
}
return 0;
}