Given a number n, write code to find the sum of digits in the factorial of the number.
Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n, the number.
Output:
Print the sum of digits in the factorial of the number.
Constraints:
1<=T<=1000
1<=n<=5000
Example:
Input:
2
10
100
Output:
27
648

Difficulty: EASY
Tags: Mathematics

Starter code:

def findSumOfDigits(n):
    
    # add code here

Solutions:
def findSumOfDigits(n):
	fact = 1
	for i in range(2, n + 1):
		fact *= i
	sum_of_digit = 0
	for i in str(fact):
		sum_of_digit += int(i)
	print(sum_of_digit)


def findSumOfDigits(n):
	r = 1
	for i in range(1, n + 1):
		r *= i
	l = [int(i) for i in str(r)]
	print(sum(l))


def findSumOfDigits(n):
	fact = 1
	for i in range(1, n + 1):
		fact *= i
	sumi = 0
	while fact > 0:
		rem = fact % 10
		sumi += rem
		fact //= 10
	print(sumi)


import math

def findSumOfDigits(n):

	def s(n):
		k = 0
		while n > 0:
			k += n % 10
			n //= 10
		return k
	fact = math.factorial(n)
	print(s(fact))


import math

def findSumOfDigits(n):
	fact = math.factorial(n)
	mlist = str(fact)
	int_list = list(map(int, mlist))
	print(sum(int_list))


import math

def findSumOfDigits(n):
	str1 = str(math.factorial(n))
	list1 = [int(i) for i in str1]
	print(sum(list1))


import math as m

def findSumOfDigits(n):
	s = list(str(m.factorial(n)))
	k = [int(i) for i in s]
	print(sum(k))


def findSumOfDigits(n):

	def f(x):
		p = 1
		if x == 0 or x == 1:
			return 1
		for i in range(2, x + 1):
			p *= i
		return p
	k = f(n)
	c = 0
	for i in str(k):
		c += int(i)
	print(c)


import math

def findSumOfDigits(n):
	k = math.factorial(n)
	a = str(k)
	l = list(map(int, a))
	print(sum(l))


from math import factorial

def findSumOfDigits(n):
	s = factorial(n)
	si = 0
	while s != 0:
		r = s % 10
		si = si + r
		s = s // 10
	print(si)


def findSumOfDigits(n):
	p = 1
	for i in range(1, n + 1):
		p *= i
	k = str(p)
	l = 0
	for j in k:
		l += int(j)
	print(l)


import math

def findSumOfDigits(n):
	a = []
	count = 0
	x = str(math.factorial(n))
	for i in x:
		a.append(i)
	for i in a:
		count = count + int(i)
	print(count)


import sys
sys.setrecursionlimit(1000001)

def fact(n):
	if n == 0:
		return 1
	return n * fact(n - 1)

def findSumOfDigits(n):
	ans = fact(n)
	s = 0
	while ans:
		s += ans % 10
		ans //= 10
	print(s)


def findSumOfDigits(n):
	f = 1
	digit = 1
	sum = 0
	for i in range(1, n + 1):
		f = f * i
	while f > 0:
		digit = f % 10
		sum = sum + digit
		f = f // 10
	print(sum)


def findSumOfDigits(n):
	import math
	s = str(math.factorial(n))
	l = [int(x) for x in s]
	print(sum(l))


def findSumOfDigits(n):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i
	sum = 0
	while fac != 0:
		sum = sum + fac % 10
		fac = fac // 10
	print(sum)


import math

def findSumOfDigits(n):
	ans = math.factorial(n)
	s = 0
	while ans > 0:
		rem = ans % 10
		s = s + rem
		ans = ans // 10
	print(s)


def findSumOfDigits(n):
	fact = 1
	sum1 = 0
	for i in range(1, n + 1):
		fact = fact * i
	fact = str(fact)
	arr = list(fact)
	for item in arr:
		sum1 = sum1 + int(item)
	print(sum1)


def findSumOfDigits(n):
	if n == 1:
		print('1')
	elif n == 2:
		print('2')
	else:
		product = 1
		summation = 0
		for i in range(n, 0, -1):
			product = product * i
		while product > 0:
			digits = product % 10
			summation = summation + digits
			product = product // 10
		print(summation)


def factorial(n):
	if n == 0:
		return 1
	if n == 1:
		return 1
	if n > 1:
		fac = 1
		for i in range(1, n + 1):
			fac = fac * i
		return fac

def findSumOfDigits(n):
	fac = factorial(n)
	total = 0
	for i in str(fac):
		total = total + int(i)
	print(total)


def findSumOfDigits(n):
	temp = 1
	for i in range(1, n + 1):
		temp *= i
	t = 0
	for i in list(str(temp)):
		t += int(i)
	print(t)


