VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-two-numbers-co-prime-not/

⇱ Check if two numbers are co-prime or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if two numbers are co-prime or not

Last Updated : 14 Oct, 2024

Two numbers A and B are said to be Co-Prime or mutually prime if the Greatest Common Divisor of them is 1. You have been given two numbers A and B, find if they are Co-prime or not.
Examples :

Input : 2 3
Output : Co-Prime

Input : 4 8
Output : Not Co-Prime

The idea is simple, we find GCD of two numbers and if GCD is 1, we return true, else false.


Output
Co-Prime
Not Co-Prime

Time Complexity: O(log(max(a,b)))

Auxiliary Space: O(1)


Comment
Article Tags: