Python Program to find Common Divisors

You are Here:

What are Common Divisors?

A number that divides two or more numbers without remainder.

Tips: It is recommended to use our online common divisor calculator for better understanding.

Examples

The following table provides few examples of common divisors of the given numbers.

NumbersCommon Divisors
4, 61, 2
12, 241, 2, 3, 4, 6, 12
15, 25, 501, 5

Common Divisors of Two Numbers

In the following example, we will find the common divisors of numbers 12 and 24.

Example

Python Compiler
num1 = 12; num2 = 24; min = (num1 < num2) and num1 or num2; print("Common Divisors of %d and %d: " % (num1 , num2)) for i in range(1, min+1): if((num1 % i == 0) and (num2 % i == 0)): print(i, end=" ")

Output

Common Divisors of 12 and 24: 1 2 3 4 6 12

Common Divisors of any Two Given Numbers

In the following example, we will find the common divisors of any two given numbers.

Example

Python Compiler
num1 = int(input("Enter (int) num1 = ")); num2 = int(input("Enter (int) num2 = ")); min = (num1 < num2) and num1 or num2; print("\nCommon Divisors of %d and %d: " % (num1 , num2)) for i in range(1, min+1): if((num1 % i == 0) and (num2 % i == 0)): print(i, end=" ")

Output

Enter (int) num1 = 54 Enter (int) num2 = 14 Common Divisors of 54 and 14: 1 2

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on Python with examples for quick and easy learning.

We are working to cover every Single Concept in Python.