快速乘+快速幂
计算 ab % p
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll a, b, p;
ll fast_mul(ll a, ll b, ll p)
{
ll res = 0;
while (b)
{
if (b & 1) res = (res + a) % p;
a = a * 2 % p;
b >>= 1;
}
return res;
}
ll fast_pow(ll a, ll b, ll p)
{
ll res = 1;
while (b)
{
if (b & 1) res = fast_mul(res, a, p);
a = fast_mul(a, a, p);
b >>= 1;
}
return res;
}
int main()
{
cin >> t;
while (t--)
{
scanf("%lld%lld%lld", &a, &b, &p);
printf("%lld
", fast_pow(a, b, p));
}
return 0;
}