BZOJ 1008: [HNOI2008]越狱 组合数学
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1008
题解:
就很傻逼的组合数学啊。。。
$$ans=M^N-M*(M-1)^{(N-1)}$$
代码:
/************************************************************** Problem: 1008 User: HarryGuo2012 Language: C++ Result: Accepted Time:0 ms Memory:1272 kb ****************************************************************/ #include<iostream> #include<cstring> #include<vector> #include<cstdio> using namespace std; typedef long long ll; const ll mod=100003; ll Pow(ll a,ll b) { ll res = 1; while (b) { if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } ll M,N; int main() { scanf("%lld%lld", &M, &N); printf("%lld\n", (M*mod + Pow(M, N) - M * Pow(M - 1, N - 1)) % mod); return 0; }