Why is it giving a wrong ans

may i jnow why my code was giving a wrong answer.

#include
#include<bits/stdc++.h>
#include

using namespace std;
#define ll long long int
int main()
{
ll t;
cin>>t;
while(t–)
{

    ll A,N,P;
    cin>>A>>N>>P;
    ll ans = A;
    ans = ans%P;
    for(ll i=1;i<=N;i++)
    {
        ans = (pow(ans,i));
        ans = ans%P;
    }
    cout<<ans<<endl;
}


return 0;

}

N can be upto 10^5. So the line ans = (pow(ans,i)); will lead to overflow. Thats why your code is giving wrong answer.

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.