-
Notifications
You must be signed in to change notification settings - Fork 0
/
34. Digit factorials.py
55 lines (49 loc) Β· 1.01 KB
/
34. Digit factorials.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
45
46
47
48
49
50
51
52
53
54
55
def factorial(n):
product = 1
for i in range(1, n+1):
product *= i
return product
factorialsDictionary = {}
for i in range(10):
factorialsDictionary[i] = factorial(i)
#print(factorialsDictionary)
#def getDigits(n):
# digits = []
# while n != 0:
# digits.append(n % 10)
# n //= 10
# return(digits[::-1])
#
#print(getDigits(1234))
#
#def doesSatisfy(number):
## numberString = str(number)
# theSum = 0
## for i in numberString:
# for i in getDigits(number):
## theSum += factorial(int(i))
## theSum += factorialsDictionary[int(i)]
# theSum += factorialsDictionary[i]
# if theSum > number:
# return False
# return theSum == number
#def getDigits(n):
# digits = []
# while n != 0:
# digits.append(n % 10)
# n //= 10
# return(digits[::-1])
#
#print(getDigits(1234))
def doesSatisfy(number):
temp = number
theSum = 0
while temp != 0:
theSum += factorialsDictionary[temp % 10]
temp //= 10
if theSum > number:
return False
return theSum == number
for i in range(10, 10**7):
if doesSatisfy(i):
print(i)