A solution in c++
#include<bits/stdc++.h>
using namespace std;
/// Typedef
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0);
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld %lld",&a,&b)
#define sc3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf1(a) printf("%lld\n",a)
#define pf2(a,b) printf("%lld %lld\n",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
ll BigMod(ll base, ll pow, ll modNum) { if(pow==0) return 1; if(pow%2) return ((base % modNum) * BigMod(base, pow-1, modNum))%modNum;
else{ ll ck = BigMod(base, pow/2, modNum); return ((ck % modNum) * (ck % modNum))%modNum; } }
/************ Start my main method code ************/
int main()
{
FastIO;
sieve();
ll n,m,t,c,i,j=0,k,ck=0,dk=0,a,b,o=0,d;
while(sc1(t)){
if(t==0) break;
while(t--){
sc3(a,b,c);
cout<<BigMod(a,b,c)<<endl;
}
}
}
0 Comments
If you have any doubts, Please let me know