How do I solve complicated prime factorization problems? (Ex: 20711)

120 Views Asked by At

The prime factorization of 20711 is 139 x 149. (139 and 149 are both prime). I found this out through trial and error for a problem on one of my tests, but I don't see how to find it normally.

1

There are 1 best solutions below

6
On

How about trying $20711=20736 - 25= 144^2-5^2=(144-5)(144+5)=139*149$?
I do not know if this is valid but this is the first technique I try: finding a square number larger than the input number and then applying $a^2-b^2 = (a+b)(a-b)$.
It generally works for me, though I must say prime factorisation at my level is generally done by finding all primes lower than $\sqrt n$, where $n$ is the input number.
Is this technique even valid?

Edit: Turns out this technique is valid and was originally used by Fermat (link in the comments courtesy Mark). Using Fermat's technique in association with trial division happens to be (according to Wikipedia) be faster than either of the $2$ methods individually.