def findSumOfDigits(n):
	k = 1
	while n > 1:
		k = k * n
		n = n - 1
	m = str(k)
	su = 0
	for i in m:
		su = su + int(i)
	print(su)


def findSumOfDigits(n):
	c = 1
	while n >= 1:
		c *= n
		n -= 1
	s = 0
	while c > 0:
		r = c % 10
		s += r
		c = c // 10
	print(s)


import math

def findSumOfDigits(n):
	sum = 0
	for i in str(math.factorial(n)):
		sum = sum + int(i)
	print(sum)


from math import factorial

def findSumOfDigits(n):
	n = factorial(n)
	sum1 = 0
	while n != 0:
		sum1 += n % 10
		n //= 10
	print(sum1)


def findSumOfDigits(n):
	m = 1
	s = 0
	while n != 0:
		m *= n
		n -= 1
	while m != 0:
		s += m % 10
		m //= 10
	print(s)


def findSumOfDigits(n):
	if n == 0:
		print(1)
	s = 1
	su = 0
	for i in range(1, n + 1):
		s = s * i
	for i in str(s):
		su += int(i)
	print(su)


def findSumOfDigits(n):
	f = 1
	s = 0
	for i in range(1, n + 1):
		f *= i
	while f != 0:
		r = f % 10
		s += r
		f = f // 10
	print(s)


def findSumOfDigits(n):
	f = 1
	i = 1
	c = 0
	while i <= n:
		f *= i
		i += 1
	while f != 0:
		r = f % 10
		c += r
		f = f // 10
	print(c)


import math

def findSumOfDigits(n):
	a = []
	sum = 0
	x = str(math.factorial(n))
	for i in x:
		a.append(i)
	for j in a:
		sum += int(j)
	print(sum)


def findSumOfDigits(n):
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i
	x = 0
	fact = str(fact)
	for i in fact:
		x = x + int(i)
	print(x)


def findSumOfDigits(n):
	import math
	fact = str(math.factorial(n))
	if int(fact) > 9:
		arr = list(fact)
		ans = 0
		for v in arr:
			ans += int(v)
		print(ans)
	else:
		print(math.factorial(n))


import math

def findSumOfDigits(n):
	p = math.factorial(n)
	l = list(str(p))
	m = [int(x) for x in l]
	print(sum(m))


def findSumOfDigits(n):
	fact = 1
	for i in range(2, n + 1):
		fact = fact * i
	sum = 0
	while fact != 0:
		sum = sum + fact % 10
		fact = fact // 10
	print(sum)


def findSumOfDigits(n: int) -> None:

	def factorial(num: int) -> int:
		result = 1
		for i in range(num, 1, -1):
			result *= i
		return result

	def sumDigits(num: int) -> int:
		result = 0
		while num:
			result += num % 10
			num //= 10
		return result
	print(sumDigits(factorial(n)))


import math

def findSumOfDigits(n):
	l = []
	total = 0
	s = str(math.factorial(n))
	for i in s:
		l.append(i)
	for i in l:
		total = total + int(i)
	print(total)


def findSumOfDigits(n):
	import math
	x = math.factorial(n)
	s = 0
	for i in str(x):
		s += int(i)
	print(s)


def findSumOfDigits(n):
	p = 1
	for i in range(1, n + 1):
		p = p * i
		while p % 10 == 0:
			p = p // 10
	g = str(p)
	s = 0
	for i in g:
		s += int(i)
	return s


import math

def findSumOfDigits(n):
	f = str(math.factorial(n))
	l = list(map(int, f.strip()))
	print(sum(l))


def findSumOfDigits(n):
	product = 1
	for i in range(1, n + 1, 1):
		product *= i
	ans = str(product)
	sum = 0
	for i in ans:
		sum = sum + int(i)
	print(sum)


def findSumOfDigits(n):
	fct = 1
	if n == 0:
		print(0)
	else:
		for i in range(1, n + 1):
			fct = fct * i
	b = str(fct)
	a = [int(x) for x in b]
	print(sum(a))


from math import *

def findSumOfDigits(n):
	s = 0
	a = factorial(n)
	a = str(a)
	for i in a:
		s += int(i)
	print(s)


def findSumOfDigits(n):
	x = 1
	for i in range(1, n + 1):
		x *= i
	s = 0
	while x != 0:
		s += x % 10
		x = x // 10
	print(s)


def findSumOfDigits(n):
	if n == 0:
		print(1)
	d = 1
	for i in range(1, n + 1):
		d *= i
	ans = 0
	d = str(d)
	for i in d:
		ans += int(i)
	print(ans)
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


