Search⌘ K
AI Features

Nth Magical Number

Explore how to calculate the nth magical number, defined as a positive integer divisible by given numbers a or b, using modular arithmetic to handle large results. Understand the problem constraints and develop efficient solutions through hands-on coding practice to sharpen your algorithmic skills.

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 ...