Beautiful numbers
Practice
3.7 (13 votes)
Algorithms
Basics of greedy algorithms
Greedy algorithms
Problem
71% Success 2111 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Any number is called beautiful if it consists of $$2N$$ digits and the sum of the first $$N$$ digits is equal to the sum of the last $$N$$ digits. Your task is to find the count of beautiful numbers in the interval from $$L$$ to $$R$$ (including $$L$$ and $$R$$).

Beautiful numbers do not have leading zeroes.

Input format

  • The first line contains an integer $$T$$ denoting the number of test cases.
  • The first line of each test case contains two space-separated integers $$L$$ and $$R$$ denoting the range interval \([L,R]\).

Output format

For each test case, print the count of beautiful numbers in a new line.

Constraints

\(1 \le T \le 200000\\ 1 \le L \le R \le 1000000000\)

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:30
2 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
4 votes
Tags:
Greedy algorithmAlgorithmsArraysGreedy AlgorithmsBasics of Greedy Algorithms
Points:30
2 votes
Tags:
AlgorithmsGreedy AlgorithmsBasics of Greedy AlgorithmsGreedy algorithm