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
David:
2014-06-11 22:42:54
I'm using a dp table dp[51][18][18][18][2] and getting TLE. Is the dimension of the table correct? or am i doing this completely wrong? |
|
ABHISHEK004:
2014-06-04 10:34:23
really an awesome problem!!!!!! made my day :)
|
|
yrocks:
2014-05-20 10:10:47
this problem cannot be solved in Python coz, range function cannot go till 10^50 |
|
(Tjandra Satria Gunawan)(曾毅昆):
2012-10-06 10:24:49
Silly mistake, I forgot about mod m, finally AC ;-) Nice problem... |
|
devu:
2012-06-30 20:15:16
Finally Accepted!!
|
|
Saransh Bansal:
2012-06-30 20:15:16
Thanks a lot.. for your comments :) |
|
Ehor Nechiporenko:
2012-06-30 20:15:16
Realy Awesome problem!!! :)) |
|
#vaidy_MIT#:
2012-06-30 20:15:16
awsme problem ...:)
|
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 |