-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrefix_Function.cpp
More file actions
61 lines (55 loc) · 1.08 KB
/
Copy pathPrefix_Function.cpp
File metadata and controls
61 lines (55 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <cstring>
#include <iomanip>
#include <map>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <vector>
#include <new>
#include <bitset>
#include <ctime>
#include <cassert>
#include <stdint.h>
#include <unistd.h>
using namespace std;
#define ll long long int
#define INF 1000000000
#define PI acos(-1.0)
#define EPS 1e-9
template <typename X> X gcd(X a, X b){if(!b)return a; else return gcd(b, a%b);}
typedef vector<int> vi;
typedef pair<int, int> ii;
const int N = 1e6 + 10 ;
int t, l, i, j, cs = 1, p[N] ;
char s[N];
int main() {
scanf("%d", &t);
while( t-- ) {
scanf("%d", &l);
getchar();
gets(&s[1]);
p[1] = 0;
i = 2, j = 0;
while ( i <= l ) {
while( j > 0 && s[j + 1] != s[i] )
j = p[j];
if( s[j + 1] == s[i] )
++j;
p[i] = j;
++i;
}
printf("Test case #%d\n", cs++);
for( i = 1; i <= l; ++i )
if( p[i] > 0 && i % (i - p[i]) == 0 )
printf("%d %d\n", i, i / ( i - p[i]));
putchar('\n');
}
return 0;
}