Advertisement
Infernale

Ancient Building (FME)

Oct 27th, 2018
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.50 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long long FME(int base, int power, int mod){
  4.     if(base==0){
  5.         return 0;
  6.     }
  7.     if(power==0){
  8.         return 1;
  9.     }
  10.     long long res;
  11.     if(power%2==0){
  12.         res = FME(base, power/2, mod);
  13.         res = (res*res)%mod;
  14.     }else{
  15.         res = base%mod;
  16.         res = (res*FME(base, power-1, mod)%mod)%mod;
  17.     }
  18.     return ((res+mod)%mod);
  19. }
  20.  
  21. int main(){
  22.     int tc;
  23.     scanf("%d",&tc);
  24.     while(tc--){
  25.         int a,b;
  26.         scanf("%d %d",&a,&b);
  27.         printf("%lld\n", FME(2,a,1000000007)*FME(3,b,1000000007)%1000000007);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement