Mathwords logoMathwords

Trial Division — Definition, Formula & Example

Trial division is the most direct way to factor a whole number. You try dividing it by 2, 3, 5, 7, and so on, and pull out each prime that divides evenly. You stop once the trial divisor squared exceeds what is left.

Let n≥2n \ge 2 be an integer and set m=nm = n. For trial divisors d=2,3,5,7,…d = 2, 3, 5, 7, \dots in increasing order, while d∣md \mid m record dd and replace mm with m/dm/d. Halt as soon as d2>md^2 > m. At that point mm is either 11 or a prime, and the recorded divisors together with mm (if m>1m > 1) give the prime factorization of nn. The method is correct because any divisor found this way is the smallest divisor greater than 11 of the current mm, so it must be prime. It is also correct because a composite mm always has a prime factor p≤mp \le \sqrt{m}.

Key Formula

keep testing d while d2≤m,where m is the current unfactored part\text{keep testing } d \text{ while } d^2 \le m, \quad \text{where } m \text{ is the current unfactored part}
Where:
  • dd = The current trial divisor (2, then odd numbers or primes in increasing order)
  • mm = The cofactor still left to factor after dividing out every factor found so far

Worked Example

Problem: Find the prime factorization of 1,386 using trial division.
Step 1: Try d=2d = 2. Since 1,386 is even, divide it out. The cofactor 693 is odd, so 2 does not divide again.
1386=2×6931386 = 2 \times 693
Step 2: Try d=3d = 3 and keep dividing as long as it works. You get two factors of 3, and then 77 is not divisible by 3. Next try d=5d = 5, which also fails because 77 does not end in 0 or 5.
693=3×231,231=3×77,77÷3=25 R 2,77÷5=15 R 2693 = 3 \times 231, \quad 231 = 3 \times 77, \quad 77 \div 3 = 25 \text{ R } 2, \quad 77 \div 5 = 15 \text{ R } 2
Step 3: Try d=7d = 7, which divides 77 and leaves the cofactor 11. Retest d=7d = 7 against 11. Because 72=49>117^2 = 49 > 11, you stop, and the leftover 11 must be prime. The bound shrank from 1386≈37\sqrt{1386} \approx 37 to below 7, so you never test 11, 13, ..., 37.
77=7×11,72=49>1177 = 7 \times 11, \qquad 7^2 = 49 > 11
Answer: 1386=2×32×7×111386 = 2 \times 3^2 \times 7 \times 11

Why It Matters

In the worst case, when nn is prime or a product of two large primes, trial division needs roughly n\sqrt{n} divisions. For a 2048-bit RSA modulus that is hopeless, which is part of why RSA encryption is considered secure. Practical factoring software still runs trial division first to strip off small prime factors cheaply. Only after that does it hand the remaining cofactor to faster methods such as Pollard's rho or the quadratic sieve.

Common Mistakes

Mistake: Dividing a prime out only once and moving on. For example, recording a single 3 for 1,386 and writing 2×3×7×112 \times 3 \times 7 \times 11, which equals only 462.
Correction: After each successful division, test the same divisor again on the new cofactor. Move to the next divisor only when there is a nonzero remainder. Check your result by multiplying the factors back together.

Related Terms