 Prime Numbers - Maple Help

Number Theory: Prime Numbers Getting Started

While any command in the package can be referred to using the long form, for example, NumberTheory:-Divisors, it is often easier to load the package and then use the short form command names.

 > restart;
 > with(NumberTheory): Examples

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The top-level ithprime command returns the ith prime. For example, the first ten primes are given by the following sequence:

 > $\mathrm{seq}\left(\mathrm{ithprime}\left(i\right),i=1..10\right)$
 ${2}{,}{3}{,}{5}{,}{7}{,}{11}{,}{13}{,}{17}{,}{19}{,}{23}{,}{29}$ (1)

The top-level isprime command determines if a given number is prime:

 > $\mathrm{isprime}\left(28\right)$
 ${\mathrm{false}}$ (2)
 > $\mathrm{isprime}\left(29\right)$
 ${\mathrm{true}}$ (3)

The Divisors command can verify that a number is prime. If the divisors of a given integer are only 1 and itself, the number is prime.

 > $\mathrm{Divisors}\left(28\right)$
 $\left\{{1}{,}{2}{,}{4}{,}{7}{,}{14}{,}{28}\right\}$ (4)
 > $\mathrm{Divisors}\left(29\right)$
 $\left\{{1}{,}{29}\right\}$ (5)

The SumOfDivisors command returns the sum of the divisors of an integer:

 > $\mathrm{SumOfDivisors}\left(28\right)$
 ${56}$ (6)

The top-level ifactor command gives the integer factorization of an integer:

 > $\mathrm{ifactor}\left(28\right)$
 ${\left({2}\right)}^{{2}}{}\left({7}\right)$ (7)

The PrimeFactors command returns a list of factors for a given integer that are primes without multiplicity:

 > $\mathrm{PrimeFactors}\left(28\right)$
 $\left\{{2}{,}{7}\right\}$ (8)

The NumberOfPrimeFactors command returns the number of prime factors of an integer, counted with multiplicity:

 > $\mathrm{NumberOfPrimeFactors}\left(28\right)$
 ${3}$ (9)

The Radical command returns the product of the prime divisors of an integer:

 > $\mathrm{Radical}\left(28\right)$
 ${14}$ (10)

The top-level nextprime (or prevprime) command returns the next (or previous) prime numbers after (or before) the given integer:

 > $\mathrm{nextprime}\left(29\right)$
 ${31}$ (11)

The PrimeCounting command returns the number of primes less than a given integer:

 > $\mathrm{PrimeCounting}\left(31\right)$
 ${11}$ (12)

Two integers are relatively prime (coprime) if the greatest common divisor of the values is 1. The AreCoprime command tests if a sequence of integers or Gaussian integers are coprime:

 > $\mathrm{AreCoprime}\left(5,8\right)$
 ${\mathrm{true}}$ (13)
 > $\mathrm{AreCoprime}\left(2,8\right)$
 ${\mathrm{false}}$ (14)

The following plot shows the coprimes for the integers 1 to 15:

 > $\mathrm{Statistics}:-\mathrm{HeatMap}\left(\mathrm{Matrix}\left(15,\left(i,j\right)→\mathrm{if}\left(\mathrm{AreCoprime}\left(i,j\right),1,0\right)\right),\mathrm{color}=\left["White","Red"\right]\right)$ An integer is called square-free if it is not divisible by the square of another number other than 1. All prime numbers are square-free:

 > $\mathrm{IsSquareFree}\left(31\right)$
 ${\mathrm{true}}$ (15)
 > $\mathrm{IsSquareFree}\left(7\cdot 101\right)$
 ${\mathrm{true}}$ (16)
 > $\mathrm{IsSquareFree}\left(3{7}^{2}\right)$
 ${\mathrm{false}}$ (17) See Also