- 同余方程
- 2012-11-18 21:29:55 @
RT- -
3 条评论
-
C++father LV 8 @ 2014-10-12 23:32:15
扩展欧几里德算法
-
2013-10-18 15:45:57@
really?
program p1781;
var
a,b,x,y:longint;
procedure gcd(a,b:longint);
var t:longint;
begin
if b<>0
then gcd(b,a mod b)
else begin
x:=1;
y:=0;
exit;
end;
t:=x;
x:=y;
y:=t-(a div b)*y;
end;
begin
readln(a,b);
gcd(a,b);
//writeln(x,' ',y);
writeln(((x mod b)+b)mod b);
end. -
2013-10-06 14:19:09@
really?
var
a,b,m,n,k:longint;procedure ojld(a,b:longint);
var
t:longint;
begin
if a mod b = 0 then
begin
m:=0;
n:=1;
end
else
begin
ojld(b,a mod b);
t:=m;
m:=n;
n:=t-(a div b)*n;
end;
end;begin
readln(a,b);
k:=b;
ojld(a,b);
writeln((m mod k+k) mod k);
end.
- 1