Ad

Changing "if n % i == 0" on line 6 to "if not(n % i)" made the time drop from 4126ms to 3810ms (as the longest time).

Code
Diff
  • from math import sqrt, floor
    
    def divisors(n):
        fact = [];
        for i in range(1, int(floor(sqrt(n))) + 1):
            if not(n % i):
                fact.append(i)
                if n / i != i:
                    fact.append(n / i)
        fact.sort()
        return fact
    • from math import sqrt, floor
    • def divisors(n):
    • fact = [];
    • for i in range(1, int(floor(sqrt(n))) + 1):
    • if n % i == 0:
    • if not(n % i):
    • fact.append(i)
    • if n / i != i:
    • fact.append(n / i)
    • fact.sort()
    • return fact