first and second. Write out, in increasing order, every positive integer divisible by at least one of them (a number divisible by both appears once).
Return the number at position rank in that list (counting from one). The answer can be huge, so return it modulo 10⁹ + 7.
Walking through the numbers one at a time is too slow: rank can be as large as a billion.rank=5, first=4, second=6 → 16
The qualifying numbers in increasing order are 4, 6, 8, 12, 16, … The fifth is 16. The number 12 divides by both but is counted once.
rank=3, first=5, second=5 → 15
Both divisors are equal, so these are just the multiples of five: 5, 10, 15.
rank=1000000000, first=2, second=2 → 999999993
rank=5, first=4, second=6
16
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.