46 lines
1012 B
Python

from functools import reduce
from tools import number_theory
g_prime = list(number_theory.make_prime(1000000))
def find_a_factor(num, prime):
while prime:
p = prime.pop(0)
if not (num % p):
return p, prime
return 0, []
def factor_num(num):
global g_prime
for i, value in enumerate(g_prime):
if value ** 2 > num:
break
prime = g_prime[:i]
factors = {}
while True:
factor, prime = find_a_factor(num, prime)
if factor:
count = 0
while not (num % factor):
num //= factor
count += 1
factors[factor] = count
else:
if 1 != num:
factors[num] = 1
return factors
def tri_num():
x = 2
while True:
yield x * (x + 1) // 2
x += 1
for x in tri_num():
factor_count = reduce(lambda x, y: x * (y + 1), factor_num(x).values(), 1)
if factor_count > 500:
print(x)
break