-
Notifications
You must be signed in to change notification settings - Fork 0
/
p04_fac.py
43 lines (36 loc) · 866 Bytes
/
p04_fac.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
"""
coding=utf-8
Author Wu Wentong
@Time : 2021/2/6 3:22 下午
@Site :
@File : p04_fac.py
@Software: PyCharm
"""
class Factorial:
def __init__(self, k):
self.n = k
def fac(self):
result = [1]
while self.n > 1:
self.mul(result, self.n)
self.n -= 1
return self.to_str(result)
@staticmethod
def to_str(result):
s = ""
for e in result:
s = str(e) + s
return s
@staticmethod
def mul(result, k):
add = 0
for i in range(len(result)):
r = k * result[i] + add
result[i] = r % 10
add = r // 10
while add > 0:
result.append(add % 10)
add //= 10
if __name__ == "__main__":
for n in range(1, 100 + 1):
print('%d! = %s' % (n, Factorial(n).fac()))