Monday, January 27, 2014

SPOJ 10186. Divisor Digits

Here is the problem statement
http://www.spoj.com/problems/PUCMM025/

In short, the problem wants us to find the number of digits which the given number is divisible by. The tasl is easy, you only need to check for all digits on by one with the divisibility rules you learnt in your early math grades.
1-The number is always divisible by 1
2-If the number ends with an even number the number is divisible by 2
3-If the sum of digits of the number is divisible on 3 then the number is divisible on 3 as well.
4-If the number formed with he last 2 digits of a given number is dvisible by 4 then the whole number is divisbly by 4
5- If the number ends eaitehr with a digit 0 or with a digit 5 its divisible by 5.
6- If the sum of the digits of teh numebr is divisible by 3 and the number is even that means that its divisble by 6
8- If the number formed from the last 3 digits of the given number is divisible by 8 , the given number is divisible by 8 as well.
9-If the sum of digits of the number is divisible on 9 then the number is divisible on 9 as well.
 I left 7 on purpose. The divisibility on 7 is very tricky, I think I can mess up If I try to explain it, I found a good explaination here.


       DOWNLOAD THE FULL SOURCE CODE



No comments:

Post a Comment