1 条题解
-
1Root (sky1231) LV 8 MOD @ 2018-05-19 17:05:37
#include <cmath> #include <ctime> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <vector> #include <deque> #include <set> #include <limits> #include <string> #include <sstream> using namespace std; namespace dts { typedef long long ll; ll n,m,key; ll qp(ll x,ll y,ll key) { ll ans=1; for (ll i=x,j=y;j>0;i=(i*i)%key,j/=2) if (j&1) ans=(ans*i)%key; return ans; } void main() { while (~scanf("%lld%lld%lld",&n,&m,&key)) { m%=key; if (m-2<0) m+=key; ll ans=(m-1)*((qp(m-2,n-1,key)+((n&1)?-1:1))%key)%key; printf("%lld\n",ans); } } }; int main() { dts::main(); }
- 1