Using mathematical functions 169
isprime Prime integer test. Returns 1 if the integer a is prime;
otherwise, returns 0.
isprime(a)
Example:
isprime(1999) returns 1.
ithprime Nth prime. For the integer n, returns the nth prime number
less than 10,000.
ithprime(n)
Example:
ithprime(5) returns 11.
nextprime Next prime. Returns the next prime number after the
integer a.
nextprime(a)
Example:
nextprime(11) returns 13.
powmod Power and modulo. For the integers a, n, and p, returns
modp.
powmod(a, n, p)
Example:
powmod(5, 2, 13) returns 12.
prevprime Previous prime. Returns the previous prime number before
the integer a.
prevprime(a)
Example:
prevprime(11) returns 7.
euler Euler's phi (or totient) function. Takes a positive integer x
and returns the number of positive integers less than or
equal to x that are coprime to x.
euler(x)
Example:
euler(6) returns 2.