Binary search for the smallest x where count(x) ≥ n. Range is [1, 2 × 10^9] because the nth ugly number cannot exceed n × max(a, b, c) and max is at most 10^9.
For each mid, compute count(mid) using inclusion-exclusion. If count < n, search right. Otherwise search left.
Compute all LCM values once before binary search. Use lcm(a, b) = (a × b) / gcd(a, b) but watch for overflow. Use long long or handle mod carefully.