95pts RE求助
查看原帖
95pts RE求助
941502
_Gabriel_楼主2023/4/9 20:41
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
	ll ans = x % y;
	while (ans != 0) {
		x = y;
		y = ans;
		ans = x % y;
	}
	return y;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin >> T;
	while (T--) {
        ll a, b;
        cin >> a >> b;
        ll ans = gcd(a * a, b / a);
        ll t = (ll)(sqrt(ans)) + 0.5;
        if (b % a != 0) {
            cout << -1 << "\n";
            continue;
        }
        if (t * t != ans) {
            cout << -1 << "\n";
            continue;
        }
        cout << (b / a) / t << "\n";
    }
    return 0;
}

调了好久没调出来

2023/4/9 20:41
加载中...