Subtask 3 giving TLE
Problem link -> https://www.codechef.com/problems/FEXP
My Code
#include <stdio.h>
#define mod 1000000007
long power(long,long);
int main(){
int t;
scanf("%d",&t);
while(t--){
long a,b;
scanf("%ld%ld",&a,&b);
printf("%ld\n",power(a,b));
}
}
long power(long a,long b){
if(b==0)
return 1;
long res = power(a%mod,((b%mod)/2))%mod;
res = ((res%mod)*(res%mod))%mod;
if(b&1)
return res = ((res%mod) * (a%mod))%mod;
return res%mod;
}