NUMTSN - 369 Numbers
A number is said to be a 369 number if:
- The count of 3s is equal to the count of 6s and the count of 6s is equal to the count of 9s.
- The count of 3s is at least 1.
For Example 12369, 383676989, 396 all are 369 numbers whereas 213, 342143, 111 are not.
Given A and B find how many 369 numbers are there in the interval [A, B]. Print the answer modulo 1000000007.
Input
The first line contains the number of test cases (T) followed by T lines each containing 2 integers A and B.
Output
For each test case output the number of 369 numbers between A and B inclusive.
Constraints
T ≤ 100
1 ≤ A ≤ B ≤ 1050
Example
Input: 3 121 4325 432 4356 4234 4325667 Output: 60 58 207159
hide comments
ujjwald:
2024-10-22 12:59:39
thanks @vibe8955 |
|
wyyvern:
2023-08-19 12:56:27
Memorize results across different test cases, do not reinitialize memo table, To avoid TLE Last edit: 2023-08-19 12:57:07 |
|
xyz2007:
2023-08-11 05:15:13
Đỗ Thành Trọng - 11 Tin - Chuyên Biên Hòa - Hà Nam code 5 dòng cũng AC
|
|
thuylinhcbhk64:
2023-08-11 05:12:55
Mai Nhật Quang - 11 Tin - Chuyên Hà Nam nhắm mắt cũng AC
|
|
vibe8955:
2023-07-05 15:29:33
for those who are getting tle just do small optimisation that if combined count of 3,6,9 exceeds remaining places to fill then return 0 |
|
yoasobi:
2023-05-05 20:16:56
Why I am getting TLE :( |
|
hit7sh:
2022-09-08 10:18:07
answer for 1 to 10^50 => 129112453
|
|
freak2:
2020-11-20 07:46:41
even dp[51][17][17][2][2] giving tle Last edit: 2020-11-20 07:47:18 |
|
dangtiendung:
2020-11-11 10:47:56
Hoàng Anh Minh - 11 Tin - Chuyên Thái Bình trâu cũng AC Last edit: 2020-11-11 10:48:16 |
|
pranay_garg:
2019-10-10 14:50:51
How does it work if we initialize dp[] only once before test cases??
|
Added by: | Saransh Bansal |
Date: | 2012-03-21 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |