Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #include <boost/math/common_factor.hpp>
- unsigned long long gcd(long long a, long long b){
- if (a == 0)
- return b;
- return gcd(b % a, a);
- };
- unsigned long long lcm(long long a, long long b)
- {
- return a * b/gcd(a, b);
- };
- int Solution::solve(vector<string> &A) {
- unsigned long long ans=1;
- // unsigned long long M = 10000007;
- for(long long i=0; i<A.size(); i++){
- string temp = A[i];
- bool found = false;
- unsigned long long r = 0;
- // cout<<temp<<"\n";
- for(unsigned long long t=1; t<=1e9; t++){
- // rotated = rotate(temp,t);
- // cout<<t;
- string output=temp;
- r = ((t * (t+1))/2) % 1000000007;
- r = r % temp.length();
- for(long long j=0; j<temp.length(); j++){
- output[j] = temp[((r+j) % temp.length())];
- }
- // cout<<output<<"=="<<temp<<"--"<<t<<","<<r<<"--";
- if(output == temp){
- found = true;
- // cout<<t;
- ans = lcm(ans,t);
- // if( (t % ans) ==0){
- // ans = t;
- // }
- // else if( (ans % t) == 0){
- // ans=ans;
- // }
- // else{
- // // ans = ((ans % M) * (t %M)) % M;
- // ans = (ans * t) % 1000000007;
- // }
- // cout<<"\n";
- break;
- }
- }
- }
- return ans % 1000000007;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement