Pagini recente » Cod sursa (job #93196) | Cod sursa (job #649784) | Cod sursa (job #435086) | Cod sursa (job #844727) | Cod sursa (job #1355151)
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
public static long[] euclid(long a, long b) {
if (b == 0) {
return new long[]{1, 0, a};
}
long[] result = euclid(b, a % b);
long x = result[1];
long y = result[0] - (a / b) * result[1];
return new long[]{x, y, result[2]};
}
public static void main(String[] args) throws FileNotFoundException, IOException {
String fin = "euclid3.in";
FileInputStream fis = new FileInputStream(fin);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
if ((line = br.readLine()) != null) {
PrintWriter pw = new PrintWriter("euclid3.out");
int lineCount = Integer.parseInt(line);
for (; lineCount != 0 && line != null; lineCount--) {
line = br.readLine();
String[] parts = line.split(" ");
long eqres = Long.parseLong(parts[2]);
if (parts.length == 3) {
long result[] = euclid(Long.parseLong(parts[0]), Long.parseLong(parts[1]));
if(eqres%result[2] != 0){
pw.println("0 0");
} else {
pw.println( (( result[0] * eqres) / result[2]) +" "+(( result[1] * eqres) / result[2])); }
}
}
pw.close();
}
br.close();
}
}