News for hackers. Stuff that matters.
Re:Quick - is 91 prime? by jgrahamc on Wednesday March 12, 2008 @09:00AM (#135098)
Nice math hack. The 11 and 7 ones were new to me.

Here's some more fun: http://www.jgc.org/blog/2008/02/sum-of-first-n-odd-numbers-i...

Re:Quick - is 91 prime? by staticshock on Wednesday March 12, 2008 @10:30AM (#135137)
7 was new to me too, that's an odd one

there's also another trick for 11 that comes from addition. 1234 * 11 = 12340 + 1234 = 13574 (or, by digit: 1 (1+2) (2+3) (3+4) 4). that makes 3 digit multiples easy to detect. for instance, 484: 8 is clearly 4+4, so it's divisible by 11 (440 + 44).

it's slightly more tedious for >3 digit numbers. for instance, 1353: from left to right: 3 = 1 + ..2, 5 = 2 + ..3. 3 == 3, so it'd divisible by 11. i guess i explained this somewhat poorly, sorry for that.

it's also somewhat harder if you have carries.

Re:Quick - is 91 prime? by philh on Wednesday March 12, 2008 @12:36PM (#135230)
What I use for 11 is take the final digit, subtract the penultimate, add the third last, etc. The result = the original number (mod 11). Obviously it works if you start at the MSD, but then you need to worry about whether there's an even number of digits, in which case you need to negative the answer.

Seven wasn't new to me, but I've never been able to remember it. Maybe I will this time.