众所周知:

  • 0=02=020=0^2=0^2
  • 4k=(k+1)2(k1)24k=(k+1)^2-(k-1)^2
  • 2k+1=(k+1)2k22k+1=(k+1)^2-k^2
  • 对于 n=4k+2n=4k+2 无解。
  • 以上式子中 kk 为非负整数。

直接分情况讨论即可。

#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)
        {
            cout << "0 0" << endl;
            continue;
        }
        switch (n % 4)
        {
            case 0:
            {
                cout << n / 4 + 1 << ' ' << n / 4 - 1 << endl;
                break;
            }
            case 2:
            {
                cout << "-1 -1" << endl;
                break;
            }
            default:
            {
                cout << n / 2 + 1 << ' ' << n / 2 << endl;
                break;
            }
        }
    }
    return 0;
}