按题意直接模拟即可。(记得要特判 00

AC code:

#include <bits/stdc++.h>
using namespace std;

int main() {
    freopen("sd.in", "r", stdin);
    freopen("sd.out", "w", stdout);
    int T;
    cin >> T;
    while (T--) {
        long long n;
        cin >> n;
        if (n == 0) {
            cout << "0 0" << endl;
            continue;
        }
        if (n % 4 == 2) {
            cout << "-1 -1" << endl;
            continue;
        }
        long long x, y;
        bool found = false;
        for (long long b = 1; b * b <= n; ++b) {
            if (n % b == 0) {
                long long a = n / b;
                if ((a + b) % 2 == 0) {
                    x = (a + b) / 2;
                    y = (a - b) / 2;
                    if (x <= n && y >= 0) {
                        cout << x << " " << y << endl;
                        found = true;
                        break;
                    }
                }
            }
        }
        if (!found) {
            cout << "-1 -1" << endl;
        }
    }
    return 0;
}