CPCRC1C - Sum of Digits


Majid is a 3rd-grade elementary student and quite well in mathematics. Once, Majid's teacher asked him to calculate the sum of numbers 1 through n.

Majid quickly answered, and his teacher made him another challenge. He asked Majid to calculate the sum of the digits of numbers 1 through n.

Majid did finally find the solution. Now it is your turn, can you find a solution?

Input

Two space-separated integers 0 <= a <= b <= 109.

Program terminates if a and b are -1.

Output

The sum of the digits of numbers a through b.

Example

Input:
1 10
100 777
-1 -1

Output:
46
8655

hide comments
akashranjan28: 2016-12-07 17:36:31

take long long instead of int for c++ user
nice question

kira28: 2016-12-06 20:21:46

the #dp tag was quite misleading...
it took me quite a while to convince myself that its just maths...

square1001: 2016-09-16 13:45:37

It is very typical.

liuxueyang: 2016-08-15 06:38:02

Here is my solution: <snip>
It can be solved if the number base is given.

Last edit: 2022-10-03 20:01:07
liuxueyang: 2016-08-14 15:10:35

@iharsh234: thank you. ;-)

iharsh234: 2016-07-30 10:55:54

Cool Problems on DDP:)
http://www.spoj.com/problems/CPCRC1C/
http://www.spoj.com/problems/LUCIFER/
http://www.spoj.com/problems/RAONE/
http://www.spoj.com/problems/GONE/
will solve some day!
Have a try guys!

mkfeuhrer: 2016-07-23 07:02:38

yess!! 250 AC :-) #math

avisheksanvas: 2016-07-12 07:54:09

The #dp tag. :p
Pure Math!

alok singh: 2016-07-10 18:29:56

binary mistake cost many 3 wrong answer.. nice :)

Deepak : 2016-07-09 23:38:02

nice problem...


Added by:Tii
Date:2010-10-25
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:http://cs.ikiu.ac.ir/cms/icpc/training/7-contest/86-contest1