Ctrl K

Numbers for Two Groups

Medium
An organizer hands out numbers to the members of two groups. The numbers are positive integers. - Group A needs count_a distinct numbers, none of them divisible by skip_a. - Group B needs count_b distinct numbers, none of them divisible by skip_b. - No number may be given to both groups. Return the smallest possible value of the largest number handed out.
Example 1
skip_a=3, skip_b=2, count_a=2, count_b=2 → 4

Group A gets 2 and 4 (not multiples of 3) and group B gets 1 and 3 (odd). The largest number is 4.

Example 2
skip_a=2, skip_b=2, count_a=3, count_b=1 → 7

Both groups can only use odd numbers, and four distinct ones are needed: 1, 3, 5 and 7. So 7 cannot be avoided.

Constraints
  • 2 ≤ skip_a, skip_b ≤ 10⁵
  • 1 ≤ count_a, count_b < 10⁹
  • 2 ≤ count_a + count_b ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsN-th Number Divisible by One of Three MediumShave Primes Into Order MediumGCD Times Sum HardK-th Postage With One Stamp Type HardPair GCDs by Sorted Position Hard
loading Python…
Input
skip_a=3, skip_b=2, count_a=2, count_b=2
Expected
4

Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.