Hiring Challenge | Kth smallest number divisible by A or B or C
1017

Given a, b, c and k. Find the kth smallest positive number which is divisible by a or b or c.

Example 1:

Input: a = 1, b = 2, c = 3, k = 4
Output: 4
Explanation:
Sequence is 1, 2, 3, 4, 5...

Example 2:

Input: a = 2, b = 4, c = 5, k = 5
Output: 8
Explanation:
Sequence is 2, 4, 5, 6, 8, 10...

Example 3:

Input: a = 2, b = 3, c = 5, k = 10
Output: 14
Explanation:
Sequence is 2, 3, 4, 5, 6, 8, 9, 10, 12, 14, 15, 16...

Example 4:

Input: a = 3, b = 5, c = 7, k = 10
Output: 18

Constraints:

  • 1<= T <=10^5
  • 1<= a, b, c <=10^4
  • 1<= k <=10^12

Time limit: 2 sec

Comments (4)