[Solved] The code isn’t efficient


There are a few tricks you can use to speed this up.

The nth triangle number is n*(n+1)/2.

For all integers n, n and n+1 are co-prime. This means that the number of divisors of n*(n+1) is the number of divisors n multiplied by the number of divisors of n+1.

For an even number k, the number of divisors of k/2 is half the number of divisors of k.

So, to compute the number of divisors of the nth triangle number, count the divisors of n+1, multiply with the number of divisors of n that you have from the previous step, and divide by two.

solved The code isn’t efficient