Anyways, basically what I'm trying to do is find all pairs of factors of a number, and I've got a program that does pretty much that.
def getFactors(num):
factors = [[1, num]]
top = num**(1/2)
test = 2
while test <= top:
if num % test == 0:
factors.append([test, num // test])
test += 1
return factors
However it cannot take negative numbers as input, and I'm not sure this is the most efficient algorithm for finding all factors. I know I can increase efficiency if I don't check multiples of previously failed numbers(eg if n%2 != 0 then don't check any other even numbers), but I don't know how to implement something like this in a proficient way. Also I'm not sure if the method I'm using is the best because I did some googling, and read something about finding the prime factors, then finding the rest of the factors, but I'm not sure how that would work. Any help would be much appreciated, thanks!

New Topic/Question
Reply


MultiQuote









|