Checking divisibility of a number

Avatar image for sub_o
sub_o

1261

Forum Posts

38

Wiki Points

0

Followers

Reviews: 2

User Lists: 8

Edited By sub_o

The ability to check whether a number is divisible by, say 4 or 9, seems to be useless at first.

But it could be a time saver when you're trying to check the result of your calculation without resorting to a calculator. Or it could be a mental trick (or what Arthur Benjamin says as Mathemagic) which you can use it for fun while drinking some beers in the pub.

Here are some of them:

- Divisibility by 2:

Very simple, check if the last digit is even or not. Thus 928474712 is divisible by 2, while 361635 is not.

- Divisibility by 3:

Quite simple, sum up all the digits in that number, and check if it's multiples of 3.

Say you have a 7 digit number 9282648.

Sum up all the digits in that number, i.e: 9 + 2 + 8 + 2 + 6 + 4 + 8 = 39

39 is divisible by 3 (39 / 3 = 13), thus 9282648 is divisible by 3 ( 9282648 / 3 = 3094216 )

or you can go several steps further, keep summing up the digits, i.e. 3 + 9 = 12 then 1 + 2 = 3

- Divisibility by 4:

Check if the last 2 digits are divisible by 4( or if you didn't memorize multiplication table of 4, then check if you can divide the last 2 digits of the number twice, since, you know 4 = 2 x 2 ).

Example: 948137924 is divisible by 4, since 24 is 6 x 4. ( 948137924 / 4 = 237034481 )

- Divisibility by 5:

Check if the last digit is 5 or 0 (e.g. 242452525, or 80808083130 )

- Divisibility by 6:

Similar to divisibility by 3, but the original number should be even number.

E.g. 9282648 is divisible by 6 and 3, while 9282645 is divisible by 3 but not by 6.

- Divisibility by 7:

For divisibility by 7, I only know the trick that uses recursive method.

  1. Separate the digits of the number into last digit and the rest of the digits.
  2. Do this: (rest of the digits) - (2 x last digit)
  3. Check if the result is multiple of 7, if yes, then voila, else repeat from step 1

Example: 2443

  1. last digit = 3, rest of the digits = 244
  2. 244 - (2 * 3) = 238
  3. Not sure if it's divisible by 7
  4. last digit = 8, rest of the digits = 23
  5. 23 - ( 2 * 8 ) = 7
  6. Divisible by 7

- Divisibility by 8:

The last 3 digits should be divisible by 8. If it's hard to check if 3 digits number is divisible by 8, try to divide it by 2 for 3 times (since 8 = 2 x 2 x 2)

Example: 24752, last 3 digits = 752.

If it's hard to see whether 752 is divisible by 8, then keep subtracting 752 with 200, until you reached a number below 200, which is in this case 152, which is divisible by 8 (152 / 8 = 19).

Thus 24752 is divisible by 8 (24752 / 8 = 3094)

- Divisibility by 9:

Similar to divisibility by 3, but this time it will end up with multiple of 9, or if you keep doing it, it will end up with 9.

Multiple of 9 is very pretty, since

1 x 9 = 096 x 9 = 54
2 x 9 = 187 x 9 = 63
3 x 9 = 278 x 9 = 72
4 x 9 = 369 x 9 = 81
5 x 9 = 459 x10= 90

The sum of the digits of the result will always be 9.

Example: 1111111101 is divisible by 9, since 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 = 9. (1111111101 / 9 = 123456789)

or 7992 is divisible by 9, since 7 + 9 + 9 + 2 = 27, and 2 + 7 = 9. (7992 / 9 = 888)

There you go, I posted it after trying to figure out what's being outputted by OpenCV's HOGDescriptor's compute function, since it gives me a 1D vector of floating numbers with the size of 7 digit numbers. Then after pondering a while, I realized that the size of that 7 digit numbers is divisible by 9, thus it should be a flattened version of 9 normalized bins. You don't need to understand what I am saying though.

Avatar image for sub_o
sub_o

1261

Forum Posts

38

Wiki Points

0

Followers

Reviews: 2

User Lists: 8

#1  Edited By sub_o

The ability to check whether a number is divisible by, say 4 or 9, seems to be useless at first.

But it could be a time saver when you're trying to check the result of your calculation without resorting to a calculator. Or it could be a mental trick (or what Arthur Benjamin says as Mathemagic) which you can use it for fun while drinking some beers in the pub.

Here are some of them:

- Divisibility by 2:

Very simple, check if the last digit is even or not. Thus 928474712 is divisible by 2, while 361635 is not.

- Divisibility by 3:

Quite simple, sum up all the digits in that number, and check if it's multiples of 3.

Say you have a 7 digit number 9282648.

Sum up all the digits in that number, i.e: 9 + 2 + 8 + 2 + 6 + 4 + 8 = 39

39 is divisible by 3 (39 / 3 = 13), thus 9282648 is divisible by 3 ( 9282648 / 3 = 3094216 )

or you can go several steps further, keep summing up the digits, i.e. 3 + 9 = 12 then 1 + 2 = 3

- Divisibility by 4:

Check if the last 2 digits are divisible by 4( or if you didn't memorize multiplication table of 4, then check if you can divide the last 2 digits of the number twice, since, you know 4 = 2 x 2 ).

Example: 948137924 is divisible by 4, since 24 is 6 x 4. ( 948137924 / 4 = 237034481 )

- Divisibility by 5:

Check if the last digit is 5 or 0 (e.g. 242452525, or 80808083130 )

- Divisibility by 6:

Similar to divisibility by 3, but the original number should be even number.

E.g. 9282648 is divisible by 6 and 3, while 9282645 is divisible by 3 but not by 6.

- Divisibility by 7:

For divisibility by 7, I only know the trick that uses recursive method.

  1. Separate the digits of the number into last digit and the rest of the digits.
  2. Do this: (rest of the digits) - (2 x last digit)
  3. Check if the result is multiple of 7, if yes, then voila, else repeat from step 1

Example: 2443

  1. last digit = 3, rest of the digits = 244
  2. 244 - (2 * 3) = 238
  3. Not sure if it's divisible by 7
  4. last digit = 8, rest of the digits = 23
  5. 23 - ( 2 * 8 ) = 7
  6. Divisible by 7

- Divisibility by 8:

The last 3 digits should be divisible by 8. If it's hard to check if 3 digits number is divisible by 8, try to divide it by 2 for 3 times (since 8 = 2 x 2 x 2)

Example: 24752, last 3 digits = 752.

If it's hard to see whether 752 is divisible by 8, then keep subtracting 752 with 200, until you reached a number below 200, which is in this case 152, which is divisible by 8 (152 / 8 = 19).

Thus 24752 is divisible by 8 (24752 / 8 = 3094)

- Divisibility by 9:

Similar to divisibility by 3, but this time it will end up with multiple of 9, or if you keep doing it, it will end up with 9.

Multiple of 9 is very pretty, since

1 x 9 = 096 x 9 = 54
2 x 9 = 187 x 9 = 63
3 x 9 = 278 x 9 = 72
4 x 9 = 369 x 9 = 81
5 x 9 = 459 x10= 90

The sum of the digits of the result will always be 9.

Example: 1111111101 is divisible by 9, since 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 = 9. (1111111101 / 9 = 123456789)

or 7992 is divisible by 9, since 7 + 9 + 9 + 2 = 27, and 2 + 7 = 9. (7992 / 9 = 888)

There you go, I posted it after trying to figure out what's being outputted by OpenCV's HOGDescriptor's compute function, since it gives me a 1D vector of floating numbers with the size of 7 digit numbers. Then after pondering a while, I realized that the size of that 7 digit numbers is divisible by 9, thus it should be a flattened version of 9 normalized bins. You don't need to understand what I am saying though.

Avatar image for deactivated-5b8316ffae7ad
deactivated-5b8316ffae7ad

826

Forum Posts

230

Wiki Points

0

Followers

Reviews: 1

User Lists: 1

Good and fun read, thanks!

Avatar image for veektarius
veektarius

6420

Forum Posts

45

Wiki Points

0

Followers

Reviews: 11

User Lists: 1

#3  Edited By veektarius

I was going to give you shit about this when I first started reading, but I didn't know any of this besides for 2 and 5, so kudos.

Avatar image for fourwude
FourWude

2274

Forum Posts

0

Wiki Points

0

Followers

Reviews: 1

User Lists: 0

#4  Edited By FourWude

MATHEMAGIC!!!

Avatar image for oldguy
OldGuy

1714

Forum Posts

28

Wiki Points

0

Followers

Reviews: 0

User Lists: 3

#5  Edited By OldGuy

That 7 recursion trick is cool... but now I've got Schoolhouse Rock running around in my head (math does that to me):

Avatar image for sub_o
sub_o

1261

Forum Posts

38

Wiki Points

0

Followers

Reviews: 2

User Lists: 8

#6  Edited By sub_o

Thanks a lot ! I found these tricks pretty interesting. These tricks might be handy for students who are preparing for SAT / GRE / GMAT too.