Kth Multiple of Either
List the positive whole numbers that are divisible by a or by b (or both), from small to large. Return the k-th one, counting from 1.
Example 1
k 4
a 2
b 3
returns 6
The list starts 2, 3, 4, 6, 8, 9, ... and its fourth number is 6.
Constraints
1 <= k <= 10**92 <= a, b <= 40000
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.