我们发现第x张牌经过一次洗牌后会变成第2x%(n+1)张。
因此第x张牌经过m次洗牌会变成第
x2m%(n+1)
张牌。
我们就是要求
x2m≡lmodn+1
,因为n+1肯定是奇数,所以(2,n+1)=1.
所以
x=l∗inv(2)m
,2的逆元为(n/2+1)。
然后乘法会爆ll,推荐O(1)快速乘。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
#define N 100010
inline char gc(){
static char buf[1<<16],*S,*T;
if(S==T){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
return *S++;
}
inline ll read(){
ll x=0,f=1;char ch=gc();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=gc();
return x*f;
}
ll n,m,L,mod;
inline ll mul(ll x,ll y){
ll res=x*y-(ll)((ld)x/mod*y+1e-8)*mod;return res<0?res+mod:res;
}
inline ll ksm(ll x,ll k){
ll res=1;for(;k;k>>=1,x=mul(x,x)) if(k&1) res=mul(res,x);return res;
}
int main(){
// freopen("a.in","r",stdin);
n=read();m=read();L=read();mod=n+1;
printf("%lld\n",mul(ksm(n/2+1,m),L));
return 0;
}