Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. // #include <boost/math/common_factor.hpp>
  2. unsigned long long gcd(long long a, long long b){
  3. if (a == 0)
  4. return b;
  5. return gcd(b % a, a);
  6. };
  7.  
  8. unsigned long long lcm(long long a, long long b)
  9. {
  10. return a * b/gcd(a, b);
  11. };
  12.  
  13. int Solution::solve(vector<string> &A) {
  14.  
  15. unsigned long long ans=1;
  16. // unsigned long long M = 10000007;
  17. for(long long i=0; i<A.size(); i++){
  18.  
  19. string temp = A[i];
  20. bool found = false;
  21. unsigned long long r = 0;
  22. // cout<<temp<<"\n";
  23. for(unsigned long long t=1; t<=1e9; t++){
  24.  
  25. // rotated = rotate(temp,t);
  26. // cout<<t;
  27. string output=temp;
  28. r = ((t * (t+1))/2) % 1000000007;
  29. r = r % temp.length();
  30.  
  31. for(long long j=0; j<temp.length(); j++){
  32. output[j] = temp[((r+j) % temp.length())];
  33. }
  34. // cout<<output<<"=="<<temp<<"--"<<t<<","<<r<<"--";
  35. if(output == temp){
  36. found = true;
  37. // cout<<t;
  38. ans = lcm(ans,t);
  39. // if( (t % ans) ==0){
  40. // ans = t;
  41. // }
  42. // else if( (ans % t) == 0){
  43. // ans=ans;
  44. // }
  45. // else{
  46. // // ans = ((ans % M) * (t %M)) % M;
  47. // ans = (ans * t) % 1000000007;
  48. // }
  49. // cout<<"\n";
  50. break;
  51. }
  52. }
  53. }
  54.  
  55.  
  56. return ans % 1000000007;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement