Prime Numbers

A positive integer is a prime number if the only positive integer divisors are the number itself and one.

Worksheet Functions

Real Statistics Functions: The Real Statistics Resource Pack contains the following functions. Here, n is any positive integer up to 231-1 = 2,147,483,647.

PrimeCount(n, start) = the number of prime numbers between start and n (inclusive)

IsPrime(n) = TRUE if n is a prime number

NextPrime(n) = next prime number after n

PriorPrime(n) = largest prime number smaller than n

NthPrime(n) = the nth prime number

PrimeList(start, size) = a column array with size number of prime numbers starting with the first prime ≥ start; if start is omitted it defaults to 2; if size is omitted it defaults to the number of rows in the highlighted range

Factors(n) = a column array containing the prime factors of n (with repetitions if necessary); actually the first value in the output is the number of prime factors.

Divisors(n): returns a column array with the divisors of n

PrimeFactors(n): returns an array whose first column contains the prime factors of n and whose second column contains the number of repetitions of each prime factor.

Examples

Figure 1 demonstrates the use of these worksheet functions.

Prime number examples

Figure 1 – Prime numbers

Examples Workbook

Click here to download the Excel workbook with the examples described on this webpage.

Reference

Caldwell, C. K. (2021) The first fifty million primes
https://primes.utm.edu/lists/small/millions/

2 thoughts on “Prime Numbers”

  1. Dear Charles,
    function Factors(n) correctly decomposes numbers:
    (example)
    2049356 = 2*2*37*61*227
    2049357 = 3*683119
    2049358 = 2*173*5923

    but function PrimeFactors(n) is able to decompose 2049356 and 2049358, but not 2049357.
    —————————–
    On page :
    https://real-statistics.com/real-statistics-environment/real-statistics-math-functions/

    there is a minor mistake in the name of the function. There is Primeactors(n) instead of PrimeFactors(n).

    I hope it helps,

    best regards,
    prof. Martin Krizek

    Reply
    • Hello Prof Krizek,
      Thanks for identifying these two errors. I have changed the PrimeFactors function name on the website.
      I have also fixed the bug in the software. I expect to issue a big fix release, Rel 9.1.1, in about a week.
      Thanks for identifying these errors. I appreciate your help.
      Charles

      Reply

Leave a Comment