1 /*
2 题意:求一个串重复出现(>1)的位置
3 KMP:这简直和POJ_2406没啥区别
4 */
5 /************************************************
6 * Author :Running_Time
7 * Created Time :2015-8-10 9:13:24
8 * File Name :POJ_1961.cpp
9 ************************************************/
10
11 #include <cstdio>
12 #include <algorithm>
13 #include <iostream>
14 #include <sstream>
15 #include <cstring>
16 #include <cmath>
17 #include <string>
18 #include <vector>
19 #include <queue>
20 #include <deque>
21 #include <stack>
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <bitset>
26 #include <cstdlib>
27 #include <ctime>
28 using namespace std;
29
30 #define lson l, mid, rt << 1
31 #define rson mid + 1, r, rt << 1 | 1
32 typedef long long ll;
33 const int MAXN = 1e6 + 10;
34 const int INF = 0x3f3f3f3f;
35 const int MOD = 1e9 + 7;
36 int n;
37 int nex[MAXN];
38 char str[MAXN];
39
40
41 void get_nex(void) {
42 int i = 0, j = -1; nex[0] = -1;
43 while (i < n) {
44 if (j == -1 || str[j] == str[i]) {
45 j++; i++;
46 if (i % (i - j) == 0 && i / (i - j) > 1) {
47 printf ("%d %d\n", i, i / (i - j));
48 }
49 nex[i] = j;
50 }
51 else j = nex[j];
52 }
53 }
54
55 int main(void) { //POJ 1961 Period
56 int cas = 0;
57 while (scanf ("%d", &n) == 1) {
58 if (!n) break;
59 scanf ("%s", &str);
60 printf ("Test case #%d\n", ++cas);
61 get_nex ();
62 puts ("");
63 }
64
65 return 0;
66 }