标签:scanf ios online 提速 pre cout algorithm ack reset
https://ac.nowcoder.com/acm/contest/3800/A
题意:求A的B次方模P
1≤T≤10~3,1≤A,B,P≤10~18
//#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdio.h>
#include <queue>
#include <stack>;
#include <map>
#include <set>
#include <ctype.h>
#include <string.h>
#include <vector>
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF 0x3f3f3f3f
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int a[10009];
ll mul(ll a , ll b , ll mod)
{
ll ans = 0 ;
while(b)
{
if(b&1)
{
ans = (ans + a) % mod ;
}
b >>= 1 ;
a = (a + a) % mod;
}
return ans ;
}
ll quickpow(ll a, ll b , ll mod)
{
ll ans = 1 ;
while(b)
{
if(b&1)
{
ans = mul(ans , a , mod) ;
}
b >>= 1 ;
a = mul(a , a, mod) ;
}
return ans ;
}
int main()
{
/*#ifdef ONLINE_JUDGE
#else
freopen("D:/c++/in.txt", "r", stdin);
freopen("D:/c++/out.txt", "w", stdout);
#endif*/
int t ;
scanf("%d" ,&t);
while(t--)
{
ll a , b , p ;
scanf("%lld%lld%lld" , &a , &b , &p);
cout << quickpow(a , b , p) << endl;
}
return 0 ;
}
标签:scanf ios online 提速 pre cout algorithm ack reset
原文地址:https://www.cnblogs.com/nonames/p/12151607.html