Finding all divisors of a number optimization
问题 I have written the following function which finds all divisors of a given natural number and returns them as a list: def FindAllDivisors(x): divList = [] y = 1 while y <= math.sqrt(x): if x % y == 0: divList.append(y) divList.append(int(x / y)) y += 1 return divList It works really well with the exception that it's really slow when the input is say an 18-digit number. Do you have any suggestions for how I can speed it up? Update : I have the following method to check for primality based on