Given an integer N, the task is to find out the count of numbers M that satisfy the condition M + sum(M) + sum (sum(M)) = N, where sum(M) denotes the sum of digits in M.
Example 1:
Input: N = 9
Output: 1
Explaination: Only 1 positive integer satisfies 
the condition that is 3, 3 + sum(3) + sum(sum(3))
= 3 + 3 + 3 = 9. 
Example 2:
Input: N = 9939
Output: 4
Explaination: M can be 9898, 9907, 9910 and 9913. 
9898 + sum(9898) + sum(sum(9898)) = 9898 + 34 + 7 
= 9939. 
9907 + sum(9907) + sum(sum(9907)) = 9907 + 25 + 7 
= 9939. 
9910 + sum(9910) + sum(sum(9910)) = 9910 + 19 + 10 
= 9939. 
9913 + sum(9913) + sum(sum(9913)) = 9913 + 22 + 4 
= 9939. 
Your Task:
You do not need to read input or print anything. Your task is to complete the function countOfNumbers() which takes the value N and returns the count of numbers M that satisfy the given condition
Expected Time Complexity: O(logn)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def countOfNumbers(self, N):
        # code here

Solutions:
class Solution:

	def sod(self, n):
		s = 0
		while n != 0:
			s += n % 10
			n = n // 10
		return s

	def countOfNumbers(self, N):
		c = 0
		d = N - 100
		if d < 0:
			d = 0
		for i in range(d, N + 1):
			if i + self.sod(i) + self.sod(self.sod(i)) == N:
				c += 1
		return c


class Solution:

	def countOfNumbers(self, N):
		c = 0
		for i in range(N - 97, N + 1):
			a = sum(i)
			b = sum(a)
			if i + a + b == N:
				c += 1
		return c

def sum(m):
	s = 0
	while m > 0:
		r = m % 10
		m = m // 10
		s = s + r
	return s


class Solution:

	def sumD(self, N):
		sm = 0
		while N > 0:
			sm += N % 10
			N //= 10
		return sm

	def countOfNumbers(self, N):
		cn = 0
		for i in range(N - 97, N + 1):
			if i + self.sumD(i) + self.sumD(self.sumD(i)) == N:
				cn += 1
		return cn


class Solution:

	def total(self, num):
		res_total = 0
		res = 0
		while num > 0:
			res = num % 10
			res_total += res
			num = num // 10
		return res_total

	def countOfNumbers(self, N):
		count = 0
		i = N - 97
		while i <= N:
			temp_1 = self.total(i)
			temp_2 = self.total(temp_1)
			temp_3 = i + temp_1 + temp_2
			if temp_3 == N:
				count += 1
			i += 1
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.countOfNumbers(N))


def sum1(n):
	rem = 0
	sum_of_digits = 0
	while n > 0:
		rem = n % 10
		sum_of_digits += rem
		n = n // 10
	return sum_of_digits

class Solution:

	def __init__(self):
		self.c = 0
		self.a = None
		self.b = None
		self.i = None

	def countOfNumbers(self, N):
		self.c = 0
		for self.i in range(N - 97, N + 1):
			self.a = sum1(self.i)
			self.b = sum1(self.a)
			if self.i + self.a + self.b == N:
				self.c += 1
		return self.c


class Solution:

	def countOfNumbers(self, N):

		def sum(n):
			s = 0
			while n > 0:
				rem = n % 10
				n //= 10
				s += rem
			return s
		c = 0
		for i in range(N - 97, N + 1):
			a = sum(i)
			b = sum(a)
			if i + a + b == N:
				c += 1
		return c