BZOJ1965 [Ahoi2005]SHUFFLE 洗牌

题面在这里

\[ x\cdot 2^m\equiv L\pmod {n+1} \\ x\equiv L\cdot \left( \frac {n+2} 2 \right)^m \pmod {n+1} \]

示例程序:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<cstdio>
typedef long long ll;

ll n,m,l,MOD;
ll power(ll a,ll b){
ll w=a%MOD,res=1;
while (b){
if (b&1) (res*=w)%=MOD;
(w*=w)%=MOD;
b>>=1;
}
return res;
}
int main(){
scanf("%lld%lld%lld",&n,&m,&l);MOD=n+1;
printf("%lld",l*power(n/2+1,m)%MOD);
return 0;
}