Skip to main content

Practice · 1 of 5

GCD and LCM

CHALLENGE
Difficulty: beginner+25 XP

**Description:** For each pair (a, b), print gcd(a, b) and lcm(a, b) on one line, space-separated. **Input:** Line 1: t (1 <= t <= 10^5). Each of the next t lines: a b (1 <= a, b <= 10^12; guaranteed lcm(a, b) <= 10^18). **Output:** t lines: g l. **Example:** 12 18 -> 6 36.

Back to lesson: Practice: Number Theory Problem Set