Day1
题解:快速幂
其实是道规律题啦。
一次洗牌之后位置x会变换到位置2*x%(n+1)
所以x*(2^m)=L (mod n+1)
2是偶数,n+1是奇数,所以两者一定互质,2^m也一定与n+1互质。
我们其实只需要知道2在模n+1意义下的的逆元,2*x+(n+1)*y=1 x的最小正整数解就是当y=-1时,x=n/2+1
所以这道题的答案就是(n/2+1)^m*L %(n+1)
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#define LL long long using namespace std;LL n,m,l;LL quickpow(LL num,LL x,LL p){ LL base=num%p; LL ans=1; while (x) { if (x&1) ans=ans*base%p; x>>=1; base=base*base%p; } return ans;}int main(){ cin>>n>>m>>l; PRintf("%I64d/n",quickpow(n/2+1,m,n+1)*l%(n+1));}
新闻热点
疑难解答