Lovely Numbers of Charan
Charan is obsessed with K-Lovely numbers and hence gave you a problem on the same.
A number is said to be K lovely if absolute difference between any two consecutive digits is at most K.
Help Charan find K-lovely numbers in a range L and R (inclusive).
All single digit numbers are K-lovely (if they fall in range)
First line will contain T, the number of test cases. Then T test cases follow.
Each test case contains three integers L,R and K, respectively.
For each test case print the total number of K-lovely integers in the given range.
- 1 <= T <= 10000
- 1 <= L <= R <= 1e18
- 0 <= K <= 9
Input: 2 1 10 1 10 20 2 Output: 10 5
Example 2 Explanation :
Among 10 to 20, only 10, 11, 12, 13, 20 have absolute difference between consecutive digits as atmost 2.All submissions for this problem are available.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions