Given three integers n, a, and b, return the nth magical number.
A magical number is defined as a positive integer that is divisible by either a or b.
As the result may be very large, return it modulo
Constraints:
n
a, b
To find the nth number divisible by either a or b, we observe that magical numbers form a sorted sequence of all multiples of a and b. Instead of generating this sequence explicitly, we can efficiently count how many magical numbers are
Count of numbers divisible by a:
Given three integers n, a, and b, return the nth magical number.
A magical number is defined as a positive integer that is divisible by either a or b.
As the result may be very large, return it modulo
Constraints:
n
a, b
To find the nth number divisible by either a or b, we observe that magical numbers form a sorted sequence of all multiples of a and b. Instead of generating this sequence explicitly, we can efficiently count how many magical numbers are
Count of numbers divisible by a: