📜  python 获取数字的因数 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:15.632000             🧑  作者: 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)