COCI '08 Contest 5 #5 Tresnja

View as PDF

Submit solution

Points: 20
Time limit: 0.6s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Lana lives in a small but merry village. There is a row of cherry trees next to the main street. Lana numbered the trees with consecutive integers starting with 1.

After much studying, Lana noticed that the number of the tree uniquely determines the amount of cherries the tree gives.

For one tree, consider consecutive groups of digits in the tree's number. For each group of digits, multiply the digit by the square of the length of the group. Adding these numbers for all groups gives the total number of cherries the tree gives.

For example, in tree number 77\,744\,007, the groups are 777, 44, 00 and 7. The amount of cherries will be 7\cdot 3^2 + 4\cdot 2^2 + 0\cdot 2^2 + 7\cdot 1^2 = 86 units.

The time has come to pick the cherry trees and the villagers have agreed to pick all trees numbered A through B (inclusive). Write a program that will calculate the total amount of cherries picked.

Input Specification

Input consists of two integers A and B (1 \leq A \leq B \leq 10^{15}), the first and last trees to be picked.

Output Specification

Output a single integer, how many units of cherries will be picked.

Sample Input 1

1 9

Sample Output 1


Sample Input 2

100 111

Sample Output 2


Sample Input 3

7774407 7774407

Sample Output 3



There are no comments at the moment.