CSES - Numbers

Your task is to count how many numbers in the range [a,b][a,b] consist of the digits 22 and 55 only. For example, in the range [1,100][1,100] the numbers are 22, 55, 2222, 2525, 5252 and 5555, and thus the answer is 66.

In a file twodigit.py, implement the function count_numbers that counts the desired numbers in the range. The function is given the parameters aa and bb representing the end points of the range.

Your function will be tested using many different ranges. In each test, 1ab1091 \le a \le b \le 10^9.

You must implement the function efficiently so that the solution is returned quickly even for long ranges.

def count_numbers(a, b):
    # TODO

if __name__ == "__main__":
    print(count_numbers(1, 100)) # 6
    print(count_numbers(60, 70)) # 0
    print(count_numbers(25, 25)) # 1
    print(count_numbers(1, 10**9)) # 1022
    print(count_numbers(123456789, 987654321)) # 512