UJ01 - Save the Scofield !!

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

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

hide comments
2015-05-17 08:56:49 rkp
unclear problem statement
2015-05-17 06:16:11 UJtriumphsâ„¢
Long long would do :-)
2015-05-17 03:26:01 :.Mohib.:
Which data type I use in c++??

Last edit: 2015-05-17 03:26:39
2015-05-14 05:42:37 UJtriumphsâ„¢
@anu_goel28 : try some optimization not an straight question :)
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
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...:(
2015-05-10 10:07:55 :.Mohib.:
Can u plzz check my submission I think my solution is correct but WA.... :(
2015-05-09 14:35:37 UJtriumphsâ„¢
Updated!!
2015-05-09 11:24:24 Pranjal Shankhdhar
constraints?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.