Skip to content

Resource · Guide or article

Primality Test

Definitions page for primes, composite numbers, and what a primality test answers, for someone who needs the vocabulary before writing an isPrime function.

Reviewed

Open the original: Primality Test (opens the original site in a new tab)

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself. However, 6 is composite because it is the product of two numbers (2 × 3) that are both smaller than 6. A primality test is an algorithm for determining whether an input number is prime. Among other fields of mathematics, it is used for cryptography. Unlike integer factorization, primality tests do not generally give prime factors, only stating whether the input number is prime or not. Factorization is thought to be a computationally difficult problem, whereas primality testing is comparatively easy (its running time is polynomial in the size of the input).

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • Definition of a prime and a composite number, with 5 and 6 as examples.
  • How primality testing differs from integer factorization, and the note that testing runs in polynomial time.

How to use it

PrepKit study advice, not a claim made by the source.

Write a trial-division isPrime and explain aloud why it only needs to check divisors up to the square root. That bound comes from other material, not from this README.

Scope and limitations

Very thin: it names no testing method, gives no code walkthrough or complexity for a specific approach, and relies on two Wikipedia links.

Access and format

English README on GitHub in trekhleb/javascript-algorithms (MIT); free to read.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/algorithms/math/primality-test/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email