HTML & JS
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define ll long long
#define key pair<int, int>
#define ff first
#define ss second
int mod = 1e9 + 7;
//const int inf = 1e15;
using namespace std;

main()
{
    fastread;
    int t; cin>>t;
    while(t--)
    {
        int k; cin>>k;
        int X = sqrt(k);
        bool p = 0;
        if(k == 0)
        {
            cout<<"1 1\n"; continue;
        }
        X++;
        for(int x = X; x < 100000; x++)
        {
            if(x*x - (x/2)*(x/2) > k) break;
            int st = 2, end = x-1, idx = -1;
            
            while(st <= end)
            {
                int mid = (st + end)/2;
                if(x*x - (x/mid)*(x/mid) > k)
                    end = mid-1;
                else if(x*x - (x/mid)*(x/mid) == k)
                {
                    idx = mid; break;
                }
                else
                    st = mid+1;
            }
            if(idx != -1) 
            {
                cout<<x<<" "<<idx;  p = 1; break;
            }
        }
        if(!p) cout<<"-1";
        cout<<"\n";
    }
}

Generated URL:

Output:

1 1
Report Bug