Title: http://www.lydsy.com/JudgeOnline/problem.php?id=1965
Find the law, set the answer to X, there is x*2^m% (n+1) =l
Then the fast Power + inverse element is available.
#include <cstring>#include<iostream>#include<cstdio>#include<queue>#include<cmath>#include<algorithm>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#defineLow (x) (x& (×))#defineMAXN 505#defineINF Int (1E9)#defineMM 1000000007#definell Long Longusing namespacestd;ll N,m,p,x,y,l,a;ll Read () {ll x=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;} ll Pow (ll X,ll y) {ll ans=1; while(y) {if(y&1) ans=ans*x%p; X=x*x%p; Y/=2; } returnans;} ll EXGCD (ll A,ll b,ll&x,ll &y) {ll D; if(b==0) {x=1; y=0; returnA; } d=EXGCD (b,a%b,y,x); Y-=a/b*x;}intMain () {n=read (); M=read (); L=read (); p=n+1; A=pow (2, M); EXGCD (A,p,x,y); X= (x%p+p)%p; printf ("%lld\n", x*l%p); return 0;}
BZOJ1965: [Ahoi2005]shuffle Shuffle