forked from H4ckSpace/HacktoberFest24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrong_Number.py
44 lines (36 loc) · 998 Bytes
/
Strong_Number.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'''
Question:
Given a number n, determine whether it qualifies as a Strong Number or not.
A Strong Number is defined as a number where the sum of the factorials of its digits equals the original number itself.
Factorials is the product of all positive integers up to a given number x.
You need to return 1 if the given number is Strong number, otherwise 0.
Note:- This is a functional problem. You do not need to take any input. You just need to complete the function and just return 1 or 0 accordingly.
Input
First line contains an Integer n.
Output
Print 1 if n is a Strong Number, otherwise print 0.
Example
Input
145
Output
1
Explanation
1! + 4! + 5! = 145 So, 145 is a Strong
Number and therefore the Output 1.
Solution:
'''
def is_strong_number(n):
num=n
fact=1
sum=0
while num>0:
x=num%10
fact=1
for i in range(1,x+1):
fact=fact*i
sum+=fact
num=num//10
if sum==n:
return 1
else:
return 0