Numbers II

4.3

18 votes
Algorithms, Binary Search, Greatest common divisor, Medium, Searching, gcd
Problem

Given two numbers a and b, you have to find the Nth number which is divisible by a or b.

Input :

First line consists of an integer T, denoting the number of test cases.
Second line contains three integers a, b and N .

Output :

For each test case, print the Nth number in a new line.

Constraints :

1t105

1a,b104

1N109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The numbers which are divisible by 2 or 3 are: 2,3,4,6,8,9,10,12,14,15 and the 10th number is 15.

Editor Image

?