Created
September 9, 2017 09:34
-
-
Save sachinsmc/e6b28c6c5e53249888a4e6c05b3d5a09 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
public class TestClass { | |
public static void main(String[] args) throws IOException { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
PrintWriter wr = new PrintWriter(System.out); | |
int T = Integer.parseInt(br.readLine().trim()); | |
for(int t_i=0; t_i<T; t_i++) | |
{ | |
String[] in=br.readLine().split(" "); | |
long a = Long.parseLong(in[0]); | |
long b = Long.parseLong(in[1]); | |
long n = Long.parseLong(in[2]); | |
long out_ = solve(a, b, n); | |
System.out.println(out_); | |
System.out.println(""); | |
} | |
wr.close(); | |
br.close(); | |
} | |
static long solve(long a, long b, long n){ | |
long temp=0; | |
if(a>b){ | |
temp=b; | |
} | |
else{ | |
temp=a; | |
} | |
for(int i=1;i<n;){ | |
temp++; | |
if((temp%a==0) || (temp%b==0)){ | |
i++; | |
} | |
} | |
return temp; | |
} | |
} | |
Numbers II | |
Given two numbers | |
a | |
a and | |
b | |
b, you have to find the | |
N | |
t | |
h | |
Nth number which is divisible by | |
a | |
a or | |
b | |
b. | |
Input : | |
First line consists of an integer | |
T | |
T, denoting the number of test cases. | |
Second line contains three integers | |
a | |
a, | |
b | |
b and | |
N | |
N . | |
Output : | |
For each test case, print the | |
N | |
t | |
h | |
Nth number in a new line. | |
Constraints : | |
1 | |
≤ | |
t | |
≤ | |
10 | |
5 | |
1≤t≤105 | |
1 | |
≤ | |
a | |
, | |
b | |
≤ | |
10 | |
4 | |
1≤a,b≤104 | |
1 | |
≤ | |
N | |
≤ | |
10 | |
9 | |
1≤N≤109 | |
Sample Input | |
1 | |
2 3 10 | |
Sample Output | |
15 | |
Explanation | |
The numbers which are divisible by | |
2 | |
2 or | |
3 | |
3 are: | |
2 | |
, | |
3 | |
, | |
4 | |
, | |
6 | |
, | |
8 | |
, | |
9 | |
, | |
10 | |
, | |
12 | |
, | |
14 | |
, | |
15 | |
2,3,4,6,8,9,10,12,14,15 and the | |
10 | |
t | |
h | |
10th number is | |
15 | |
15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment