当前位置: 代码迷 >> 综合 >> HDU 1420 Prepared for New Acmer(快速幂裸题)
  详细解决方案

HDU 1420 Prepared for New Acmer(快速幂裸题)

热度:81   发布时间:2023-11-06 18:27:01.0

快速幂裸题,注意用ll,数据别溢出就可以。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstring>
#define ll long long
using namespace std;
int powermod(ll a,ll b,ll c){ll ans=1;a = a % c;while(b>0){if(b%2) ans = (ans * a) %c;b = b/2;a = (a * a)%c;}return ans;	
} 
int main(){int T;scanf("%d",&T);while(T--){ll a,b,c;scanf("%I64d%I64d%I64d",&a,&b,&c);printf("%d\n",powermod(a,b,c));}return 0;