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
filter_none

edit
close

play_arrow

link
brightness_4
code

# 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

chevron_right


Output:

6

Please refer complete article on Common Divisors of Two Numbers for more details!



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.