目录
F - S = 1:
题目大意:
思路解析:
代码实现:
F - S = 1:
题目大意:
思路解析:
这道题需要解决的就是三角形面积怎么用 A、B、X、Y,表示。
exgcd求解大致思路:可看Codeforces Round 927 (Div. 3) G. Moving Platforms --- 题解 (非常好的题)-CSDN博客
代码实现:
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
long a = input.nextLong();
long b = input.nextLong();
long[] arr = exgcd(a, b);
if (2 % arr[0] != 0) out.println(-1);
else{
out.println(-arr[2] * 2 / arr[0] + " " + arr[1] * 2 / arr[0]);
}
out.flush();
out.close();
br.close();
}
public static long[] exgcd(long a, long b){
if (b == 0) return new long[]{a, 1, 0};
long[] arr = exgcd(b, a % b);
long k = a / b;
return new long[]{arr[0], arr[2], arr[1] - k * arr[2]};
}
static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
static Input input = new Input(System.in);
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static class Input {
public BufferedReader reader;
public StringTokenizer tokenizer;
public Input(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public char[] nextChars(){return next().toCharArray();}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}