HDU 1358
大同小异
#include <iostream>
#include "stdio.h"
#include <string.h>
#include <cstring>
using namespace std;
#define n 1000010
int next[n],l;
char s[n];
void getNext(){
int j,k;
next[0]=-1;
j=0;
k=-1;
while(j<l){
if(k==-1||s[j]==s[k]) {
j++;
k++;
next[j]=k;
}
else
k=next[k];
}
//for(int i=1;i<=l;i++)cout<<next[i]<<endl;
}
int main(){
int game=0;
while(scanf("%d",&l)!=EOF){
if(l==0)break;
game++;
scanf("%s",s);
getNext();
printf("Test case #%d\n",game);
/*for(int i=2;i<k;i++){
if(i%(i-next[i])==0)
printf("%d %d\n",i,i/(i-next[i]));
}
int j=1;
for(int i=k+k;i<=l;i+=k){
printf("%d %d\n",i,j+1);
j++;
}*/
for(int i=1;i<l;i++)
{
if(next[i+1]!=0&&(i+1)%(i+1-next[i+1])==0)
{
printf("%d %d\n",i+1,(i+1)/(i+1-next[i+1]));
}
}
printf("\n");
}
return 0;
}