Special numbers
Practice
2.7 (4 votes)
Ready
Open
Recruit
Approved
Ready
Open
Recruit
Approved
Ready
Medium
Implementation
Ternary search
Approved
Searching
Algorithms
Mathematics
Problem
44% Success 444 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
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)\):
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
\(1 ≤ T ≤ 50\)
\(1 ≤ l ≤ r ≤ 10^9\)
Explanation
In the first sample:
f(3)+f(4)+f(5)+f(6)+f(7)=5+5+5+22+22=59
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
1.A to B
Points:30
24 votes
Tags:
AlgorithmsApprovedEasyOpen
Points:20
2 votes
Tags:
EasyMath
Points:50
9 votes
Tags:
Dynamic ProgrammingAlgorithmsC++
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor