TITLE: How to factor 5671?
QUESTION [5 upvotes]: The other day I wanted to factor 5671 in my head. (It turns out to be $53\cdot107$, but I did not know this at the time.)  I quickly ruled out the easy divisors, 2, 3, 5, 7, 11, and 13. At this point I saw no obvious way to proceed short of a very tedious trial division.
But I did notice that 5671 has a residue of 1 modulo 2, 3, 5, and 7. Is there any way to use this coincidence to reduce or simplify the problem of finding a factorization of 5671, perhaps by ruling out certain types of divisors?

REPLY [3 votes]: The comments below the question suggest the Fermat method, but neglects to state how you would go about doing the Fermat method mentally. Here's how I'd approach it mentally.
First, you need to be familiar with all possible 2-digit endings of squares:
$${00, 01, 04, 09, 16, 21, 24, 25, 29, 36, 41, 44, 49, 56, 61, 64, 69, 76, 81, 84, 89, 96}$$
Note that there are several patterns that make this easier:
1) If the units digit of a perfect square is 1, 4, or 9, then the tens digit must be even (01, 21, 41, 61, 81 and 04, 24, 44, 64, 84 and 09, 29, 49, 69, 89).
2) If the units digit of a perfect square is 6, then the tens digit must be odd (16, 36, 56, 76, 96).
3) If the units digit of a perfect square is 0, then the tens digit is also a 0.
4) If the units digit of a perfect square is 5, then the tens digit is a 2.
You should also be able to square two digit numbers in your head and understand that the squares of the numbers 1-25 contain every possible 2-digit endings of squares.
Using the Fermat approach, we're going to factor the given number m in the follow manner:
$$m=A^{2}-B^{2}$$
We start by finding out which 1 of the following 3 questions apply, so that we can work out what values of A^2 are worth checking:
1) Are the last 2 digits of m also possible as the 2-digit ending of a square? If so, the last two digits of A^2 are either 25 or the same as the last 2 digits of m.
2) Are the last 2 digits of m a hundreds complement (100-last two digits) to the last two digits of a square? If so, the last two digits of A^2 are either 00 or equal to the last 2 digits of m+25 (mod 100, if needed).
3) If neither of the first two questions apply, then m must have a units digit of 3 or 7. Now we can determine the units digit of A^2 using these questions:
a) Is the 2-digit ending of m equal to 03, 23, 43, 63, or 83? If so, A^2 ends in 4.
b) Is the 2-digit ending of m equal to 07, 27, 47, 67, or 87? If so, A^2 ends in 6.
c) Is the 2-digit ending of m equal to 13, 33, 53, 73, or 93? If so, A^2 ends in 9.
d) Is the 2-digit ending of m equal to 17, 37, 57, 77, or 97? If so, A^2 ends in 1.
Shortcut for 3a-3d: If the units digit of m is a 3, then the units digit of A^2 is a square number (4 or 9). If the units digit of m is a 7, then the units digit of A^2 is NOT a square number (1 or 6). In both cases, to decide between your two choices here, choose the odd one when then tens digit is odd, and the even one when the tens digit is even.
Let's apply this to the 5671 problem.
Are the last 2 digits, 71, the ending of a perfect square? No, so forget this question.
Can you take the last 2 digits, 71, and add a square ending to get 100? Yes, you can add 29 to make 100. Now we know that A^2, if it exists (we still haven't determined whether 5671 is prime), ends in either 00 or 96 (71 + 25).
What numbers will yield a square ending in 00? Anything ending in a multiple of 10. What numbers will yield a square ending in 96? Any number which is 14 away from a multiple of 50 (14, 36, 64, 86, 114, 136, etc.).
Where do we start? Well, 5671 is above 75^2 (5625), so 76 should be our minimum starting point. In other words, we'll check numbers 76 or greater that either end in 0, or are 14 away from a multiple of 50. In other words, we're limiting our possibilities for A to 80, 86, 90, 100, 110, 114, and so on.
OK, let's start with 80^2 (6400). Is 6400-5671 a square number? As it happens, the answer, 729, is 27^2! We got lucky on the first try, discovering:
$$5671=80^{2}-27^{2}$$
What does this tell us? Remember:
$$A^{2}-B^{2}=(A+B)(A-B)$$
So, the factors of 5671 are:
$$(80+27)(80-27)\\107\times53$$