Given two integers L, R, and digit X.Find the number of occurrences of X in all the numbers in the range (L, R) Excluding L and R.
Example 1:
Input:
L=10,R=19,X=1
Output:
9
Explanation:
There are 9 1s in the numbers in the
range (10,19).
Example 2:
Input:
L=18,R=81,X=9
Output:
7
Explanation:
There are 7 occurrences of the digit 9
in the numbers in the range (18,81).
Your Task:
You don't need to read input or print anything. Your task is to complete the function countX() which takes three integers L, R, and X as input parameters and returns the number of occurrences of X in the numbers in the range(L, R).
Expected Time Complexity:O(RLogR)
Expected Auxillary Space:O(1)
 
Constraints:
1<=L<R<=10^{5}
0<=X<10

Difficulty: EASY
Tags: Number theory

Mathematics
Expected Time Complexity: O(RLogR)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3

class Solution:    
    def countX(self,L,R,X):
        #code here


Solutions:
class Solution:

	def countX(self, L, R, X):
		c = 0
		for i in range(L + 1, R):
			n = i
			while n:
				d = n % 10
				if d == X:
					c = c + 1
				n = n // 10
		return c


class Solution:

	def countX(self, L, R, X):
		count = 0
		for i in range(L + 1, R):
			i = str(i)
			for j in i:
				if int(j) == X:
					count += 1
		return count


class Solution:

	def countX(self, L, R, X):
		k = ''
		for i in range(L + 1, R):
			k += str(i)
		res = k.count(str(X))
		return res


class Solution:

	def countX(self, L, R, X):
		c = ''
		count = 0
		for i in range(L + 1, R):
			c += str(i)
		return c.count(str(X))


class Solution:

	def countX(self, L, R, X):
		ans = 0
		for i in range(L + 1, R):
			arr = list(str(i))
			ans += arr.count(str(X))
		return ans


class Solution:

	def countX(self, L, R, X):
		c = 0
		p = str(X)
		for i in range(L + 1, R):
			s = str(i)
			if p in s:
				for j in range(len(s)):
					if p == s[j]:
						c = c + 1
			else:
				pass
		return c


class Solution:

	def countX(self, L, R, X):
		sum = 0
		X = str(X)
		for i in range(L + 1, R):
			st = str(i)
			for i in range(len(st)):
				if X in st[i]:
					sum = sum + 1
		return sum


class Solution:

	def countX(self, L, R, X):
		an = 0
		X = str(X)
		for i in range(L + 1, R):
			k = str(i)
			if X in k:
				an += k.count(X)
		return an


class Solution:

	def countX(self, L, R, X):
		s = 0
		for i in range(L + 1, R):
			while i > 0:
				p = i % 10
				i = i // 10
				if p == X:
					s += 1
		return s


class Solution:

	def countX(self, L, R, X):
		s = ''
		for i in range(L + 1, R):
			s += str(i)
		return s.count(str(X))


class Solution:

	def countX(self, L, R, X):
		ans = ''.join(map(str, range(L + 1, R)))
		return ans.count(str(X))


class Solution:

	def countX(self, L, R, X):
		c = 0
		L = L + 1
		while L < R:
			if str(X) in str(L):
				c = c + str(L).count(str(X))
			L = L + 1
		return c


class Solution:

	def countX(self, L, R, X):
		l = []
		for i in range(L + 1, R):
			l.append(str(i))
		ans = ''.join(l)
		c = 0
		for i in ans:
			if int(i) == X:
				c = c + 1
		return c


class Solution:

	def countX(self, L, R, X):
		count = 0
		L = L + 1
		while L < R:
			n = L
			while n > 0:
				r = n % 10
				if r == X:
					count = count + 1
				n = n // 10
			L = L + 1
		return count


from collections import Counter

class Solution:

	def countX(self, L, R, X):
		arr = []
		for i in range(L + 1, R):
			arr += [*str(i)]
		c = Counter(arr)
		return c[str(X)]


