Himanshu and Luck
Practice
3.5 (173 votes)
Binary search algorithm
Hiring
Recursion
Brute Force search
Easy Medium
Ready
Approved
Backtracking
Problem
48% Success 4014 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Himanshu is quite a lucky person, or atleast he claims to be. Recently, he has started some research work in college and guess what is he researching on? Lucky Numbers! While doing his bit of research, a fellow colleague of him asked him a pretty awkward question : "Given a range as input, find the number of lucky numbers lying in that range!". Himanshu somehow solved this problem, but now he has a bigger challenge for you : "There are Q queries, each of which contains a range. Find out the number of lucky numbers lying in each range (inclusive of end points)." Are you up for this hack?

Note : A number is a lucky number if it contains 4 or 7, or both in its decimal representation.

Examples:
1) 147 is not a Lucky Number as it contains 1 as an extra element, which violates the property of Lucky Numbers.
2) 47, 44, 77 , 447, 774, 4, 7 are the examples of Lucky number.

Input Format
First line contains T, the number of test cases. Each of the next T lines contains two space separated integers L and R, depicting the range.

Output Format

For each of the T lines, output one integer : The answer as specified.

Constraints

1 <= T <= 10000

1 <= L <= R <= 10^18

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
6 votes
Tags:
Dijkstra's AlgorithmMedium
Points:30
Tags:
Easy-Medium
Points:30
5 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMathMediumOpen