#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
const int N = 1000010;
char p[N];
int ne[N];
void solve()
{
//谷子评测出了点问题,用acwing做的,读入上稍有修改
int n;
int cnt = 0;
while(cin>>n,n)
{
cnt++;
scanf("%s",p+1);
cout<<"Test case #"<<cnt<<'\n';
ne[1] = 0;
for(int i=2,j=0;i<=n;++i)//此处p的子匹配需要错位开始i=2
{
while(j&&p[j+1]!=p[i]) j=ne[j];//j+1是上一次循环的j,i会自增
if(p[i]==p[j+1]) j++;//如果匹配成功j增加1
ne[i]=j;
}
for(int i=2;i<=n;++i)
{
if(ne[i])
{
int T = i-ne[i];
//T是周期但不一定是循环元
if(i%T==0&&i/T>1)
{
cout<<i<<' '<<i/T<<'\n';
}
}
}
cout<<'\n';
}
}
int main()
{
solve();
}
标签:typedef,return,int,PERIOD,long,vector,kmp,vx,border
From: https://www.cnblogs.com/ruoye123456/p/18413415