-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPE012.py
More file actions
122 lines (99 loc) · 2.56 KB
/
PE012.py
File metadata and controls
122 lines (99 loc) · 2.56 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env python
# -*coding:UTF-8-*-
"""
@Project hello_world
@File PE012.py
@Author Haosen Luo
@Date 2025/2/5 20:24
"""
import time
def timer(main_function):
def inner(*args, **kwargs):
begin = time.time()
main_function(*args, **kwargs)
print(f"Running Time: {time.time() - begin} s")
return inner
def have_divisible_number_list(n):
if n > 1:
return [i for i in range(1, n + 1) if n % i == 0]
else:
return [1]
# @timer
# def main(limit):
# triangle_num = 1
# num = 2
# while True:
# triangle_num += num
# num += 1
# divisors = 1
# factors = []
#
# # 找出所有质因数
# N = triangle_num
# while True:
# if N == 1:
# break
# for i in range(2, N + 1):
# if N % i == 0:
# N = N // i
# factors.append(i)
# break
#
# # 约数个数 = (a1 + 1)*(a2 + 1)*(a3 + 1)...(ak + 1)
# item = 1
# tmp = 1
# for a in factors:
# if a == tmp:
# item += 1
# if a > tmp:
# item += 1
# divisors *= item
# item = 1
# tmp = a
# if divisors >= limit:
# print(triangle_num)
# break
def main():
"""
个人改编
:return:
"""
# 自然数增加量
num = 2
triangle_num = 1
while True:
# 每一次循环,自然数的增加量都比前一次多1
triangle_num += num
num += 1
total_count = 1
# 因数存放点
factors = []
# 重新赋值,将三角形数提供给N进行循环计算,辗转相除
N = triangle_num
while N != 1:
for i in range(2, N + 1):
if N % i == 0:
# 整除
N = N // i
# 将约数 放到因数存放点里
factors.append(i)
# 重新思考 N
break
# 约数个数 = (a1 + 1)*(a2 + 1)*(a3 + 1)...(ak + 1)
count = 1
temp_factor = 1
for p in factors:
if p == temp_factor:
count += 1
if p > temp_factor:
count += 1
total_count *= count
count = 1
temp_factor = p
if total_count >= 500:
print(triangle_num)
break
if __name__ == '__main__':
# main(5)
# main(500)
main()