Special numbers

3.8

28 votes
Datastructures, Operators, Algorithms, Basic Math, Math
Problem

You are given a range L to R. You are required to find the number of k-special numbers in this range. A k-special number is a number whose all digits are a multiple of k.

For example:
26 is a 2-special number. Digits 2 and 6 are multiples of 2.
63 is a 3-special number. Digits 6 and 3 are multiples of 3.

Input format

  • The first line contains T denoting the number of test cases.
  • Next T lines contain integers L R k.

Output format

For each test case, print an integer in a separate line denoting the count of k-special integers in range L to R (both inclusive).

Constraints

1T1000001LR10181k9

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

1st test case

only 5 is the number that is 5-special in 5 - 10

2st test case

{20, 22, 24, 26, 28, 40} are the number that is 2-special in 20 - 40

Editor Image

?