提交时间:2023-11-10 21:36:04
运行 ID: 30643
#include<bits/stdc++.h> using namespace std; using ll = long long; ll f(ll b,ll p,ll k){ if(p==1) return b%k; else{ ll q = p/2; ll a = f(b,q,k); ll c = a*a%k; if(p&1==1) c = c*b%k; return c; } } int main(){ ll b,p,k; cin >> b >> p >> k; ll a = f(b,p,k); //cout << b << '^' << p << " mod " << k << "=" << a << endl; printf("%lld^%lld mod %lld=%lld\n",b,p,k,a); return 0; }