GCD and LCM
Given two positive integers a and b, return [g, l] where and .
Use the identity .
Requirements
- Implement Euclid's algorithm yourself: .
Constraints
Examples
EXAMPLE WALKTHROUGHcommon factors
A guided view of the published example, not a trace of your code.
INPUT
[12,18]TASKgcd_and_lcm()
EXPECTED OUTPUT
[6,36]Start with the input values shown in this example.
Example 1 of 3
Input: a = 12, b = 18
Output: [6,36]
Explanation: common factors
Input: a = 7, b = 13
Output: [1,91]
Explanation: coprime
Input: a = 5, b = 5
Output: [5,5]
Explanation: equal
Hint 1
Repeatedly replace (a, b) with (b, a % b) until b is 0.
Hint 2
Divide before multiplying to keep the LCM computation small: a // g * b.