Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream in("moka.in");
  6.  
  7. ofstream out("moka.out");
  8.  
  9.  
  10. unsigned long long puterel(unsigned long long a, unsigned long long b)
  11.  
  12. {
  13. unsigned long long z[1001],p=a,i,c=0;
  14.    
  15.    while(b)
  16.           {
  17.        
  18.                z[++c]=b%2;
  19.        
  20.                if(b%2==1)
  21.            
  22.                        b--;
  23.        
  24.                else
  25.                        b/=2;
  26.            
  27.            }
  28.    
  29.       for(i=c-1;i>=1;i--)
  30.        
  31.        {
  32.            
  33.                if(z[i]==1)
  34.                
  35.                    p=(p%1999999973*a%1999999973)%1999999973;
  36.            
  37.                else
  38.                           p=(p%1999999973)*(p%1999999973)%1999999973;
  39.            }
  40.     return p;
  41.    
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
  48. int main()
  49.  
  50. {
  51.    
  52.        unsigned long long x,y,c;
  53.    
  54.        in>>x>>y;
  55.    
  56.        c=puterel(x,y);
  57.    
  58.        out<<c;
  59.    
  60.        return 0;
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement