
思路:因为数据范围较大相乘会爆ull所以加上快速乘
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
#define space putchar(' ')
#define enter putchar('\n')
#define ZY set::iterator
#define lson root<<1
#define rson root<<1|1
typedef unsigned long long ull;
const int MOD7 = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int imax_n = 1e5 + 7;
typedef pair<int,int> PII;
const int inf=0x3f3f3f3f;
const int N=5e6+10;
const double esp=1e-10;ll gcd(ll a,ll b)
{return b==0?a:gcd(b,a%b);
}ll lcm(ll a,ll b)
{return a*(b/gcd(a,b));
}template <class T>
void read(T &x)
{char c;bool op = 0;while(c = getchar(), c < '0' || c > '9')if(c == '-')op = 1;x = c - '0';while(c = getchar(), c >= '0' && c <= '9')x = x * 10 + c - '0';if(op)x = -x;
}
template <class T>
void write(T x)
{if(x < 0)x = -x, putchar('-');if(x >= 10)write(x / 10);putchar('0' + x % 10);
}int a[N];
int n,k;
ull ksc(ull x,ull y,ull p)
{ull ans=0;while(y){if(y&1) ans=(ans+x)%p;x=(x+x)%p;y>>=1;}return ans;
}
ull qpow(ull a,ull b,ull p)
{ull res=1;while(b){if(b&1){res=ksc(res,a,p);}a=ksc(a,a,p);b>>=1;}return res;
}
int main()
{int t;read(t);while(t--){ull a,b,p;read(a),read(b),read(p);ull ans=qpow(a,b,p);write(ans);enter;}return 0;
}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!