Search⌘ K
AI Features

Nth Magical Number

Understand how to solve the nth magical number problem, where you find the positive integer divisible by given values a or b. Learn efficient math-based coding strategies, handle large constraints, and implement solutions to optimize time and space.

Statement

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 109+710^9+7 ...