大意:跟poj2406一样的题 思路见http://www.cnblogs.com/zhanzhao/p/4761477.html
代码:

1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 using namespace std;
5
6 const int maxn = 1000005;
7
8 int next[maxn];
9
10 void get(char *s) {
11 int l = strlen(s);
12 int j = 0, k = -1;
13 next[0] = -1;
14 while(j < l) {
15 if(k == -1 || s[j] == s[k]) {
16
17
18
19 // if(s[++j] == s[++k]) {
20 // next[j] = next[k];
21 // } else {
22 // next[j] = k;
23 // }
24 next[++j] = ++k;
25 } else {
26 k = next[k];
27 }
28 }
29 }
30 char s[maxn];
31
32 int main() {
33 int n;
34 int kase = 1;
35 while(scanf("%d",&n) && n) {
36 scanf("%s",s);
37 printf("Test case #%d\n", kase++);
38 get(s);
39 int l = strlen(s);
40 // for(int i = 0; i <= l; i++) {
41 // printf("%d ", next[i]);
42 // }puts("");
43 for(int i = 2; i <= l; i++) {
44 int ans = 1;
45 if(i % (i - next[i]) == 0) {
46 ans = i / (i - next[i]);
47 }
48 if(ans > 1) {
49 printf("%d %d\n", i, ans);
50 }
51 }
52 puts("");
53 }
54 }
来源:https://www.cnblogs.com/zhanzhao/p/4761549.html
