問題描述 給定A, B, P,求(A^B) mod P。 輸入格式 輸入共一行。 第一行有三個數,N, M, P。 輸出格式 輸出共一行,表示所求。 樣例輸入 2 5 3 樣例輸出 2 數據規模和約定 共10組數據 對100%的數據,A, B為long long范圍內的非負整數,P為int內的非負整數。
http://lx.lanqiao.cn/PRoblem.page?gpid=T375
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define ll long longusing namespace std;typedef long long LL;long long Max;LL fun(LL x,LL n){ LL res=1; while(n>0) { x%=Max; if(n & 1) res=((res*x)%Max+Max)%Max; x=(x*x)%Max; n >>= 1; } return res;}int main(){ long long a,b; cin>>a>>b>>Max; cout<<fun(a,b)<<endl;}新聞熱點
疑難解答