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

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

hide comments
2015-07-22 14:18:27
Try PR003004 after this
2015-06-26 13:02:05 :.Mohib.:
Nice one....pure maths.... :)
2015-06-25 22:31:16
Excellent Problem! At least for a beginner like me.
2015-04-28 22:24:05 Deepak Singh Tomar
great problem... worth the time... :)
2015-03-05 22:37:56 Abhinandan Agarwal
Good problem (y) ... Did it using recursion .

Last edit: 2015-03-05 22:38:22
2014-10-16 19:45:22 Infinity
WHAT will be answer for a=b;
we take sum of digits of a/b twice ?

1. its taken to be once.
2. take long long everywhere to avoid silly mistakes

Last edit: 2014-10-17 06:53:26
2014-09-02 13:55:18 Rajat (1307086)
Awesome problem. I ll not call it a pure DP but the approach is DP like..........
2013-12-15 08:29:25 meAnon
so awesome problem.. :)
2011-03-04 21:11:14 Haidar Abboud
Does the answer always fit in LONG LONG ?
----------
Tii:Yes

Last edit: 2011-03-04 21:07:34
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.