玄关求条!样例有无 -1 正好相反
查看原帖
玄关求条!样例有无 -1 正好相反
1140668
___W___Z___L___PVP楼主2025/1/13 20:42
#include <bits/stdc++.h>
using namespace std;
#define int long long

inline int read() {
	char c = getchar();
	int f = 1;
	int x = 0;
	while (c < '0' || c > '9') {
		if (c == '-')
			f = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + (c^'0');
		c = getchar();
	}
	return x * f;
}
int t, x, y;

int exgcd(int a, int b) {
	if (!b) {
		x = 1;
		y = 0;
		return a;
	}
	int res = exgcd(b, a % b);
	int t = x;
	x = y;
	y = t - a / res * y;
	return res;
}

signed main() {
	t = read();
	while (t--) {
		int a = read(), b = read(), c = read();
		int res = exgcd(a, b);
		if (c % res == 0)
			cout << "-1";
		else {
			x = x * c / res, y = y * c / res;
			int xx = b / res, yy = a / res;
			x += xx * ceil((1.0 - x) / xx);
			y -= yy * ceil((1.0 - x) / xx);
			if (y <= 0) {
				cout << x << ' ' << y + yy *ceil((1.0 - y) / yy);
			} else {
				cout << (y - 1) / (yy + 1) << ' ' << x << ' ' << (y - 1) % yy + 1 << ' ' << x + (y - 1) / yy *xx << ' ' << y;
			}
		}
		x = 0, y = 0;
		cout << '\n';
	}

	return 0;
}
2025/1/13 20:42
加载中...