// 2360--最多子串重复次数
// 来源:东方博宜oj oj.czos.cn
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,P=131;
typedef unsigned long long ULL;
ULL h[N],p[N];
char s[N];
ULL get(int l,int r)
{
return h[r]-h[l-1]*p[r-l+1];
}
void gethash()
{
int len=strlen(s+1);
p[0]=1;
for(int i=1; i<=len; i++)
{
p[i]=p[i-1]*P;
h[i]=h[i-1]*P+(s[i]-'a'+1);
}
}
int main()
{
while(scanf("%s",s+1)&&s[1]!='.')
{
gethash();
int len=strlen(s+1);
for(int i=1; i<=len; i++) // i表示当前段长度
{
if(len%i==0)
{
ULL t=h[i];
bool f=true;
for(int j=i+1; j<=len; j+=i) //每个j都是每段区间的第一个数
{
if(get(j,j+i-1)!=t)
{
f=false;
break;
}
}
if(f==true)
{
printf("%d\n",len/i);
break;
}
}
}
}
return 0;
}
2360--最多子串重复次数---字符串哈希
于 2023-02-13 18:47:52 首次发布