Please enter your email address or userHandle.
Given two positive integers A and B, find GCD of A and B.
Input: A = 3, B = 6
Explanation: GCD of 3 and 6 is 3
Input: A = 1, B = 1
Explanation: GCD of 1 and 1 is 1
You don't need to read input or print anything. Complete the function gcd() which takes two positive integers as input parameters and returns an integer.
Expected Time Complexity: O(log(min(A, B)))
Expected Auxiliary Space: O(1)
1 ≤ A, B ≤ 109
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?
Login to access your submissions.
Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.