Created
November 2, 2016 09:25
-
-
Save bahriddin/f551fdc36b189cc231c552fe3beb05fa 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
package com.company; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
int q = in.nextInt(); | |
int a, b, d, tmp, res; | |
for (int i = 0; i < q; i++) { | |
a = in.nextInt(); | |
b = in.nextInt(); | |
d = in.nextInt(); | |
if(a > b) { | |
tmp = a; | |
a = b; | |
b = tmp; | |
} | |
res = d + b; | |
tmp = d / b + 1; | |
if(d % b == 0) | |
res = d / b; | |
else if(d % a == 0) { | |
res = d / a; | |
if(tmp < res) | |
res = tmp; | |
} | |
else if(d < b) | |
res = 2; | |
else { | |
for (int j = d / b; j > 0; j--) { | |
if((d - b*j) % a == 0) { | |
res = j + (d - b * j) / a; | |
break; | |
} | |
} | |
if(tmp < res) | |
res = tmp; | |
} | |
System.out.println(res); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment