Strong Numbers are the numbers whose sum of factorial of digits is equal to the original number. Given a number N, the task is to check if it is a Strong Number or not. Print 1 if the Number is Strong, else Print 0.
 
Example 1: 
Input:
N = 145
Output:
1
Explanation:
1! + 4! + 5! = 145 So, 145 is a Strong
Number and therefore the Output 1.
Example 2: 
Input:
N = 14
Output:
0
Explanation:
1! + 4! = 25 So, 14 isn't a Strong
Number and therefore the Output "NO".
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function isStrong() which takes an Integer N as input and returns the answer.
 
Expected Time Complexity: O(|N|)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{8}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

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

Solutions:
class Solution:

	def isStrong(self, N):

		def fact(n):
			if n == 1 or n == 0:
				return 1
			return n * fact(n - 1)
		sumo = 0
		n = N
		while n != 0:
			r = n % 10
			sumo = sumo + fact(r)
			n = n // 10
		if sumo == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, n):
		sumi = 0
		a = n
		while n > 0:
			rem = n % 10
			fact = 1
			for i in range(1, rem + 1):
				fact *= i
			sumi += fact
			n //= 10
		if sumi == a:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		summ = 0
		for i in str(N):
			import math
			summ += math.factorial(int(i))
		if summ == N:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		s = 0
		rrr = N
		while N != 0:
			f = 1
			r = N % 10
			for i in range(1, r + 1):
				f *= i
			s += f
			N //= 10
		if s == rrr:
			return 1
		return 0


class Solution:

	def isStrong(self, n):
		a = n
		summ = 0
		while a > 0:
			b = a % 10
			f = 1
			a = int(a / 10)
			for i in range(1, b + 1):
				f = f * i
			summ += f
		if summ == n:
			return 1
		else:
			return 0


import math

class Solution:

	def isStrong(self, n):
		m = n
		num = 0
		while m:
			k = m % 10
			num += math.factorial(k)
			m = m // 10
		return 1 if n == num else 0


import math

class Solution:

	def isStrong(self, N):
		sum = 0
		mstr = str(N)
		for num in mstr:
			sum += math.factorial(int(num))
		return 1 if N == sum else 0


class Solution:

	def isStrong(self, N):
		import math
		s = str(N)
		d = [math.factorial(int(x)) for x in s]
		j = sum(d)
		if j == N:
			return 1
		else:
			return 0


class Solution:

	def fact(self, n):
		k = 1
		for i in range(1, n + 1):
			k = k * i
		return k

	def isStrong(self, N):
		m = str(N)
		s = 0
		for i in m:
			s = s + self.fact(int(i))
		if N == s:
			return 1
		else:
			return 0


class Solution:

	def factorial(self, n):
		return 1 if n == 0 else self.factorial(n - 1) * n

	def isStrong(self, N):
		s = 0
		for i in str(N):
			s += self.factorial(int(i))
		return 1 if s == N else 0


from math import factorial

class Solution:

	def isStrong(self, N):
		s = 0
		p = N
		while N != 0:
			r = N % 10
			s = s + factorial(r)
			N = N // 10
		if p == s:
			c = 1
		else:
			c = 0
		return c


class Solution:

	def isStrong(self, N):

		def fact(n):
			res = 1
			for i in range(2, n + 1):
				res *= i
			return res
		digit_sum = 0
		temp = N
		while temp > 0:
			digit = temp % 10
			digit_sum += fact(digit)
			temp //= 10
		if N == digit_sum:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		temp = N

		def fact(k):
			s = 1
			for i in range(1, k + 1):
				s *= i
			return s
		res = 0
		while N > 0:
			a = N % 10
			res = res + fact(a)
			N //= 10
		if temp == res:
			return 1
		else:
			return 0


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

class Solution:

	def isStrong(self, n):
		N = n
		s = 0
		while n:
			dig = n % 10
			s += fact(dig)
			n //= 10
		return int(s == N)


class Solution:

	def isStrong(self, N):
		temp = N
		result = 0
		while temp > 0:
			rem = temp % 10
			fact = 1
			for i in range(1, rem + 1):
				fact = fact * i
			result += fact
			temp = temp // 10
		if N == result:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):

		def fa(x):
			p = 1
			if x == 0 or x == 1:
				return 1
			else:
				for i in range(2, x + 1):
					p *= i
				return p
		c = 0
		for i in range(len(str(N))):
			c += fa(int(str(N)[i]))
		if c == N:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		sum = 0
		ans = str(N)
		for i in ans:
			sum = sum + math.factorial(int(i))
		if sum == N:
			return 1
		return 0


from math import factorial

class Solution:

	def isStrong(self, N):
		x = 0
		y = N
		while y != 0:
			rem = y % 10
			x = x + factorial(rem)
			y = y // 10
		if x == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		l = []
		s = 0
		temp = N
		while N > 0:
			rem = N % 10
			l.append(rem)
			N = N // 10
		for i in l:
			s = s + math.factorial(i)
		if s == temp:
			return 1
		else:
			return 0


class Solution:
	import math

	def isStrong(self, N):
		temp = N
		l = []
		a = []
		while N:
			digit = N % 10
			N = N // 10
			a.append(digit)
		for i in a:
			f = math.factorial(i)
			l.append(f)
		if sum(l) == temp:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		h = N
		s = 0
		while N > 0:
			r = N % 10
			f = math.factorial(r)
			s += f
			N = N // 10
		if s == h:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		m = str(N)
		h = 0
		for i in m:
			k = int(i)
			fact = 1
			for j in range(1, k + 1):
				fact = fact * j
			h = h + fact
		if h == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		a = []
		n = [int(i) for i in str(N)]
		for i in n:
			a.append(math.factorial(i))
		if sum(a) == N:
			return 1
		return 0


import math

class Solution:

	def isStrong(self, n):
		x = n
		sum1 = 0
		while x > 0:
			r = x % 10
			sum1 += math.factorial(r)
			x = x // 10
		if sum1 == n:
			return 1
		else:
			return 0


import math

class Solution:

	def isStrong(self, N):
		temp = N
		summ = 0
		while N:
			rem = N % 10
			summ += math.factorial(rem)
			N = N // 10
		if summ == temp:
			return 1
		else:
			return 0


from math import factorial

class Solution:

	def isStrong(self, N):
		s = 0
		for i in str(N):
			s += factorial(int(i))
			if s > N:
				return 0
		return 1 if s == N else 0


class Solution:

	def isStrong(self, N):
		k = 0
		m = str(N)
		for i in m:
			h = 1
			while int(i) > 1:
				h = h * int(i)
				i = int(i) - 1
			k = k + h
		if k == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		temp = N
		s1 = 0
		while N > 0:
			k = N % 10
			fact = 1
			for i in range(1, k + 1):
				fact = fact * i
			s1 = s1 + fact
			N = N // 10
		if s1 == temp:
			return 1
		else:
			return 0


def fact(n):
	c = 1
	while n >= 1:
		c *= n
		n = n - 1
	return c

class Solution:

	def isStrong(self, N):
		n = N
		k = n
		p = 0
		while n > 0:
			r = n % 10
			p = p + fact(r)
			n = n // 10
		if p == k:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		a = N
		sum1 = 0
		while a != 0:
			r = a % 10
			x = math.factorial(r)
			sum1 = sum1 + x
			a = a // 10
		if sum1 == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		sum = 0
		a = N
		while a:
			r = a % 10
			s = math.factorial(r)
			sum = sum + s
			a = a // 10
		if sum == N:
			return '1'
		else:
			return '0'


class Solution:

	def factorial(self, N):
		fact = 1
		for i in range(N, 0, -1):
			fact = fact * i
		return fact

	def isStrong(self, N):
		res = 0
		num = N
		while N:
			r = N % 10
			res = res + self.factorial(r)
			N = N // 10
		if res == num:
			return 1
		else:
			return 0


import math

class Solution:

	def isStrong(self, N):
		s = 0
		dn = N
		while dn != 0:
			s += math.factorial(dn % 10)
			dn = dn // 10
		if s == N:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		n = N
		s = 0
		t = n
		while n:
			i = 1
			f = 1
			r = n % 10
			while i <= r:
				f = f * i
				i = i + 1
			s = s + f
			n = n // 10
		if s == t:
			return '1'
		else:
			return '0'


class Solution:

	def isStrong(self, N):
		sum = 0
		tmp = N
		while tmp > 0:
			dig = tmp % 10
			fac = 1
			for i in range(2, dig + 1):
				fac *= i
			sum += fac
			tmp //= 10
		if N == sum:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):

		def fact(n):
			if n in [0, 1]:
				return 1
			else:
				return n * fact(n - 1)
		N = str(N)
		sum = 0
		for i in N:
			sum += fact(int(i))
		if sum == int(N):
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		a = []
		x = list(str(N))
		for i in x:
			b = 1
			for j in range(1, int(i) + 1):
				b *= int(j)
			a.append(b)
		if sum(a) == N:
			return 1
		else:
			return 0


def fact(i):
	f = 1
	for j in range(1, i + 1):
		f *= j
	return f

class Solution:

	def isStrong(self, N):
		temp = N
		sum1 = 0
		while N > 0:
			d = N % 10
			sum1 += fact(d)
			N //= 10
		if temp == sum1:
			return 1
		else:
			return 0


def fact(n):
	f = 1
	for i in range(1, n + 1):
		f *= i
	return f

class Solution:

	def isStrong(self, N):
		temp = N
		pd = 0
		while N > 0:
			d = N % 10
			pd += fact(d)
			N //= 10
		if pd == temp:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):

		def fact(n):
			if n == 0 or n == 1:
				return 1
			return n * fact(n - 1)
		n = str(N)
		x = 0
		for i in n:
			x += fact(int(i))
		if x == N:
			return 1
		return 0


class Solution:

	def fact(self, N):
		if N == 1 or N == 0:
			return 1
		else:
			return N * self.fact(N - 1)

	def isStrong(self, n):
		a = str(n)
		l = []
		suma = 0
		for i in range(len(a)):
			l.append(self.fact(int(a[i])))
		for i in range(len(l)):
			suma += l[i]
		if n == suma:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		sf = 0
		f = 1
		temp = N
		while N > 0:
			r = N % 10
			for i in range(1, r + 1):
				f *= i
			sf += f
			f = 1
			N = N // 10
		if sf == temp:
			return 1
		else:
			return 0


class Solution:

	def factorial(self, n):
		if n <= 1:
			return 1
		return n * self.factorial(n - 1)

	def sumFact(self, n):
		sm = 0
		while n > 0:
			sm += self.factorial(n % 10)
			n //= 10
		return sm

	def isStrong(self, n):
		return int(self.sumFact(n) == n)


class Solution:

	def isStrong(self, N):
		import math
		arr = list(str(N))
		ans = []
		for i in range(0, len(arr)):
			ans.append(math.factorial(int(arr[i])))
		ans = sum(ans)
		if N == ans:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		N = str(N)
		sume = 0
		for i in N:
			sume += math.factorial(int(i))
		if int(N) != int(sume):
			return 0
		else:
			return 1


class Solution:

	def isStrong(self, N):
		l1 = []
		num = N
		sum = 0
		while N > 0:
			l1.append(N % 10)
			N = N // 10
		i = 0
		while i < len(l1):
			fact = 1
			while l1[i] > 0:
				fact *= l1[i]
				l1[i] -= 1
			i += 1
			sum += fact
		if sum == num:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		l = str(N)
		mul = 1
		lis = []
		for i in l:
			for j in range(1, int(i) + 1):
				mul *= j
			lis.append(mul)
			mul = 1
		if sum(lis) == N:
			return '1'
		else:
			return '0'


import math

class Solution:

	def isStrong(self, N):
		St = str(N)
		sum = 0
		for dig in St:
			n = int(dig)
			num = math.factorial(n)
			sum = sum + num
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		temp = N
		sum = 0
		while N > 0:
			i = N % 10
			fac = 1
			if i == 0 or i == 1:
				fac = 1
			else:
				for j in range(1, i + 1):
					fac = fac * j
			sum = fac + sum
			N = N // 10
		if sum == temp:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N: int) -> int:

		def factorial(num: int) -> int:
			result = 1
			for i in range(num, 1, -1):
				result *= i
			return result
		summation = 0
		n = N
		while N:
			summation += factorial(N % 10)
			N //= 10
		if summation == n:
			return 1
		else:
			return 0


import math as m

class Solution:

	def isStrong(self, n):
		count = 0
		for i in str(n):
			count += m.factorial(int(i))
		if n == count:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		r = N
		s = 0
		from math import factorial
		while N != 0:
			t = N % 10
			s += factorial(t)
			N = N // 10
		if r == s:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		count = 0
		a = N
		b = N
		f = 1
		s = 0
		while N > 0:
			N = N // 10
			count = count + 1
		while a > 0:
			p = a % 10
			a = a // 10
			f = 1
			for i in range(1, p + 1):
				f = f * i
			s = s + f
		if s == b:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		fact = [1] * 10
		curr = N
		for i in range(1, 10):
			fact[i] = fact[i - 1] * i
		SUM = 0
		while curr >= 1:
			SUM += fact[int(curr % 10)]
			curr = curr // 10
		return 1 if SUM == N else 0


class Solution:

	def isStrong(self, N):
		s = 0
		r = 0
		num = N
		while num > 0:
			r = num % 10
			s = s + self.fact(r)
			num = num // 10
		if s == N:
			return 1
		return 0

	def fact(self, n):
		if n == 1 or n == 0:
			return 1
		f = self.fact(n - 1) * n
		return f


from collections import defaultdict

class Solution:

	def isStrong(self, N):
		fact = defaultdict(lambda : 0)
		value = 1
		fact[0] = 1
		for i in range(1, 10):
			value = value * i
			fact[i] = value
		M = N
		total = 0
		while M != 0:
			total += fact[M % 10]
			M //= 10
		if total == N:
			return 1
		return 0


def fact(n):
	f = 1
	for i in range(1, n + 1):
		f = f * i
	return f

class Solution:

	def isStrong(self, N):
		res = 0
		t = N
		while N != 0:
			res += fact(N % 10)
			N = N // 10
		if res == t:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		a = 1
		b = 0
		l = [1]
		for x in range(1, 10):
			a = a * x
			l.append(a)
		for y in str(N):
			y = int(y)
			b = b + l[y]
		if b == N:
			return 1
		return 0


import math

class Solution:

	def isStrong(self, N):
		a = list(str(N))
		b = []
		for i in a:
			b.append(math.factorial(int(i)))
		if sum(b) == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		x = N
		s = 0

		def fact(n):
			if n == 1 or n == 0:
				return 1
			return n * fact(n - 1)
		while N:
			s += fact(N % 10)
			N = N // 10
		if x == s:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):

		def fac(n):
			if n == 0 or n == 1:
				return 1
			f = 1
			while n > 1:
				f *= n
				n -= 1
			return f
		s = 0
		for i in str(N):
			s = s + fac(int(i))
		if s == N:
			return 1
		return 0


import math

class Solution:

	def isStrong(self, N):
		result = 0
		x = N
		while x != 0:
			y = x % 10
			result = result + math.factorial(y)
			x = x // 10
		if result == N:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		sum = 0
		M = N
		while N > 0:
			rem = N % 10
			pro = 1
			for i in range(1, rem + 1):
				pro *= i
			sum += pro
			N = int(N / 10)
		if sum == M:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		x = str(N)
		arr = list(x)
		arr1 = []
		for i in arr:
			arr1.append(int(i))

		def fact(num):
			if num == 0:
				return 1
			else:
				return num * fact(num - 1)
		sum = 0
		for i in arr1:
			sum += fact(i)
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		sum = 0
		stri = str(N)
		for n in stri:
			sum += math.factorial(int(n))
		return 1 if N == sum else 0


class Solution:

	def isStrong(self, N):
		t = N
		sum = 0
		p = 1
		while N > 0:
			p = 1
			d = N % 10
			for i in range(1, d + 1):
				p = p * i
			sum = sum + p
			N = N // 10
		if sum == t:
			return 1
		return 0


import math as m

class Solution:

	def isStrong(self, N):
		sum = 0
		s = str(N)
		for i in s:
			sum += m.factorial(int(i))
		if sum == N:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, n):
		ans = n
		s = 0
		while n != 0:
			d = n % 10
			m = 1
			for i in range(1, d + 1):
				m = m * i
			s = s + m
			n = n // 10
		if ans == s:
			return 1
		return 0


class Solution:

	def isStrong(self, N):
		o = N
		sum = 0
		while N != 0:
			k = int(N % 10)
			j = math.factorial(k)
			sum += j
			N = N // 10
		if sum == o:
			return 1
		else:
			return 0


class Solution:

	def isStrong(self, N):
		temp = N
		sum1 = 0
		while N:
			i = 1
			f = 1
			r = N % 10
			while i <= r:
				f = f * i
				i = i + 1
			sum1 = sum1 + f
			N = N // 10
		if sum1 == temp:
			return 1
		else:
			return 0