Data update
This commit is contained in:
parent
8e4e15fa56
commit
72eb4943cb
1853 changed files with 35514 additions and 9441 deletions
18
Task/Modular-inverse/PascalABC.NET/modular-inverse.pas
Normal file
18
Task/Modular-inverse/PascalABC.NET/modular-inverse.pas
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function ModInverse(a, m: integer): integer;
|
||||
begin
|
||||
result := 1;
|
||||
if m = 1 then exit;
|
||||
var m0 := m;
|
||||
var (x, y) := (1, 0);
|
||||
while a > 1 do
|
||||
begin
|
||||
var q := a div m;
|
||||
(a, m) := (m, a mod m);
|
||||
(x, y) := (y, x - q * y);
|
||||
end;
|
||||
result := if x < 0 then x + m0 else x;
|
||||
end;
|
||||
|
||||
begin
|
||||
ModInverse(42, 2017).Println;
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue