If P [1... k] and P [L-k + 1... l] match (L is the string length), then P [L-k + 1... l] This character must be repeated in P [1... l]-P [L-K + 1... l.
Proof Method: if this section is not repeated, P [1... K] and P [L-k + 1... L] cannot match. You can try drawing.
Note that the starting position of the string is 0. The following code is used:
# Include <stdio. h> # include <string. h> # define maxn 1000500 char s [maxn]; int next [maxn]; int n; void kmp_next (char * s, int len) {int I = 0; int j =-1; next [0] =-1; while (I <len) {while (j> = 0 & s [I]! = S [j]) j = next [j]; I ++; j ++; next [I] = j ;}} int main () {int T = 0; while (scanf ("% d", & n) {T ++; scanf ("% s", s); int len = strlen (s ); kmp_next (s, len); printf ("Test case # % d \ n", T); for (int I = 2; I <= len; I ++) {if (next [I]! = 0 & I % (I-next [I]) = 0) printf ("% d \ n", I, i/(I-next [I]);} printf ("\ n");} return 0 ;}