传送门:BZOJ1008
我即使没有系统学习离散数学,也会觉得出题人是不是太懒了……
第一个人显然可以任意选择宗教,第一个人选定后第二个人则有m-1种宗教可选,类似第三个人也有m-1种宗教可选,且选择之间彼此独立。
故n个人不发生越狱事件的总数是m[(m-1)^(n-1)],而n个人总共的选择数是m^n,套一个补集定理,即ans=m^n-m[(m-1)^(n-1)],快速幂即可。
上面那步用归纳法可能比乘法原理好理解。
说来这题我第一反应是Bernoulli分布的……
代码上的小细节见下。
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
const long long tomod=100003;
long long m,n;
long long Power_Mid(long long a,long long b)
{
if(b==0)
return 1;
if(b==1)
return a%tomod;
long long mid=Power_Mid(a,b/2);
if(b%2==0)
return mid*mid%tomod;
return (((mid*mid)%tomod)*(a%tomod))%tomod;
}
void Readdata()
{
freopen("loli.in","r",stdin);
cin>>m>>n;
}
void Solve()
{
long long ans=((Power_Mid(m,n)+tomod)-((Power_Mid(m-1,n-1)*(m%tomod))%tomod))%tomod;
cout<<ans<<endl;
}
void Close()
{
fclose(stdin);
fclose(stdout);
}
int main()
{
Readdata();
Solve();
Close();
return 0;
}