Supertables
Practice
3.7 (6 votes)
Approved
Binary search
Math
Medium
Open
Sorting
Problem
20% Success 4323 Attempts 30 Points 4s Time Limit 256MB Memory 1024 KB Max Code

Little Timmy is exceptionally good at math tables, so his maths teacher decided to make things a bit more interesting. His teacher takes two numbers A and B and merges the tables of A and B in sorted order (ascending order), removing the duplicates and thus creates supertable of A and B and asks Little Timmy the Nth number in the supertable.
Given A, B and N, calculate the Nth number in the supertable of A and B.

Input
First line contains number of test cases T . Each test case contains three integers A , B and N .

Output
For each test case print the Nth number of the supertable.

Constraints:
1<=T<=300000
1<=A, B<=1000
1<=N<=1000000000

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:30
8 votes
Tags:
Binary SearchSortingAlgorithms
Points:30
6 votes
Tags:
Greedy algorithmBinary SearchSortingAlgorithms
Points:30
10 votes
Tags:
AlgorithmsBinary SearchGreedy AlgorithmsMediumOpenSorting