Ma · Mathematics

Is There a Formula for Composite Numbers?

Published By the 9to5Science editorial team

At a glance

  1. 1. Use the definition

    A composite integer is a positive integer greater than 1 that can be written as a product of two smaller positive integers.

  2. 2. Check small divisors

    To test n, look for a divisor d with 2 ≤ d ≤ the square root of n.

  3. 3. Classify the result

    If such a divisor exists, n is composite; otherwise, n is prime, provided n is greater than 1.

  4. 4. Generate examples

    Products such as n(n + 1) are always composite for integers n ≥ 2, but do not list every composite.

Advertisement

A composite number is a positive integer greater than 1 that has a factor other than 1 and itself. The basic formula is a factorization: n=abn=ab, where aa and bb are integers greater than 1. If you want to decide whether a particular number is composite, you can use this definition and make the search efficient by checking divisors only up to its square root.

There is not one standard simple formula that lists every composite number in order. Depending on what you mean by “formula,” you might want a definition, a test for a given number, or a way to generate some composite numbers. These are related but different tasks.

The defining formula

For an integer n>1n>1, the following are equivalent:

  • nn is composite.
  • There are integers a,b>1a,b>1 such that n=abn=ab.
  • There is an integer divisor dd of nn with 1<d<n1<d<n.

When n=abn=ab and both factors exceed 1, you can choose the order so that a≤ba\le b. Then a2≤ab=na^2\le ab=n, which means a≤na\le\sqrt n. Thus every composite number has a divisor no larger than its square root.

This gives the useful characterization

n is composite⟺n=ab for some integers 2≤a≤b.n\text{ is composite}\quad\Longleftrightarrow\quad n=ab\text{ for some integers }2\le a\le b.

The restriction n>1n>1 matters. The number 1 is neither prime nor composite. A prime number is greater than 1 and has no positive divisors except 1 and itself.

How to test a number

To check whether an integer n>1n>1 is composite:

  1. Find the integer part of n\sqrt n.
  2. Test whether any integer from 2 up to that value divides nn evenly.
  3. If one does, nn is composite. If none does, nn is prime.

You do not need to test divisors larger than n\sqrt n. If nn had a factor larger than n\sqrt n, its paired factor in the product would have to be smaller than n\sqrt n and would already have been found.

Worked example: Is 91 composite?

Since 91≈9.54\sqrt{91}\approx9.54, test the possible divisors from 2 through 9. The number 91 is not divisible by 2, 3, 4, or 5. But

91=7×13.91=7\times13.

Because 7 is a divisor greater than 1, 91 is composite. There is no need to test 10, 11, or any larger possible divisor.

For comparison, to test 29 you only need to check 2, 3, 4, and 5, because 29≈5.39\sqrt{29}\approx5.39. None divides 29, so 29 is prime.

Formulas that generate composites

Many formulas produce composite numbers without producing all of them. For example,

n(n+1)n(n+1)

produces a composite number for every integer n≥2n\ge2, since it is a product of two integers greater than 1. Setting n=2,3,4n=2,3,4 gives 6, 12, and 20. This sequence does not include every composite number: for instance, it does not produce 9.

Another useful construction is n!+kn!+k. For any integer n≥2n\ge2 and any integer kk with 2≤k≤n2\le k\le n, the number n!+kn!+k is composite. Indeed, kk divides n!n! and also divides kk, so it divides their sum; moreover, n!+k>kn!+k>k. For example, with n=5n=5 and k=3k=3,

5!+3=123=3×41.5!+3=123=3\times41.

This construction makes particular composite numbers, but it is not a formula for listing every composite number.

Common mistakes

  • Treating 1 as composite: It is neither prime nor composite under the standard definition.
  • Checking only prime divisors without explaining why: It is enough to test prime divisors up to n\sqrt n, since any composite divisor has a prime factor. Testing every integer in that range also works, though it may take longer.
  • Assuming every product formula lists all composites: A formula such as n(n+1)n(n+1) gives a family of composites, not the complete set.
  • Testing divisors beyond the square root: That work is unnecessary because factors occur in pairs, with at least one factor no greater than n\sqrt n.

For a specific integer, the square-root divisor test is usually the most useful meaning of a “formula for composite numbers.” For a sequence or construction, first specify whether you need to generate some composites or enumerate all of them; those are different goals.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.