All Tracks Problem

Cool numbers
Tag(s):

Easy-Medium, Implementation, Math, approved

Problem
Editorial
Analytics

Today Oz is busy with cool numbers. Cool numbers are positive integers whose decimal representation contains only the cool digits 2 and 5. For example, numbers 25, 522, 2 are cool and 7, 15, 265 are not.
Let f(k) be the smallest cool number greater than or equals k. Oz is interested what is the value of the following expression for a given pair (l,r) :
enter image description here

Input :
The first line of input contains an integer T - number of test cases. Each test case consist of two integers l and r.

Output :
For each test case output required answer.

Constraint :
1 ≤ T ≤ 50
1 ≤ l ≤ r ≤ 109

SAMPLE INPUT
1
3 7
SAMPLE OUTPUT
59
Explanation

In the first sample:
f(3)+f(4)+f(5)+f(6)+f(7)=5+5+5+22+22=59

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

Capillary Technologies

Challenge Name

Capillary Java Developers Challenge

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications