Help me with this question?

any more efficient way to do this my testcases show worng

you are taking modulus at wrong step. you have to take step wise mod in your fast function . please refer to the video tutorial correctly.

#include using namespace std; long long int fast(int x, unsigned int n, int y){ x = x%y; long long int ans = 1; if(x==0) return 0; while(n){ if(n&1){ ans = (ansx)%y; } n=n>>1; x = (xx)%y; } return ans; } int main() { int a,c; unsigned int b; cin>>a>>b>>c; cout<<fast(a,b,c); return 0; }

this code is failing onr test case

hi @tharunnayak14,


This is your modified code.
There were two mistakes in it,

  1. You have to take modulus at each step.
  2. You have to take long long everywhere.
    Please let me know if there is any other doubt.