Hdu1358
The next array stores the length of the prefix suffix + 1 with the longest I-bit characters in the String.
I-next [I] indicates the length of the loop section in the first I bit.
[Cpp]
# Include <iostream>
# Include <cstdio>
Using namespace std;
Char T [1000010]; www.2cto.com
Int next [1000010];
Int N, M;
Void GetNext ()
{
Int I = 1, j = 0; next [1] = 0;
While (I <= N)
{
If (j = 0 | T [I] = T [j])
{
++ I; ++ j;
Next [I] = j;
}
Else j = next [j];
}
}
Int main ()
{
Int t = 1, I, j, num, k;
While (scanf ("% d", & N) & N! = 0)
{
Scanf ("% s", T + 1 );
GetNext ();
// For (I = 0; I <= N; I ++) printf ("% d", next [I]); printf ("\ n ");
// For (I = 0; I <= N; I ++) printf ("% d", I-next [I]); printf ("\ n ");
Printf ("Test case # % d \ n", t ++ );
For (I = 3; I <= N + 1; I ++)
{
Int Y = (I-1)/(I-next [I]);
If (I-1) % (I-next [I]) = 0 & Y> 1) printf ("% d \ n", I-1, Y );
}
Printf ("\ n ");
}
Return 0;
}