Test Cases Failed

#include
using namespace std;

int main() {

int a,b,c;
cin>>a>>b>>c;

long long ans=1;

while(b>0)
{
   if(b&1)
      ans*=a%c;
   a=a*a;
   b>>=1;
}
cout<<ans%c;
return 0;

}

why my code not passing all test cases ?
plzz mnetion the test cases where my code failed

hey @Pramod123 you are not doing modulo correctly and a, b, c needs to be long long,
instead of ans*=a%c; you should have written ans=(ans*a)%c; and when you do a^2 you need to take modulo, here is your code after rectification

#include using namespace std; int main() { long long a,b,c; cin>>a>>b>>c; long long ans=1; while(b>0) { if(b&1) ans=(ansa)%c; a=aa; b>>=1; } cout<<ans; return 0; } still getting wrong Answers

@Pramod123 please use ide.codingblocks.com to share the code, and you still need to replace a =a * a with a = (a*a)%c, please refer to the code provided by me above as i have corrected your code only.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like