#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll bigmod(ll a, ll b, ll m)
{
if(b == 0)
return 1;
int x = bigmod(a, b/2, m);
x = (x*x)%m;
if(b%2 == 1)
x = (x*a)%m;
return x;
}
int main()
{
ll x, y, n, t, i;
while(cin >> t && t > 0)
{
for(i=1; i<=t; i++)
{
cin >> x >> y >> n;
int r = bigmod(x, y, n);
cout << r << endl;
}
}
return 0;
}
#define ll long long int
using namespace std;
ll bigmod(ll a, ll b, ll m)
{
if(b == 0)
return 1;
int x = bigmod(a, b/2, m);
x = (x*x)%m;
if(b%2 == 1)
x = (x*a)%m;
return x;
}
int main()
{
ll x, y, n, t, i;
while(cin >> t && t > 0)
{
for(i=1; i<=t; i++)
{
cin >> x >> y >> n;
int r = bigmod(x, y, n);
cout << r << endl;
}
}
return 0;
}
Comments
Post a Comment