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 be an integer and set . For trial divisors in increasing order, while record and replace with . Halt as soon as . At that point is either or a prime, and the recorded divisors together with (if ) give the prime factorization of . The method is correct because any divisor found this way is the smallest divisor greater than of the current , so it must be prime. It is also correct because a composite always has a prime factor .
Key Formula
Where:
- = The current trial divisor (2, then odd numbers or primes in increasing order)
- = 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 . Since 1,386 is even, divide it out. The cofactor 693 is odd, so 2 does not divide again.
Step 2: Try and keep dividing as long as it works. You get two factors of 3, and then 77 is not divisible by 3. Next try , which also fails because 77 does not end in 0 or 5.
Step 3: Try , which divides 77 and leaves the cofactor 11. Retest against 11. Because , you stop, and the leftover 11 must be prime. The bound shrank from to below 7, so you never test 11, 13, ..., 37.
Answer:
Why It Matters
In the worst case, when is prime or a product of two large primes, trial division needs roughly 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 , 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.
