您的位置:首页 > 其它

fzu 1759 Super A^B mod C

2017-08-17 15:54 405 查看
题目链接

//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
typedef long long LL;

LL qpow(LL x,LL n,LL mod)        //求x^n%mod
{
LL ret=1;
for(; n; n>>=1)
{
if(n&1) ret=ret*x%mod;
x=x*x%mod;
}
return ret;
}

LL Eular(LL n)
{
LL ret=n;
for(LL i=2; i*i<= n; i++)
if(n%i==0)
{
ret-=ret/i;
while(n%i==0) n/= i;
}
if(n>1) ret-=ret/n;
return ret;
}

LL A,C;

char B[1000005];
int main()
{
while(~scanf("%lld%s%lld",&A,B,&C))
{
LL ans,a=A;
LL phiC=Eular(C);
int lenB=strlen(B);
if(lenB>10)
{
LL t1=0;
for(int i=0;i<lenB;i++)
t1=(t1*10+B[i]-'0')%phiC;
t1+=phiC;
ans=qpow(A,t1,C);
}
else
{
LL b=0;
for(int i=0;i<lenB;i++)
b=b*10+B[i]-'0';
ans=qpow(A,b,C);
}
printf("%lld\n",ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: