Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <iomanip>
- #include <vector>
- #include <map>
- #include <algorithm>
- #include <string>
- #include <cmath>
- #include <set>
- #include <unordered_set>
- #include <stack>
- #include <cassert>
- #include <queue>
- #include <deque>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- //const int inf=1e9+1329;
- //#define int long long
- //для одной строки
- const ll MOD_1=1e9+1329;
- const ll MOD_2=1e9-239;
- const ll BASE_1=239;
- const ll BASE_2=1329;
- vector<ll> base_pow_1;
- vector<ll> base_pow_2;
- vector<ll> h_1;
- vector<ll> h_2;
- string s;
- void precalc(){
- int n=(int)s.size();
- base_pow_1.resize(n+1);
- base_pow_2.resize(n+1);
- h_1.resize(n+1);
- h_2.resize(n+1);
- base_pow_1[0]=1;
- base_pow_2[0]=1;
- h_1[0]=0;
- h_2[0]=0;
- for(int i=0;i<n;i++){
- h_1[i+1]=(h_1[i] * BASE_1 + (s[i] - 'a')) % MOD_1;
- h_2[i+1]=(h_2[i] * BASE_2 + (s[i] - 'a')) % MOD_2;
- base_pow_1[i+1]=(base_pow_1[i] * BASE_1) % MOD_1;
- base_pow_2[i+1]=(base_pow_2[i] * BASE_2) % MOD_2;
- }
- return;
- }
- ll get_hash_1(int l,int r){
- return h_1[r] - h_1[l] * base_pow_1[r-l];
- }
- ll get_hash_2(int l,int r){
- return h_2[r] - h_2[l] * base_pow_2[r-l];
- }
- bool equal(int fl,int fr,int sl,int sr){
- if(fr-fl!=sr-sl){
- return false;
- }
- ll tmp_1=get_hash_1(fl, fr) - get_hash_1(sl, sr);
- ll tmp_2=get_hash_2(fl, fr) - get_hash_2(sl, sr);
- return tmp_1%MOD_1==0 && tmp_2%MOD_2==0;
- }
- vector<int> slv(string cur){
- vector<int> ans;
- s=cur;
- precalc();
- int n=s.size();
- vector<int> fact;
- for(int i=1;i<=n;i++){
- if(n%i==0){
- fact.push_back(i);
- }
- }
- for(auto cur:fact){
- bool fl=1;
- for(int i=0;i+1<n/cur;i++){
- if(!equal(cur*i,cur*(i+1),cur*(i+1),cur*(i+2))){
- fl=0;
- }
- }
- if(fl){
- ans.push_back(cur);
- }
- }
- return ans;
- }
- //
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement