链接:https://www.luogu.org/problemnew/show/P1226

题解:(重要结论:(a*b*c*d*...*n)%k=[(a%k)*(b%k)*...(n%k)]%k)

#include<iostream>
#include<cstdio>
using namespace std;
long long b,p,k,s=1;
void m(long long i)
{
while(p>0)
{if(p&1)
s=s*i%k;
i=i*i%k;
p=p>>1;
}
}
int main()
{long long n;
cin>>b>>p>>k;
n=p;m(b);
cout<<b<<"^"<<n<<" mod "<<k<<"="<<s%k;
}

05-11 01:11