Search
⌘K

Leetcode 878. Nth Magical Number

Find the nth positive integer divisible by a or b (i.e., multiples of a or b). Because n can be up to 1e9, use inclusion–exclusion with lcm to count how many numbers ≤ x and binary search for the smallest x with count ≥ n; return x mod 1e9+7.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.