in reply to Re: Golf the numbers!
in thread Golf the numbers!
there is a rule for division by seven, but it's no use here ...
Alternatively, convert to base 8 and add the digits. :)
More useful can be to take advantage of the fact that 1001 is 7 * 11 * 13 - you can check for divisibility of all three of those in one step by adding/subtracting alternating groups of 3 digits (counting from the right).
Eg:
testing 123456789 split into groups: 789, 456, 123 add/subtract alternately: 789 - 456 + 123 = 456 factorise what's left: 456 = 2^3 * 3 * 19 so 123456789 is not divisible by 7 or 11 or 13
If the resulting number is difficult to factorise in your head, you can always add/subtract multiples of one of those primes until you get to something that obviously is/isn't a multiple of that prime:
456 = 400 + 56 (so it isn't divisible by 7) 456 = 390 + 66 (so it isn't divisible by 11 or 13)
Hugo
|
|---|