I am looking for the fastest, minimum execution time approach to get all the numbers below a "n" number given by the user that are multi-perfect. A number "X" is said to be multi-perfect if the sum of divisors is equal to "X" or "X" multiplied by a int between 2 to 11. Something like this:
-
sum_div = X --> Multi-perfect number
-
sum_div = X * k (int between 2 to 11) --> Multi-perfect number
The algorithm that i have currently is this:
def multiperfect(n):
list=[1]
for X in range(2, n + 1):
div = []
for i in range(1, X):
if X % i == 0:
div.append(i)
sum_div = sum(div)
if sum_div == X:
list.append(X)
else:
for k in range(2, 11):
if (k * X == sum_div):
list.append(X)
return list
As you can see this algorithm has 2 iterative structures that make it very very slow O(n^2), i am looking to improve that, any suggestion or advice?
source https://stackoverflow.com/questions/76087605/python-fastest-minimum-execution-time-approach
Comments
Post a Comment