题解 | 好多次方

好多次方

https://www.nowcoder.com/practice/8bf1186260634b209b5cff362da45305

#include<bits/stdc++.h>
using namespace std;
#define int long long
int power(int a,int b,int p){
	int ans=1;
	b=b%p;
	while(b>0){
		if(b&1==1){
			ans=(ans*a)%p;
		}
		a=a*a%p;
		b=b>>1;
	}
	return ans;
}
const int MOD=1e9+7;

int T,a,b,c;

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>T;
	while(T--){
		cin>>a>>b>>c;
		
		int bc_MOD=power(b,c,MOD-1);
		if(bc_MOD==0) bc_MOD=MOD-1;
		int ans=power(a,bc_MOD,MOD);
		cout<<ans<<endl;
	}
	
    return 0;
}


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务