寻找循环节其实就是KMP中的NEXT数组的后缀在当前字符串中有多少重循环
//5028K 157MS
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
#define MAX_N 1000007
static char mol[MAX_N];//模式串
static void initNext(int*NEXT)
{
int p=0,q= -1;
NEXT[0] = -1;
int n = strlen(mol);
while(p<n)
{
if (q==-1||mol[p]==mol[q])
{
NEXT[++p] = ++q;
}
else
q = NEXT[q];
}
}
int main()
{
while(~scanf("%s",mol))
{
if (strcmp(mol,".")==0)
break;
int n = strlen(mol);
int NEXT[MAX_N]={};
int ans = 1;
initNext(NEXT);
int length = n - NEXT[n];
if (n!=length&&n%length==0)
ans = n/length;
printf("%d\n",ans);
}
return 0;
}