Distribute the Numbers
Practice
2.6 (9 votes)
Binary search
C++
Algorithms
Problem
87% Success 1514 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Bunty and Bublee like to play with numbers. You have to distribute \(n_{1}\) and \(n_{2}\) integers between Bunty and Bublee respectively. You cannot give the same numbers to both Bunty and Bublee. Also, Bunty doesn't like the numbers that are divisible by prime number \(x\) and Bublee doesn't like the numbers that are divisible by a prime number \(y\). So you cannot distribute the numbers to them that they do not like. Find the minimum value of \(n\), that you can use to distribute from set \(1, 2, 3, \dots, n\). You can choose not to distribute some numbers at all.

Input format

  • The first line contains an integer \(T\) - denoting the number of test cases.
  • The first line of each test case contains \(4\) space-separated integers \(n_{1}, n_{2}, x, y\).

Output format

Print a single integer - the minimum number \(n\), that you can use to distribute numbers from the set \(1, 2, 3, \dots, n\).

Constraints

\(1 \le T \le 100\)
\(1 \leq n_{1} , n_{2} < 10^9\)
\(n_{1} + n_{2} \leq 10^9\)
\(2 \leq x < y \leq 10^5\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
11 votes
Tags:
AlgorithmsBinary SearchFenwick TreeHardHiringSearching
Points:50
4 votes
Tags:
AlgorithmsBinary Search
Points:30
246 votes
Tags:
ReadyMathematicsSortingApprovedEasy-Medium