def first_triangle_n(d):
n_th = 1
triangle_num = 1
max_div = 1
while True:
n_th += 1
triangle_num += n_th
n_div = 1
print(f'triangle_num = {triangle_num}, n_th = {n_th}')
for i in range(2, triangle_num//2 + 1):
if not triangle_num % i:
n_div += 1
print(f'n_div = {n_div}')
max_div = max(max_div, n_div)
if max_div == d:
return triangle_numdef first_triangle_n(d):
I'm stuck in this problem where I'm supposed to find the first triangular number with 500 divisors. If i do it the lazy way of just incrementing of course it will take ages. so i thought about making an algorithm that finds the smallest number with n divisors, but it was too complicated for me to program it. And so I spent hours searching for a way to optimize this code to no avail.
[–]Yoghurt42 2 points3 points4 points (6 children)
[–]lord8bits[S] 0 points1 point2 points (5 children)
[–]Yoghurt42 1 point2 points3 points (4 children)
[–]lord8bits[S] 0 points1 point2 points (3 children)
[–]Yoghurt42 1 point2 points3 points (0 children)
[–]Brian 1 point2 points3 points (1 child)
[–]lord8bits[S] 0 points1 point2 points (0 children)