Fastest way to find sum of digits on big numbers

Posted by dada on Stack Overflow See other posts from Stack Overflow or by dada
Published on 2010-04-15T20:35:45Z Indexed on 2010/04/15 20:43 UTC
Read the original article Hit count: 218

Filed under:
|
|
|

I have some big numbers (again) and i need to find if the sum of the digits is an even number. I tried this: finding the sum of the digits with a while loop and then checking if that sum % 2 equals 0 and it's working but it's too slow for big numbers, because i am given intervals of numbers and if the input is 1999999 19999999999 then my program fails, i cannot complete within the time limit which is 0,1 sec.

What to do ? Is there any other faster way to do this ?

EDIT: The input 1999999 19999999999 means it will start with 1999999 and check all the numbers like i wrote above until 19999999999, and because we are talking about big numbers (< 2^30) my program is not worthy.

© Stack Overflow or respective owner

Related posts about school

Related posts about problem