标签:strlen span isp open stc ase res test contain
本题考点:欧拉降幂
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B<=10^1000000).
AC代码:
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long ll; ll a,p; char b[10000005]; ll phi(ll x) { ll res=x; ll a=x; for(int i=2;i*i<=x;i++) { if(a%i==0) { res=res/i*(i-1); while(a%i==0) a/=i; } } if(a>1) res=res/a*(a-1); return res; } ll qp(ll a,ll b,ll p) { ll ans=1; while(b) { if(b&1) { ans=(ans*a)%p; } a=(a*a)%p; b>>=1; } return ans; } int main() { //freopen("input.txt","r",stdin); while(scanf("%lld %s %lld",&a,&b,&p)!=EOF) { ll len=strlen(b); ll res=0; ll pp=phi(p); for(int i=0;i<len;i++) { res=(res*10+b[i]-‘0‘)%pp; } printf("%lld\n",qp(a,res,p)); } return 0; }
标签:strlen span isp open stc ase res test contain
原文地址:https://www.cnblogs.com/cautx/p/11396842.html