UJ01 - Save the Scofield !!

no tags 

Scofield is excellent at math tables, so T-BAG decided to make things a bit more interesting. He gives two numbers A and B and merges the tables of A and B in sorted order (ascending order), removing the duplicates and thus creates Saratable of A and B (sounds interesting) and asks Scofield the Nth number in the Saratable.

Given A, B and N, Help Scofield in finding the Nth number in the Saratable, else he will be put into Camp 22 (North Korea) by the security officer T-BAG Tongue out.

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 Saratable.

Constraints

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

Input:
4
3 5 2
3 5 3
2 3 4
2 3 6

Output:
5
6
6
9

hide comments
rkp: 2015-05-17 08:56:49

unclear problem statement

UJtriumphsâ„¢: 2015-05-17 06:16:11

Long long would do :-)

:.Mohib.:: 2015-05-17 03:26:01

Which data type I use in c++??

Last edit: 2015-05-17 03:26:39
UJtriumphsâ„¢: 2015-05-14 05:42:37

@anu_goel28 : try some optimization not an straight question :)

anu_goel28: 2015-05-12 13:30:07

i'm new to the site.....
I tried coding in python... n I always get time limit exceeded
I checked on ideone it takes 0.03 time
than what's the problem with the code

sumanth96: 2015-05-11 21:37:44

i m getting a run time error NZEC while trying to code it in python 2.7...could u check and tell where its going wrong...:(

:.Mohib.:: 2015-05-10 10:07:55

Can u plzz check my submission I think my solution is correct but WA.... :(

UJtriumphsâ„¢: 2015-05-09 14:35:37

Updated!!

Pranjal Shankhdhar: 2015-05-09 11:24:24

constraints?


Added by:Ujjawal Dixit
Date:2015-05-09
Time limit:1s-2.841s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All