The Number of Pairs
HardRating 2100CodeforcesNumber Theory
Approach hintTry it first, then revealHide
Let g = gcd(a, b); then g divides x, and for each divisor the equation fixes the ratio lcm / gcd. A value k has 2^w(k) ordered coprime factorisations, where w(k) counts its distinct primes; sieve w once.