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 multiplication 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
lumaks_69: 2022-09-28 10:02:37

fortnite or pubg

sai_chavali: 2019-03-29 07:00:29

Don't try this problem in python. It's giving TLE

Jacob Plachta: 2015-12-07 00:04:55

The "table of A" is the list of all multiples of A (A, 2A, 3A, ...).

biswas: 2015-08-28 14:28:01

@SRC: You don't need any array...just simple mathematics.

Shivaraj Lakka: 2015-07-17 09:29:41

problem is not clear!!!
finally AC.. :-)

Last edit: 2015-07-24 12:38:05
kp: 2015-07-02 06:31:56

pen and paper rocks ! AC in one GO :P

Vipul Srivastava: 2015-06-27 15:25:10

Very nice question!!

Aman Agarwal: 2015-06-23 19:24:13

nice question bhai :)

black MaMbA: 2015-06-18 09:30:46

@HELLGEEK,would you please check submission id 14479575,is it wrong

SRC: 2015-06-17 00:48:05

What should the length of the array? Please help !


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