Handbook
Glossary
find-relative-prime* ( n guess -- p )
Prime numbers
Prev:
find-relative-prime ( n -- p )
Next:
unique-primes ( n numbits -- seq )
Vocabulary
math
.
primes
Inputs
n
an
integer
guess
an
integer
Outputs
p
an
integer
Word description
Returns a number that is relatively prime to
n
, starting by trying
guess
.
Definition
USING:
kernel
math
math.bitwise
;
IN:
math.primes
:
find-relative-prime*
( n guess -- p )
[
dup
1
<=
[
no-relative-prime
]
when
]
[
>odd
dup
1
<=
[
drop
3
]
when
]
bi*
[
2dup
coprime?
]
[
2
+
]
until
nip
;