I am getting tle in math day hint
Math dat getting tle
#include using namespace std; int power(long long x, unsigned int y, int p) { int res = 1; while (y > 0) { if (y & 1) res = ((res%p)(x%p)) % p; x = ((x%p)(x%p)) % p; y = y>>1; } return res; } int main() { int t; cin>>t; while(t–) { int a,n,p; cin>>a>>n>>p; for(int i=1;i<=n;i++) { int y=power(a,i,p); a=y; } cout<<a<<endl; } return 0; }
You need to use long long int to prevent overflow.
I am grttiling tlw for test case 3 and 4
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.