ArticleslgStudy

mathematics

Trial division

Trial division is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Trial division rather than just read about it. In short: Trial division is the most laborious but easiest to understand of the integer factorization algorithms. The essential idea behind trial division tests to see if an integer n, the integer to be factored, can be divided by each number in turn that is less than or equal to the square root of n.

Key takeaways

  • Trial division belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Trial division to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Trial division from memory before moving on to harder problems.

Reference excerpt

Trial division is the most laborious but easiest to understand of the integer factorization algorithms. The essential idea behind trial division tests to see if an integer n, the integer to be factored, can be divided by each number in turn that is less than or equal to the square root of n. For example, to find the prime factors of n = 70, one can try to divide 70 by successive primes: first, 70 / 2 = 35; next, neither 2 nor 3 evenly divides 35; finally, 35 / 5 = 7, and 7 is itself prime. So 70 = 2 × 5 × 7. Trial division was first described by Fibonacci in his book Liber Abaci (1202).

Method Given an integer n (n refers to "the integer to be factored"), the trial division consists of systematically testing whether n is divisible by any smaller number. Clearly, it is only worthwhile to test candidate factors less than n, and in order from two upwards because an arbitrary n is more likely to be divisible by two than by three, and so on. With this ordering, there is no point in testing for divisibility by four if the number has already been determined not divisible by two, and so on for three and any multiple of three, etc. Therefore, the effort can be reduced by selecting only prime numbers as candidate factors, provided they are repeatedly tested until they fail. Furthermore, the trial factors need go no further than n {\displaystyle \scriptstyle {\sqrt {n}}} because if n is composite, it must have at least one factor ≤ ( n ) {\displaystyle \scriptstyle {\sqrt {(}}n)} , which would have been detected earlier; having all factors > ( n ) {\displaystyle \scriptstyle {\sqrt {(}}n)} is impossible because the product of any two would be > n. When a trial division is successful, the process is applied recursively to the resulting quotient. A definite bound on the prime factors is possible. Suppose Pi is the i'th prime, so that P1 = 2, P2 = 3, P3 = 5, etc. Then the last prime number worth testing as a possible factor of n is Pi where P2i + 1 > n; equality here would mean that Pi + 1 is a factor. Thus, testing with 2, 3, and 5 suffices up to n = 48 not just 25 because the square of the next prime is 49, and below n = 25 just 2 and 3 are sufficient. Should the square root of n be an integer, then it is a factor and n is a perfect square. The trial division algorithm in pseudocode:

algorithm trial-division is input: Integer n to be factored output: List F of prime factors of n

P ← set of all primes ≤ n {\displaystyle {\sqrt {n}}}

F ← empty list of factors

for each prime p in P do while n mod p is 0 Add factor p to list F n ← n/p

if F is empty (Original n is prime?) Add factor n to list F

Determining the primes less than or equal to n {\displaystyle {\sqrt {n}}} is not a trivial task as n gets larger, so the simplest computer programs to factor a number just try successive integers, prime and composite, from 2 to n {\displaystyle {\sqrt {n}}} as possible factors.

Speed In the worst case, trial division is a laborious algorithm. For a base-2 n digit number a, if it starts from two and works up only to the square root of a, the algorithm requires

π ( 2 n / 2 ) ≈ 2 n / 2 ( n 2 ) ln ⁡ 2 {\displaystyle \pi (2^{n/2})\approx {2^{n/2} \over \left({\frac {n}{2}}\right)\ln 2}}

trial divisions, where π ( x ) {\displaystyle \pi (x)} denotes the prime-counting function, the number of primes less than x. This does not take into account the overhead of primality testing to obtain the prime numbers as candidate factors. A useful table need not be large: P(3512) = 32749, the last prime that fits into a sixteen-bit signed integer and P(6542) = 65521 for unsigned sixteen-bit integers. That would suffice to test primality for numbers up to 655372 = 4,295,098,369. Preparing such a table (usually via the Sieve of Eratosthenes) would only be worthwhile if many numbers were to be tested. If instead a variant is used without primality testing, but simply dividing by every odd number less than the square root the base-2 n digit number a, prime or not, it can take up to about:

2 n / 2 {\displaystyle 2^{n/2}}

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Trial division

Start with the simplest possible case. Write down what Trial division claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Trial division before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Trial division ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Trial division

In research
Trial division appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Trial division in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Trial division is common in secondary-school and first-year university syllabi. It links to neighbouring topics Division (mathematics), Integer factorization algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Trial division outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Trial division” →

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Trial division in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Trial division means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Trial division out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Trial division in simple terms?

Trial division is the most laborious but easiest to understand of the integer factorization algorithms. The essential idea behind trial division tests to see if an integer n, the integer to be factored, can be divided by each number in turn that is less than or equal to the square root of n.

Why does Trial division matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Trial division?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Trial division.

Tags

  • Division (mathematics)
  • Integer factorization algorithms

Keep exploring