Python Program to Check Whether Two Numbers are Co-Prime or Not

This python program checks whether two given numbers are co-prime numbers are not.

Two numbers are said to be co-prime numbers if they do not have a common factor other than 1.

Two numbers whose Highest Common Factor (HCF) or Greatest Common Divisor (GCD) is 1 are co-prime numbers.

Co-prime Number Example: 3 and 7 are co-prime, 7 and 10 are co-prime etc.

Note: Co-prime numbers do not require to be prime numbers.

Python Source Code: Check Co-Prime Numbers


# Python program to check Co-Prime Number

# Function to check Co-prime
def are_coprime(a,b):
    
    hcf = 1

    for i in range(1, a+1):
        if a%i==0 and b%i==0:
            hcf = i

    return hcf == 1

# Reading two numbers
first = int(input('Enter first number: '))
second = int(input('Enter second number: '))

if are_coprime(first, second):
    print('%d and %d are CO-PRIME' %(first, second))
else:
    print('%d and %d are NOT CO-PRIME' %(first, second))

Co-Prime Check Python Output

Enter first number: 5
Enter second number: 17
5 and 17 are CO-PRIME