#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll n,m,k;
ll ksm(int m,int n,int k){
if(n==0) return 1%k;
if(n==1) return m%k;
ll t=ksm(m,n/2,k);
if(n%2==0){
return (t%k)*(t%k)%k;
}else{
return (((t%k)*(t%k)%k)*m)%k;
}
}
int main(){
ios::sync_with_stdio(0);
cin>>m>>n>>k;
cout<<m<<"^"<<n<<" "<<"mod"<<" "<<k<<"="<<ksm(m,n,k);
return 0;
}
快速幂||取余运算
最新推荐文章于 2024-01-27 16:51:39 发布