Answer the question
In order to leave comments, you need to log in
Finding the divisors of a number?
Hello! There is a factorization algorithm (I heard that you can find divisors of a number through it):
def Factor(n):
Ans = []
d = 2
while d * d <= n:
if n % d == 0:
Ans.append(d)
n //= d
else:
d += 1
if n > 1:
Ans.append(n)
return Ans
Answer the question
In order to leave comments, you need to log in
Hello! There are ideas for such an algorithm, you can go to the root of the number and check whether the number is divisible, if it is divisible, then immediately add 2 (because if 24 is a multiple of 4, then it is a multiple of 24/4), you just need to check if the divisor * divisor is not a number.
Here is the
while implementation
def fact(a):
i = 1
o = 0
while i * i <= a:
if a % i == 0 and i * i != a: o += 2
elif a % i == 0 and i * i == a: o += 1
i += 1
return o
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question