Sunday, August 24, 2014

COJ 1573. Just Another Easy Problem

The task consists of 2 parts, conversion and check. First of all conversion. If we have a hex number and want to convert it to decimal we have to do the following. We need to multiply every digit with the power of it's index base 16 counting from the right to left. For example we have a number ABCD , after converting to decimal it will be 13*(16^0) + 12* (16^1) + 11*(16^2) + 10* (16^3).  Now let's check for the divisibility. The sum of numbers form 1 to N is N*(N+1) /2 and it is easy to notice that when N is odd then the result is divisible otherwise not.


       FULL SOURCE CODE

No comments:

Post a Comment