Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether Two Numbers Are Coprime

Basic Acceptance 83.45% Points 10.00

You are given two positive integers a and b. Your task is to determine whether they are coprime. Two numbers are coprime if their greatest common divisor (GCD) is exactly 1.

Examples
Example 1

Input: a = 8, b = 15
Output: Yes
Explanation: The GCD of 8 and 15 is 1. Therefore, the numbers are coprime.

Example 2

Input: a = 12, b = 18
Output: No
Explanation: The GCD of 12 and 18 is 6, which is greater than 1. Therefore, the numbers are not coprime.

Example 3

Input: a = 1, b = 100
Output: Yes
Explanation: The GCD of 1 and 100 is 1. Therefore, the numbers are coprime.

Constraints
  • 1 <= a, b <= 109
Companies
Samsung Infosys
Topics
Data Structures Basics Comparisons
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions