Back

Try the following code, which will actually returns all the factors, efficiently and very quickly of a number "n".

from functools import reducedef factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

from functools import reduce

def factors(n):

return set(reduce(list.__add__,

([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

30.9k questions

32.9k answers

500 comments

665 users