Search⌘ K
AI Features

Nth Magical Number

Explore how to calculate the nth magical number defined as a positive integer divisible by either of two given integers. Learn to approach this math and geometry challenge efficiently and implement a solution suitable for large inputs, helping you master relevant coding interview problems.

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