高速電力テンプレート_

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

//求 m^k mod p,时间复杂度 O(logk)。
int qmi(int a , int k , int p)
{
	int res = 1 ;
	while(k)
	{
		if(k & 1)  res = (LL)res * a % p ;   // 
		k >>= 1;
		a= (LL)a * a % p;
	}
	return res;
}

int main()
{
	int n;
	scanf("%d" , &n);
	while(n--)
	{
		int a, k ,p;
		scanf("%d%d%d" , &a , &k , &p);
		
		printf("%d\n" , qmi(a , k , p));
	}
	
	return 0;
} 
公開された12元の記事 ウォンの賞賛0 ビュー116

おすすめ

転載: blog.csdn.net/qq_45244489/article/details/105129325