这是我的代码QAQ
#include<bits/stdc++.h>
using namespace std;
int a,b,p,x=1;
cin>>a>>b>>p;
for(int i=1;i<=b;i++){
if(b!=0){
x*=a;
x=x%p;
}else{
x=1;
x=x%p;
}
}
int main(){
cin>>a>>b>>k;
cout<<a<<" ^ "<<b<<" mod "<<p<<" = "<<x;
}
这是dalao的代码
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,m,k;
LL ksm(LL x,LL y)
{
LL a=1,b=x;
while(y>0)
{
if(y%2==1)
{
a=a*b;
a=a%m;
}
b=b*b;
b=b%m;
y=y/2;
}
return a;
}
int main()
{
cin>>n>>k>>m;
cout<<n<<"^"<<k<<" mod "<<m<<"="<<ksm(n,k)%m<<endl;;
return 0;
}
why...QAQ