标签:include define line a* class i++ P20 show inline
我们考虑每一步牌的变化:
那么我们可以看做是\(x\times 2^m\equiv l \pmod n\)
于是求个逆元就好了
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define F(i,a,b) for(register int i=(a);i<=(b);i++)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
inline LL read() {
LL x=0,f=1;char c=getchar();
while(!isdigit(c)) {if(c=='-')f=-f;c=getchar();}
while(isdigit(c)) x=(x<<1)+(x<<3)+c-48,c=getchar();
return x*f;
}
LL MOD,m,l;
LL exgcd(LL a,LL b,LL &x,LL &y) {
if(!b) {x=1;y=0;return a;}
LL d=exgcd(b,a%b,x,y),t=x;x=y;y=t-a/b*y;
return d;
}
LL qpow(LL a,LL b) {
LL t=1;
while(b) {
if(b&1) t=t*a%MOD;
a=a*a%MOD; b>>=1;
}
return t;
}
LL inv(LL a) {
LL x,y;exgcd(a,MOD,x,y);
return (x%MOD+MOD)%MOD;
}
int main() {
MOD=read()+1,m=read(),l=read();
printf("%lld",l*inv(qpow(2,m))%MOD);
return 0;
}
标签:include define line a* class i++ P20 show inline
原文地址:https://www.cnblogs.com/Menteur-Hxy/p/9740840.html