fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll ;
  5. const int MAX = 100000;
  6. const int MOD = 1000000007; // 10^9 + 7 really big prime number
  7.  
  8. int bem(ll a , ll n , ll MOD){ //binary exponentiation with mod
  9. if (n==0) return 1 % MOD ;
  10. int half = bem(a,n/2,MOD) % MOD;
  11. ll res;
  12. if(n%2==0){
  13. res = (half*half)%MOD;
  14. }
  15. else{
  16. res = (a*half*half)%MOD;
  17.  
  18. }
  19. return res;
  20. }
  21.  
  22. int main(){
  23.  
  24. cout<<bem(3,4,MOD);
  25. return 0 ;
  26.  
  27.  
  28. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
81