Every number factors into primes. For gcd, you take the minimum power of each prime. For lcm, you take the maximum power.
Example: 12 = 2² × 3, 18 = 2 × 3². gcd = 2¹ × 3¹ = 6. lcm = 2² × 3² = 36. Product: 6 × 36 = 216 = 12 × 18.
The formula gcd × lcm = a × b holds because you count each prime power exactly twice across both sides.