比赛 2025.9.13 评测结果 AAAAAAAAAAAA
题目名称 Transforming Pairs 最终得分 100
用户昵称 xuyuqing 运行时间 0.175 s
代码语言 C++ 内存使用 3.69 MiB
提交时间 2025-09-13 09:53:37
显示代码纯文本

#include <cstdio>
#include <iostream>

using namespace std;

int t;
long long a;
long long b;
long long c;
long long d;
long long res;

int main () {
	
	freopen ("Transforming.in", "r", stdin);
	freopen ("Transforming.out", "w", stdout);

	cin >> t;
	for (int index = 1; index <= t; index++) {
		cin >> a >> b >> c >> d;
		if (a > c || b > d) {
			cout << -1 << endl;
			continue;
		}
		res = 0;
		while (true) {
			if (a == c && b == d) {
				cout << res << endl;
				break;
			}
			if (c > d) {
				long long t = (c - a) / d;
				if (!t) {
					cout << -1 << endl;
					break;
				}
				res += t;
				c -= t * d;
			}
			else {
				long long t = (d - b) / c;
				if (!t) {
					cout << -1 << endl;
					break;
				}
				res += t;
				d -= t * c;
			}
		}
	}
	
	return 0;
}