def findSumOfDigits(n):
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i
	factorial = str(fact)
	arr = []
	for i in factorial:
		arr.append(int(i))
	print(sum(arr))
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


import math

def findSumOfDigits(n):
	x = math.factorial(n)
	res = 0
	while x:
		res += x % 10
		x //= 10
	print(res)
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


def findSumOfDigits(n):
	p = 1
	for i in range(1, n + 1):
		p = p * i
	res = 0
	while p > 0:
		res += int(p % 10)
		p = p // 10
	print(res)
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


import math

def findSumOfDigits(n):
	fact = math.factorial(n)
	mlist = str(fact)
	int_list = list(map(int, mlist))
	print(sum(int_list))
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


def findSumOfDigits(n):
	fact = 1
	for i in range(1, n + 1):
		fact = fact * i
	fact = str(fact)
	sum = 0
	for i in fact:
		i = int(i)
		sum = sum + i
	print(sum)
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


def findSumOfDigits(n):
	(sum, fact) = (0, 1)
	while n >= 1:
		fact = fact * n
		n = n - 1
	temp = fact
	while fact != 0:
		rev = fact % 10
		fact = fact // 10
		sum = sum + rev
	print(sum)
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		n = int(input())
		findSumOfDigits(n)


def findSumOfDigits(n):
	p = 1
	for i in range(1, n + 1):
		p = p * i
	p = str(p)
	s = 0
	for i in p:
		s += int(i)
	print(s)


def fac(n):
	pro = 1
	for i in range(2, n + 1):
		pro *= i
	return pro

def findSumOfDigits(n):
	ans = fac(n)
	output = 0
	for i in str(ans):
		output += int(i)
	print(output)


def findSumOfDigits(n):
	if n == 0 or n == 1:
		print(1)
	else:
		fact = 1
		while n > 0:
			fact *= n
			n = n - 1
		s = str(fact)
		sum = 0
		for i in s:
			sum += int(i)
		print(sum)


def findSumOfDigits(n):
	prod = 1
	for i in range(1, n + 1):
		prod *= i
	prod = [int(i) for i in str(prod)]
	print(sum(prod))


import math

def findSumOfDigits(n):
	x = math.factorial(n)
	z = str(x)
	l = list(map(int, z))
	print(sum(l))


import sys
sys.setrecursionlimit(10 ** 6)
mod = 10 ** 9 + 7

def findSumOfDigits(n):
	num = factorial(n)
	summ = 0
	while num > 0:
		summ = summ + num % 10
		num //= 10
	print(summ)

def factorial(n):
	if n == 1:
		return 1
	num = factorial(n - 1)
	val = n * num
	return val


def findSumOfDigits(n):
	p = 1
	s = 0
	for i in range(1, n + 1):
		p *= i
	while p:
		d = p % 10
		s += d
		p = p // 10
	print(s)


def findSumOfDigits(n):
	pro = 1
	sum = 0
	for i in range(1, n + 1):
		pro *= i
	while pro:
		d = pro % 10
		sum += d
		pro = pro // 10
	print(sum)


import math

def findSumOfDigits(n):
	sum1 = 0
	fact = math.factorial(n)
	str1 = str(fact)
	for i in str1:
		sum1 += int(i)
	print(sum1)


import math

def findSumOfDigits(n):
	k = math.factorial(n)
	k = str(k)
	l = [int(i) for i in k]
	print(sum(l))


def findSumOfDigits(n):
	import math
	f = math.factorial(n)
	sum = 0
	while f:
		d = f % 10
		sum = sum + d
		f = f // 10
	print(sum)


def findSumOfDigits(n):
	fact = 1
	s = 0
	temp = 0
	for i in range(1, n + 1):
		fact *= i
	while fact != 0:
		temp = fact % 10
		s += temp
		fact = fact // 10
	print(s)


def findSumOfDigits(n):
	import math
	facto = str(math.factorial(n))
	sum = 0
	for i in range(len(facto)):
		sum += int(facto[int(i)])
	print(sum)


import math

def findSumOfDigits(n):
	a = math.factorial(n)
	a = str(a)
	b = list(a)
	s = 0
	for i in b:
		s += int(i)
	print(s)


import math

def findSumOfDigits(N):
	sum = math.factorial(N)
	sum1 = 0
	for i in str(sum):
		sum1 += int(i)
	print(sum1)

def fact(i):
	if i <= 1:
		return 1
	else:
		return i * fact(i - 1)


import math

def findSumOfDigits(n):
	k = math.factorial(n)
	x = [int(i) for i in str(k)]
	y = sum(x)
	print(y)


def findSumOfDigits(n):
	import math
	a = n
	import math
	n = math.factorial(n)
	n = str(n)
	a = [int(x) for x in n]
	print(sum(a))