📜  两个数的公约数的Python程序

📅  最后修改于: 2022-05-13 01:56:56.778000             🧑  作者: Mango

两个数的公约数的Python程序

给定两个整数,任务是找出给定数字的所有公约数的个数?

Input : a = 12, b = 24
Output: 6
// all common divisors are 1, 2, 3, 
// 4, 6 and 12

Input : a = 3, b = 17
Output: 1
// all common divisors are 1

Input : a = 20, b = 36
Output: 3
// all common divisors are 1, 2, 4
# Python Program to find 
# Common Divisors of Two Numbers
  
a = 12
b = 24
n = 0
  
for i in range(1, min(a, b)+1):
    if a%i==b%i==0:
        n+=1
      
print(n)
  
# Code contributed by Mohit Gupta_OMG

输出:

6

更多详细信息,请参阅关于两个数的公约数的完整文章!