很明显,求方程x*2^m=L (mod n+1)的解(1<=x<=n)
1 var n,m,l,x,y,p:int64; 2 function quick(x:int64):int64; 3 var j:int64; 4 begin 5 j:=2; quick:=1; 6 while x>0 do 7 begin 8 if x mod 2=1 then quick:=quick*j mod p; 9 x:=x div 2; 10 j:=j*j mod p; 11 end; 12 end; 13 14 procedure exgcd(a,b:int64;var x,y:int64); 15 var xx,yy:int64; 16 begin 17 if b=0 then 18 begin 19 x:=1; 20 y:=0; 21 end 22 else begin 23 exgcd(b,a mod b,xx,yy); 24 x:=yy; 25 y:=xx-(a div b)*yy; 26 end; 27 end; 28 29 begin 30 readln(n,m,l); 31 p:=n+1; 32 m:=quick(m); 33 exgcd(m,p,x,y); 34 x:=(x+p) mod p; 35 writeln(qword(x)*qword(l) mod p); 36 end.