仅供参考
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
static int N = 10000005;
static int[] next = new int[N];
public static void main(String[] args) throws IOException {
int t = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (t > 0) {
int n = Integer.parseInt(br.readLine());
if (n == 0) {
break;
}
String s = br.readLine();
char[] ch = new char[n + 1];
for (int i = 1; i <= n; i++) ch[i] = s.charAt(i - 1);
for (int i = 2, j = 0; i <= n; ++i) {
while (j != 0 && ch[i] != ch[j + 1]) j = next[j];
if (ch[i] == ch[j + 1]) j++;
next[i] = j;
}
System.out.printf("Test case #%d\n", t++);
for (int i = 2; i <= n; ++i) {
int j = i - next[i];
if (i > j && i % j == 0) System.out.println(i + " " + i / j);
}
System.out.println();
}
}
}