对应整数数列𝐴_1,𝐴_2,…,𝐴_𝑛 是否存在𝑋_1,𝑋_2,…,𝑋_𝑛,使得𝐴_1 𝑋_1+𝐴_2 𝑋_2+…+𝐴_𝑛 𝑋_𝑛=𝐶,其中 gcd(𝐴_1,𝐴_2,…,𝐴_𝑛)|𝐶(𝑛≥2) 。如请找出一组整数解(𝑥_1,𝑥_2,𝑥_3,𝑥_4)满足12𝑥_1+24𝑥_2+18𝑥_3+15𝑥_4=3 。
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream is = System.in;
OutputStream os = System.out;
InputReader in = new InputReader(is);
PrintWriter out = new PrintWriter(os);
Solver solver = new Solver();
solver.solve(in, out);
out.close();
}
static class Solver {
long[] ans = new long[10];
long[] a = {-1, 12, 24, 28, 15};
long[] g = new long[10];
long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void exgcd(long a, long b, long[] d, long[] x, long[] y) {
if (b == 0) {
x[0] = 1;
y[0] = 0;
d[0] = a;
return;
}
exgcd(b, a % b, d, y, x);
y[0] -= a / b * x[0];
}
void solve(int i, long c) {
long[] x = new long[2];
long[] y = new long[2];
long[] d =new long[2];
exgcd(g[i - 1], a[i], d, x, y);
y[0] = y[0] * (c / d[0]);
x[0] = x[0] * (c / d[0]);
ans[i] = y[0];
if (i == 2) {
ans[i - 1] = x[0];
} else {
solve(i - 1, c - a[i] * y[0]);
}
}
public void solve(InputReader in, PrintWriter out) {
long dd = a[1];
for (int i = 1; i < 4; i++) {
dd = gcd(dd, a[i]);
g[i] = dd;
}
solve(4, 3);
long s = 0;
for (int i = 1; i <= 4; i++) {
s += ans[i] * a[i];
out.println(ans[i]);
}
out.println(s);
}
}
}