Advertisement
_rashed

SPOJ PERIOD

Jul 25th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. int main()
  9. {
  10.     ios_base::sync_with_stdio(NULL);
  11.     cin.tie(0);
  12.     cout.tie(0);
  13.     int t;
  14.     cin >> t;
  15.     for(int ti = 1; ti <= t; ti++) {
  16.         int n;
  17.         cin >> n;
  18.         string s;
  19.         cin >> s;
  20.         vector<int> f(s.length());
  21.         cout << "Test case #" << ti << "\n";
  22.         for(int i = 1, k = 0; i < s.length(); i++) {
  23.             while(k > 0 && s[k] != s[i]) {
  24.                 k = f[k-1];
  25.             }
  26.             f[i] = (s[i] == s[k] ? ++k:k);
  27.             //cout << "f[" << i << "] = " << f[i] << "\n";
  28.             if(f[i]*2 >= i+1 && !((i+1)%(i+1 - f[i]))) {
  29.                 cout << i+1 << " " << (i+1)/(i+1 - f[i]) << "\n";
  30.             }
  31.         }
  32.         cout << "\n";
  33.     }
  34.     return 0;
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement