Special numbers

0

0 votes
Ready, Open, Recruit, Approved, Ready, Open, Recruit, Approved, Ready, Medium, Implementation, Ternary Search, approved, Searching, Algorithms, Mathematics
Problem

Special numbers are positive integers whose decimal representation contains only the special digits 2 and 5. For example, 25, 522, and 2 are the special numbers and 7, 15, and 265 are not.
Assume that f(k) is the smallest special number that is greater than or equal to k. Determine the value of the following expression for a pair (l,r):
enter image description here

Input format

  • First line: An integer T denoting the number of test cases 
  • Next T lines: Two integers l and r

Output format
For each test case, print the required answer.

Constraints
1T501lr109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

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

Editor Image

?