Back to course home
0% completed
Vote For New Content
Solution: Nth Magical Number
Problem Statement
Given the three integers n, a, and b, return the n<sup>th</sup> magical number modulo 10^9 + 7 as it can be very large.
A positive integer is called magical if it is divisible by either a or b.
Examples
- 
Example 1: - Input: n = 3, a = 2, b = 3
- Expected Output: 4
- Justification: The first three magical numbers divisible by 2 or 3 are 2, 3, and 4. The third magical number is 4.
 
- Input: 
- 
Example 2: - Input: n = 5, a = 3, b = 4
- Expected Output: 9
 
- Input: 
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page