Ad
  • Default User Avatar

    Think further about this line in get_divisor_sum(x):

    for i in range (2, int(x/2) + 1):

    You can do some further optimization on the upper end of the range as you don't need to count up to half of x if you use a common trick when calculating divisors. If x % i == 0, i is a divisor, but so is x // i, which you basically get for free here.

    That being said, for very large numbers this solution might still time out. A more efficient way is to calculate the sum of the divisors through the prime factors and their exponents - both of which can be calculated very efficiently.