(http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105595#problem/G)
题意:寻找最小循环节
解法:后缀数组,KMP都能做,比较懒,只写了KMP的版本。。。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <queue>
//#include <tr1/unordered_set>
//#include <tr1/unordered_map>
#include <bitset>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define inf 1e9
#define debug(a) cout << #a" = " << (a) << endl;
#define debugarry(a, n) for (int i = 0; i < (n); i++) { cout << #a"[" << i << "] = " << (a)[i] << endl; }
#define clr(x, y) memset(x, y, sizeof x)
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) \
for(i=a;a<b?i<=b:i>=b;a<b?i++:i--)
const int maxn = 1000000+100;
char s[maxn];
int f[maxn],len;
void getFail()
{
char *P=s;
int m=len;
f[0]=f[1]=0;
for(int i=1;i<m;i++)
{
int j=f[i];
while(j&&P[i]!=P[j]) j=f[j];
f[i+1] = P[i]==P[j]?j+1:0;
}
}
int main()
{
//freopen("input.txt","r",stdin);
while(~scanf("%s",s))
{
if(strcmp(s,".")==0) break;
len=strlen(s);
getFail();
int ans=1;
int j = f[len];
while(j)
{
if( len%(len-j)==0 )
ans = max(ans , len/(len-j) );
// debug(j);
j=f[j];
}
printf("%d\n",ans);
}
return 0;
}