1.求一个数的所有约数

def getNum(num):
    dict={}
   #因子数都是以sqrt(num)为界对称的,找出<=sqrt(num)这边的,用num/i就同时获得了另一半的因子数,从1开始遍历即可。
    for i in range(1,int(num**0.5)+1):
        if num%i==0:
            dict[i]=1
            dict[num//i]=1
    print(dict.keys())

 2.求两个数的最大公约数

def getMaxCommonDivisor(a,b):
if a%b==0:
return b
while a%b!=0:
a,b=b,a%b
return b

 3.最小公倍数

记住这个公式: x*y=最小公倍数*最大公约数

相关文章:

  • 2021-08-26
  • 2022-12-23
  • 2021-12-02
  • 2021-04-09
  • 2021-08-05
  • 2021-11-07
猜你喜欢
  • 2022-02-10
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
相关资源
相似解决方案