Python Program for Common Divisors of Two Numbers
Given two integer numbers, the task is to find count of all common divisors of given numbers?
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 = 12b = 24n = 0 for i in range(1, min(a, b)+1): if a%i==b%i==0: n+=1 print(n) # |
Output:
6