TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Techniques for Factoring Numbers in Your Head

218 pointsby exuperoover 7 years ago

13 comments

CurtMonashover 7 years ago
I factor numbers up to 3 or 4000 as my form of &quot;counting sheep&quot; when I want to relax and sleep. It&#x27;s not hard. Obviously, you only need to check primes up to the square root of the number in question. 2, 3, 5 and 11 are easy to check. Beyond that, my main trick is to quickly reduce a divisibility check to a check on a smaller number. For example, if I want to know whether 2747 is divisible by 7, that&#x27;s true if and only if 2040 is, which is divisible by 7 iff 204 is, which is divisible by 7 if 102 is, which is divisible by 7 iff 51 is, and it isn&#x27;t. Alternatively, 2747 is divisible by 7 iff 2800-2747 = 53 is, which it isn&#x27;t.<p>To check 13, I might subtract off 2600 to get 147, then also 130 to get 17. Or I might have started by adding 13 to get 2760 and hence 276, then subtracted 260 or 26.<p>To check 17 subtract it once to get 2730 and hence 273. Then add it to get 290 and hence 29.<p>To check 19 subtract 1900 to get 847, then 38 to get 805. Divide by 5 to get 161, add 19, and we&#x27;ve pretty much gotten to &quot;no&quot;.<p>For 23 add it to 2747 to get 2770 and 277, then substract 230 to get 47.<p>2900 - 2747 = 153, which can only be divisible by 29 if it equals 29 x 7 (because else the last digit wouldn&#x27;t be 3), which it doesn&#x27;t.<p>Similarly, 31 doesn&#x27;t divide 353.<p>2747 - 37 = 2710, and now there&#x27;s a special trick, because 37 divides 111. 271 - 111 = 136. 136 - 37 = 99, which 37 obviously doesn&#x27;t divide.<p>At 41 I&#x27;ll just do a size check. 41 x 57 is too small, and 57 isn&#x27;t prime anyway. 41 * 77 also couldn&#x27;t work. So it&#x27;s 41 x 67 or bust. That&#x27;s 2400 + 280 + 60 + 7 ... and we have a winner! 2747 = 41 x 67. Checking the multiplication, (40+1) x (70-3) = 2800 + 70 - 120 - 3, which indeed works out to 2747.
评论 #16069253 未加载
评论 #16069091 未加载
评论 #16074011 未加载
评论 #16068962 未加载
dahartover 7 years ago
Long division is hard to do in your head, but to determine if a number is a factor, there&#x27;s a technique in between long division and memorizing a graph walk that is probably easier to do mentally that either one (since you don&#x27;t have to memorize a graph for each divisor). With &quot;modulo division&quot; you can calculate a running remainder in your head while consuming one digit at a time of the dividend, from left to right. It gets pretty easy with just a little practice. <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Short_division#Modulo_division" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Short_division#Modulo_divisi...</a><p>The division by subtraction is fairly well known, of course, but it reminds me of the surprising square root by subtraction that I only learned about recently. It&#x27;s probably too much to do mentally, but easy with pencil &amp; paper.<p>To compute the digits of the square root of n, set a = 5n, b = 5. Repeat: if a≥b, set a=a-b, add 10 to b. Then if a&lt;b, add two zeroes to a, and add a zero to b just before the final digit (which will always be ‘5’).<p>I had to code it up myself just to believe it would work. <a href="http:&#x2F;&#x2F;www.afjarvis.staff.shef.ac.uk&#x2F;maths&#x2F;jarvisspec02.pdf" rel="nofollow">http:&#x2F;&#x2F;www.afjarvis.staff.shef.ac.uk&#x2F;maths&#x2F;jarvisspec02.pdf</a>
评论 #16068121 未加载
评论 #16067988 未加载
DoreenMicheleover 7 years ago
Tip: you only need to factor it to the midpoint. Factors occur in pairs. Identifying the smallest factors will automatically identify the largest.<p>100 is divisible by 2. 2x50=100<p>No need to wonder if 51-99 are factors. They aren&#x27;t. 50 is your largest factor.
评论 #16067438 未加载
bumbledravenover 7 years ago
Doerfler&#x27;s _ Dead Reckoning: Calculating Without Instruments _ (pages 47-73) deals extensively with this issue. <a href="https:&#x2F;&#x2F;archive.org&#x2F;stream&#x2F;deadreckoningcal00doer#page&#x2F;46&#x2F;mode&#x2F;2up" rel="nofollow">https:&#x2F;&#x2F;archive.org&#x2F;stream&#x2F;deadreckoningcal00doer#page&#x2F;46&#x2F;mo...</a>
评论 #16067825 未加载
peterburkimsherover 7 years ago
When I was in primary school, I had to memorise the &quot;times tables&quot;.<p>I realised that the digits of multiples of 9 that are under 100 always add up to 9. I was surprised when I discovered that other students didn&#x27;t notice this.<p>Others tables are easy: 10x (just add a 0), 5x (half of 10), 2x, 4x, 8x (keep multiplying by 2). That only leaves 3x, 6x, 7x, and 12x to memorise.<p>Now I have a calculator watch, I don&#x27;t need to remember the times tables. But when I was younger, it was very important to my teachers. I wish methods like this were taught instead of &quot;just memorise it&quot;.
评论 #16069728 未加载
评论 #16069832 未加载
评论 #16069945 未加载
factoring_taover 7 years ago
Two things which help me in factoring in my head:<p>To know if a number less than 100 is a prime, you just need to remember that 7 x 13 = 91. This is the only number than seems like it might be prime, but isn&#x27;t. All other composite numbers are multiples of 2, 3, 5 or 11 (easy to check quickly) or 49, widely known to be 7 x 7.<p>Secondly, if you are factoring large numbers, and you have quickly checked for division by 2, 3 and 5, you should then take the number modulo 1001. 1001 = 7 x 11 x 13, the next few primes, so you can use modulo 1001 to check for divisibility by all of these.<p>It&#x27;s easy to reduce modulo 1001, similarly to reducing modulo 11. 1000 is -1 modulo 1001, 1000000 is 1 modulo 1001, etc. So 31,415,926,535,897 = 31 - 415 + 926 - 535 + 897 mod 1001<p>These two tidbits are numerical &#x27;coincidences&#x27;, but they&#x27;re also related. Remember how 7 x 13 = 91? Well 1 &#x2F; 11 = 0.0909090909... so 1000 &#x2F; 11 = 90.9090.., just below 91, and repeating every two digits. Add one one-thousandth of itself and you get 90.9999999 = 91.
mklover 7 years ago
It looks like step 4 should say something like (edited):<p>If b evenly divides <i>a</i>×<i>r_i</i>, where <i>r_i</i> is the current value, divide by b. If not, add or subtract p until the result is evenly divisible by b, then divide by b.<p>And step 6 should loop back to step 4 and define <i>r_i</i> to be the &quot;result&quot;.<p>This method is very interesting and systematic, but it seems pretty complicated compared to ad hoc reasoning. E.g. 34 is a multiple of 17, so 680 must be too; 986-680 = 306, which is 34 away from 340, a multiple of 17, so 17 is a factor of 986.
评论 #16069739 未加载
评论 #16068277 未加载
wolfi1over 7 years ago
I can only recommend &quot;What is Mathematics&quot; by Courant and Robbins, which has a great chapter about divisibility
dmichulkeover 7 years ago
Slightly OT:<p>&gt; can I factor the current time faster than he can fall asleep?<p>If your son falls asleep within 3 minutes, you might want to consider putting him to bed earlier, especially if his exhaustion is not based on lots of physical activity.<p>Why? Because he must be really tired if he falls asleep like that which might be an indication of sleep deprivation.
Natsuover 7 years ago
&gt; Given the number n and prime p, calculate a and b. a is p subtracted from the nearest multiple of 10. b is that same multiple of 10 divided by 10.<p>This part threw me for a bit until I realized that numbers that end in 5 can&#x27;t be prime, other than 5 itself. And I don&#x27;t really need a rule to test divisibility by 5.
czbondover 7 years ago
I don&#x27;t have anything exciting to add, except to say thanks for posting it. Math was my weaker spot in school and trying to shore that up.
评论 #16069118 未加载
cervedover 7 years ago
[Math processing error]
tempthrowaway23over 7 years ago
Great post, really enjoyed it.