Python Practice Lab
mediumUnit 5 · Loops: for, while, break, continue

P15. GCD and LCM

Loops: for, while, break, continue

Read two positive integers. Find their GCD using Euclid's method with a while loop: repeatedly replace (a, b) with (b, a % b) until b becomes 0; then a is the GCD. The LCM is a × b ÷ GCD. Two numbers are co-prime if their GCD is 1.

Input Format

  • Line 1: a
  • Line 2: b

Output Format

  • Line 1: GCD: <g>
  • Line 2: LCM: <l>
  • Line 3: Co-prime: Yes or Co-prime: No

Constraints

  • 1 ≤ a, b ≤ 10^6
  • Do not use math.gcd()

Sample Test Cases

Sample 1
Input
12
18
Output
GCD: 6
LCM: 36
Co-prime: No
Sample 2
Input
17
5
Output
GCD: 1
LCM: 85
Co-prime: Yes

Submitting checks 2 sample cases and 4 hidden test cases.

Hints

Saved
Custom 1

This is your own input, so Run will show what your program prints but can't say whether it's correct.