Handbook
Glossary
totient ( n -- t )
Vocabulary
math
.
primes
.
factors
Inputs
n
a positive integer
Outputs
t
an
integer
Word description
Return the number of integers between 1 and
n-1
that are relatively prime to
n
.
Definition
USING:
combinators
kernel
math
sequences
;
IN:
math.primes.factors
:
totient
( n -- t )
{
{
[
dup
2
<
]
[
drop
0
]
}
[
dup
unique-factors
[
1
[
1
-
*
]
reduce
]
[
product
]
bi
/
*
]
}
cond
;
foldable
flushable