Solution to Number Of Ones from Jobdu

31 Aug

Question (in Chinese): http://ac.jobdu.com/problem.php?pid=1373

Question Name: Number Of Ones

Question Description: Given an integer, find the number of 1s in the string representation of all integers from 0 to it.

Input: the input might contain multiple test cases. Each test case contains one single line, which includes two integers N and M (0 <= N, M <= 1000000000).

Output: For each test case, print the number of 1s in the string representation of all integers between N and M (both inclusive).

The official solution converts the integers to string and then computes. While my solution deals with the integers directly.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please put your code into a <pre>YOUR CODE</pre> section. Thanks and Happy Coding!