Advertisement
rotti321

porumbei [90p] pbinfo.ro

May 23rd, 2017
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. int n,a;
  5. long long r=1;
  6. bitset<2000002> rr;
  7. ifstream f("porumbei.in");
  8. ofstream g("porumbei.out");
  9. stack<pair<int,int>> st;
  10. int main()
  11. {
  12.     f>>a>>n;
  13.  
  14.     for(int i=1;i<=n;i++){
  15.         r = (r*a)%n;  ///sume part
  16.       ///  cout<<i<<" r="<<r<<endl;
  17.         if(r==1){
  18.             g<<"0 "<<i<<endl;
  19.             return 0;
  20.  
  21.         }
  22.         else{
  23.             if(rr[(int)r]!=0){
  24.                 int ok=1;
  25.                 pair<int,int> elem;
  26.                 while(!st.empty() && ok){
  27.                     elem=st.top();
  28.                     //cout<<elem.first<<" "<<elem.second<<endl;
  29.                     if(elem.first==(int)r){
  30.                         ok=0;
  31.                     }
  32.                     st.pop();
  33.                 }
  34.                 g<<elem.second<<" "<<i;
  35.                 return 0;
  36.             }
  37.             else{
  38.                 rr[r]=1;
  39.                 st.push(make_pair((int)r,i));
  40.             }
  41.         }
  42.     }
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement