【BZOJ1008】越狱
很少刷到这么水的题了...
答案就是总方案数-无法越狱的方案数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <cstdio> typedef long long LL; using namespace std; const int mod=100003; LL Pow(LL a,LL b) { LL res=1; a%=mod; while (b) { if (b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res; } LL n,m; int main() { scanf ( "%lld%lld" ,&m,&n); printf ( "%lld\n" ,(Pow(m,n)-(m*Pow(m-1,n-1))%mod+mod)%mod); return 0; } |