fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define LL long long int
  4.  
  5.  
  6. LL pow(LL a, LL b, LL mod) {
  7. LL x = 1, y = a;
  8. while(b > 0) {
  9. if(b%2 == 1) {
  10. x=(x*y);
  11. if(x>mod) x%=mod;
  12. }
  13. y = (y*y);
  14. if(y>mod) y%=mod;
  15. b /= 2;
  16. }
  17. return x;
  18. }
  19. int main()
  20. {
  21. LL A,B,MOD=1000000007;
  22. cin>>A>>B;
  23. cout<<pow(A,B,MOD)<<endl;
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0s 15240KB
stdin
2 3
stdout
8