class Solution:

	def countX(self, l, r, x):
		li = []
		c = 0
		for i in range(l + 1, r):
			while i > 0:
				if i % 10 == x:
					c += 1
				i //= 10
		return c


class Solution:

	def countX(self, L, R, X):
		ans = 0
		for i in range(L + 1, R):
			num = i
			count = 0
			while num > 0:
				digits = num % 10
				if digits == X:
					count += 1
				num = num // 10
			ans += count
		return ans


class Solution:

	def countX(self, L, R, X):
		ans = 0
		for n in range(L + 1, R):
			while n > 0:
				if n % 10 == X:
					ans += 1
				n = int(n / 10)
		return ans


class Solution:

	def countX(self, l, r, X):
		h = ''
		c = 0
		for i in range(l + 1, r):
			h += str(i)
		for i in h:
			if i == str(X):
				c += 1
		return c


class Solution:

	def countX(self, L, R, X):
		if X > 9:
			return 0
		ans = 0
		s = ''
		for i in range(L + 1, R):
			s = str(i)
			ans += s.count(str(X))
		return ans


class Solution:

	def countX(self, L, R, X):
		count = 0
		x = str(X)
		for i in range(L + 1, R):
			y = str(i)
			if x in y:
				count += y.count(x)
		return count


class Solution:

	def countX(self, L, R, X):
		c = 0
		x = str(X)
		for n in range(L + 1, R):
			strn = str(n)
			if x in strn:
				c += strn.count(x)
		return c


class Solution:

	def countX(self, L, R, X):
		count = 0
		for i in range(L + 1, R):
			while i != 0:
				digit = i % 10
				i = i // 10
				if digit == X:
					count += 1
		return count


class Solution:

	def countX(self, L, R, X):
		c = r = 0
		if L > 1 and R <= 9:
			return 0
		for i in range(L + 1, R):
			while i > 0:
				r = i % 10
				if r == X:
					c += 1
				i = i // 10
		return c


class Solution:

	def countX(self, L, R, X):
		x_count = 0
		str_x = str(X)
		for n in range(L + 1, R):
			str_n = str(n)
			if str_x in str_n:
				x_count += str_n.count(str_x)
		return x_count


class Solution:

	def countX(self, L, R, X):
		c = 0
		for i in range(L + 1, R):
			li = []
			x = str(i)
			for k in x:
				if k == str(X):
					c += 1
		return c


class Solution:

	def countX(self, L, R, X):
		count = 0
		xval = str(X)
		for i in range(L + 1, R):
			ival = str(i)
			if xval in ival:
				count += ival.count(xval)
		return count


class Solution:

	def countX(self, L, R, X):
		count = 0
		for i in range(L + 1, R):
			count += str(i).count(str(X))
		return count
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(L, R, X) = map(int, input().strip().split(' '))
		ob = Solution()
		ans = ob.countX(L, R, X)
		print(ans)


class Solution:

	def countX(self, L, R, X):
		lst = range(L + 1, R)
		lst = list(map(lambda x: str(x), lst))
		s = ''.join(lst)
		return s.count(str(X))
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(L, R, X) = map(int, input().strip().split(' '))
		ob = Solution()
		ans = ob.countX(L, R, X)
		print(ans)


class Solution:

	def countX(self, L, R, X):
		oc = 0
		for x in range(L + 1, R):
			oc += self.count(x, X)
		return oc

	def count(self, n, x):
		n = str(n)
		if str(x) in n:
			aux = len(n)
			n = n.replace(str(x), '')
			return aux - len(n)
		return 0
import math
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(L, R, X) = map(int, input().strip().split(' '))
		ob = Solution()
		ans = ob.countX(L, R, X)
		print(ans)


class Solution:

	def countX(self, l, r, x):
		ans = 0
		for i in range(l + 1, r):
			ans += str(i).count(str(x))
		return ans