Harshad Numbers

0

0 votes
Hard
Problem

Daksh loves mathematics more than he loves his cold drinks and chips. One fine day while strolling through the Learning Resource Centre he found an intresting book on Harshad Numbers . A harshad number (or Niven number), is an integer that is divisible by the sum of its digits .

digitSum(n) : Sum of digits of n (in Decimal Representation)

eg: n = 200 then digitSum(n) = 2+0+0= 2

as 200%digitsum(200) is 0, 200 is a Harshad Number.

Daksh being the lazy guy he is, asked Raman to tell the number of Harshad Numbers in range [L,R] inclusive. Raman does not know the answer,So he asked his Coder friend i.e you for the help. Help him !!

Input:

  • First line contains 'T' i.e number of test cases .
  • Next T lines contain 2 integers 'A' and 'B' respectively.

Output:

  • Print the answer in a new line .

Constraints:

  • 1 <= T <= 50
  • 1<=A,B<=109
Sample Input
4
2 5
1 10
20 45
1 100
Sample Output
4
10
9
33
Time Limit: 1
Memory Limit: 256
Source Limit:
Contributers:
Editor Image

?