Happy Range

Welcome to the world of happy numbers. In this world, only digits 4 and
7 are happy while the rest are unhappy, so happy numbers are those
composed of 4s and 7s, e.g. 123456 and 4749 are unhappy but 774 and 4747
are happy numbers.

Given two numbers A and B, print the amount of happy numbers in the
range [A, B] such that 0 ≤ A < B ≤ 10⁹.

Input

The input starts with the number of test cases T ≤ 1000. For each test
case, there are two integers A and B that corresponds to range where we
have to look for happy numbers.

Output

For each test case, output the total number of happy numbers in the
range [A, B].

In the first example, in [1, 10] only 4 and 7 are happy so the answer is
2.

In the second example, in [44, 450], the happy numbers are 44, 47, 74,
77, 444 and 447 so the answer is 6.

Problem information

Author: Javier Segovia

Generation: 2026-01-25T22:32:55.858Z

© Jutge.org, 2006–2026.
https://jutge.org
