[Login|Register]
Problems

Status

Rank

Problem 1302
Ugly number
Time Limit: 1000ms
Memory Limit: 65536kb
Description
A number is called 'ugly number' if and only if it is composed of digit 2 or 5 or 8. So the first ten 'ugly number' are: 2 5 8 22 25 28 52 55 58 82.
Now, we define two functions:
next(x) : the minimum 'ugly number ' greater or equal to x.
pre(x) : the maximum 'ugly number ' smaller or equal to x.
For example, next(3)=5, pre(24)=22.
Given an interval [S, D] (S<=D), can you compute the value of TT, defined as:
Input
The input consists of multiple test cases.
The first line, an integer T (1<=T<=100), indicates the number of test cases. Each test case has only one line, containing two numbers S and D, in which:
2<=S<=100000000
S<=D<=100000000
Output
Output the answer of each case.
Sample Input
1
2 4
Sample Output
6
Hint
next(2)-pre(2)+next(3)-pre(3)+next(4)-pre(4)=2-2+5-2+5-2=6
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.1ms with 1 query(s).