标签:
1 /************************************************************** 2 Problem: 1477 3 User: HansBug 4 Language: Pascal 5 Result: Accepted 6 Time:0 ms 7 Memory:224 kb 8 ****************************************************************/ 9 10 type 11 vec=record 12 x,y:int64; 13 end; 14 var 15 i,j:longint; 16 k,l,m,n,x,y,x1,x2,x3:int64; 17 a1,a2:vec; 18 function ex_gcd(a,b:int64):vec; 19 var 20 a1,a2:vec; 21 begin 22 if b=0 then 23 begin 24 a1.x:=1;a1.y:=0; 25 ex_gcd:=a1 26 end 27 else 28 begin 29 a1:=ex_gcd(b,a mod b); 30 a2.x:=a1.y; 31 a2.y:=a1.x-(a div b)*a1.y; 32 ex_gcd:=a2; 33 end; 34 end; 35 function gcd(x,y:int64):int64; 36 var 37 z:int64; 38 begin 39 while y<>0 do 40 begin 41 z:=x mod y; 42 x:=y; 43 y:=z; 44 end; 45 gcd:=x; 46 end; 47 begin 48 readln(x,y,m,n,l); 49 a1:=ex_gcd(m-n,-l); 50 k:=gcd(m-n,-l); 51 if ((y-x) mod k)<>0 then 52 begin 53 writeln(‘Impossible‘); 54 halt; 55 end; 56 x1:=(y-x) div k; 57 a1.x:=a1.x*x1; 58 a1.y:=a1.y*x1; 59 if a1.x>0 then a1.x:=a1.x mod l else a1.x:=((a1.x mod l)+2*l) mod l; 60 writeln(a1.x); 61 end.
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4472318.html