2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,13 +1,15 @@
|
|||
/*REXX program calculates the modular inverse of an integer X modulo Y. */
|
||||
parse arg x y . /*obtain two integers from the C.L. */
|
||||
say 'modular inverse of ' x " by " y ' ───► ' modInv(x,y)
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*────────────────────────────────────────────────────────────────────────────*/
|
||||
modInv: parse arg a,b 1 ob; ox=0
|
||||
/*REXX program calculates and displays the modular inverse of an integer X modulo Y.*/
|
||||
parse arg x y . /*obtain two integers from the C.L. */
|
||||
if x=='' | x=="," then x= 42 /*Not specified? Then use the default.*/
|
||||
if y=='' | y=="," then y= 2017 /* " " " " " " */
|
||||
say 'modular inverse of ' x " by " y ' ───► ' modInv(x,y)
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
modInv: parse arg a,b 1 ob; z=0 /*B & OB are obtained from the 2nd arg.*/
|
||||
$=1
|
||||
if b \= 1 then do while a>1
|
||||
parse value a/b a//b b ox with q b a t
|
||||
ox=$-q*ox; $=trunc(t)
|
||||
end /*while a>1*/
|
||||
if b\=1 then do while a>1
|
||||
parse value a/b a//b b z with q b a t
|
||||
z=$ - q*z; $=trunc(t)
|
||||
end /*while*/
|
||||
if $<0 then $=$+ob
|
||||
return $
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue