Try
[ProjectEuler] 프로젝트 오일러 Problem 12 본문
import time
start_time = time.time()
def count_factors(num):
loop=num**0.5
# for square number
if loop==int(loop):
count=1
else:
count=0
i=1
while i<loop:
if num%i==0:
count+=2
i+=1
return count
i=1;tri_num=0
while True:
tri_num = tri_num + i
count = count_factors(tri_num)
print("loop:",i,"tri_num",tri_num,"count",count)
if count > 500:
break
i+=1
print("answer:",tri_num)
print("calculation time:",time.time()-start_time)
#출처 https://www.opentutorials.org/module/2980/17520
출처
'Algorithm > ProjectEuler' 카테고리의 다른 글
[ProjectEuler] 프로젝트 오일러 Problem 14 (0) | 2019.07.03 |
---|---|
[ProjectEuler] 프로젝트 오일러 Problem 13 (0) | 2019.07.03 |
[ProjectEuler] 프로젝트 오일러 Problem 11 (0) | 2019.06.29 |
[ProjectEuler] 프로젝트 오일러 Problem 10 (0) | 2019.06.28 |
[ProjectEuler] 프로젝트 오일러 Problem 9 (0) | 2019.06.28 |
Comments