UVa 1230 MODEX
UVa 1230 MODEX
#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
ll sqr(ll v)
{
return v*v;
}
ll bigMod(ll p, ll v, ll m)
{
if (p==0) return 1;
else if (p&1) return (v%m * bigMod(p-1,v,m))%m;
else return (sqr(bigMod(p/2,v,m)))%m;
}
int main()
{
int tst;
ll x, y, n;
cin >> tst;
while (tst--)
{
cin >> x >> y >> n;
cout << bigMod(y,x,n) << endl;
}
cin >> tst;
return 0;
}
Go to link download