Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
11
Task/Modular-inverse/Ada/modular-inverse-1.ada
Normal file
11
Task/Modular-inverse/Ada/modular-inverse-1.ada
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package Mod_Inv is
|
||||
|
||||
procedure X_GCD(A, B: in Natural; D, X, Y: out Integer);
|
||||
-- the Extended Euclidean Algorithm
|
||||
-- finds (D, X, Y) with D = GCD(A, B) = A*X + B*Y
|
||||
|
||||
function Inverse(A, M: Integer) return Integer;
|
||||
-- computes the multiplicative inverse Inv_A of A mod M, using X_GCD
|
||||
-- raises Constraint_Error if Inv_A does not exist
|
||||
|
||||
end Mod_Inv;
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
with Ada.Text_IO;
|
||||
|
||||
procedure Mod_Inv is
|
||||
package body Mod_Inv is
|
||||
|
||||
procedure X_GCD(A, B: in Natural; D, X, Y: out Integer) is
|
||||
-- the Extended Euclidean Algorithm
|
||||
|
|
@ -35,8 +33,4 @@ procedure Mod_Inv is
|
|||
end if;
|
||||
end Inverse;
|
||||
|
||||
begin
|
||||
Ada.Text_IO.Put_Line(Natural'Image(Inverse(42, 2017)));
|
||||
-- Ada.Text_IO.Put_Line(Natural'Image(Inverse(154, 3311)));
|
||||
-- The above would raise CONSTRAINT_ERROR : GCD ( 154, 3311 ) = 77 /= 1
|
||||
end Mod_Inv;
|
||||
9
Task/Modular-inverse/Ada/modular-inverse-3.ada
Normal file
9
Task/Modular-inverse/Ada/modular-inverse-3.ada
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
with Ada.Text_IO; with Mod_Inv; use Mod_Inv, Ada.text_IO;
|
||||
|
||||
procedure Mod_Inv_Test is
|
||||
begin
|
||||
-- Put_Line(Natural'Image(Inverse(154, 3311)));
|
||||
-- The above would raise CONSTRAINT_ERROR : GCD ( 154, 3311 ) = 77 /= 1
|
||||
|
||||
Put_Line(Natural'Image(Inverse(42, 2017)));
|
||||
end Mod_Inv_Test;
|
||||
Loading…
Add table
Add a link
Reference in a new issue