Competitive Programming in Python |
In this article, we are going to check for the co-prime numbers using Python
Two numbers are said to be co-prime if they do not have any common divisor other than one
If you are looking for a Python Tutorial Series then it's here
def coprime(x,y):
hcf = 1
for i in range(1, x+1):
if x%i==0 and y%i==0:
hcf = i
return hcf == 1
def main():
num1 = int(input('Enter first number: '))
num2 = int(input('Enter second number: '))
if coprime(num1, num2):
print('%d and %d are CO-PRIME Number' %(num1, num2))
else:
print('%d and %d are NOT CO-PRIME Number' %(num1, num2))
main()
The output of the code is:
Enter first number: 7
Enter second number: 11
7 and 11 are CO-PRIME
Enter first number: 5
Enter second number: 10
5 and 10 are NOT CO-PRIME Number
Comments
Post a Comment