Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,10 @@
: invmod { a m | v b c -- inv }
m to v
1 to c
0 to b
begin a
while v a / >r
c b s>d c s>d r@ 1 m*/ d- d>s to c to b
a v s>d a s>d r> 1 m*/ d- d>s to a to v
repeat b m mod dup to b 0<
if m b + else b then ;

View file

@ -0,0 +1,18 @@
: modinv ( a m - inv)
dup 1- \ a m (m != 1)?
if \ a m
tuck 1 0 \ m0 a m 1 0
begin \ m0 a m inv x0
2>r over 1 > \ m0 a m (a > 1)? R: inv x0
while \ m0 a m R: inv x0
tuck /mod \ m0 m (a mod m) (a/m) R: inv x0
r> tuck * \ m0 a' m' x0 (a/m)*x0 R: inv
r> swap - \ m0 a' m' x0 (inv-q) R:
repeat \ m0 a' m' inv' x0'
2drop \ m0 R: inv x0
2r> drop \ m0 inv R:
dup 0< \ m0 inv (inv < 0)?
if over + then \ m0 (inv + m0)
then \ x inv'
nip \ inv
;