getting test case 3 and 4 wrong
Getting test case 3 and 4 wrong
still getting wrong answer
#include
using namespace std;
long long int p(long long int a,long long int b,long long int c){
if(b==0){
return 1;
}
else if( b==1){
return a%c;
}
else if (b%2==0){
return (((p(a,b/2,c)%c)*(p(a,b/2,c))%c))%c;
}
else if(b%2==1){
return (((p(a,(b-1)/2,c)%c)*((p(a,(b-1)/2,c)%c))*a%c))%c;
}
return 0;}
int main(){
int t;
cin>>t;
while(t–){
long long int a,b,c;
cin>>a>>b>>c;
long long int ans=a%c;
for(long long int i=1;i<=b;i++){
ans=p(ans,i,c);
}
cout<<ans<<endl;}
}
@coe17b014 just replaced the power function in your code.
(used fast power iterative way , you were using recursive fast power way which is a little slower than iterative one because of recursion thats why it leads to tle(constraints too tight))
dont forget to hit like and mark resolved if cleared
1 Like