📜  快速查找数字因数的方法python代码示例

📅  最后修改于: 2022-03-11 14:47:08.298000             🧑  作者: Mango

代码示例1
def factors(x):
  listOfFactors = []
  for i in range(1, int(x ** 0.5)):   
    # Use a loop from 1 to the square root of x for more speed.
    if x % i == 0:
      listOfFactors.append(x)
      listOfFactors.append(i)
    # May repeat some numbers. Further code would be needed to fix that.
    print(i)