CanonSharp/OpenSet/43_exgcd.pas
jackfiled 89ce313b77 feat: CanonSharp Benchmark. (#4)
Reviewed-on: https://git.bupt-hpc.cn/jackfiled/CanonSharp/pulls/4
Co-authored-by: jackfiled <xcrenchangjun@outlook.com>
Co-committed-by: jackfiled <xcrenchangjun@outlook.com>
2024-08-19 14:37:34 +08:00

37 lines
494 B
ObjectPascal

program main;
var
x, y: array[0..0] of integer;
a, b: integer;
function exgcd(a, b: integer; var x, y: integer): integer;
var
t, r: integer;
begin
if b = 0 then
begin
x := 1;
y := 0;
exgcd := a;
end
else
begin
r := exgcd(b, a mod b, x, y);
t := x;
x := y;
y := (t - (a div b) * y);
exgcd := r;
end;
end;
begin
a := 7;
b := 15;
x[0] := 1;
y[0] := 1;
exgcd(a, b, x[0], y[0]);
x[0] := ((x[0] mod b) + b) mod b;
write(x[0]);
end.