QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#886#586653#9381. 502 Bad Gatewayucup-team1769ucup-team1769Success!2024-09-24 14:55:242024-09-24 14:55:24

Details

Extra Test:

Wrong Answer
time: 0ms
memory: 3548kb

input:

1
4

output:

5 2

result:

wrong answer 1st lines differ - expected: '7 3', found: '5 2'

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586653#9381. 502 Bad Gatewayucup-team1769WA 463ms11212kbC++201.5kb2024-09-24 14:52:282024-09-24 14:57:56

answer

#include <bits/stdc++.h>
#define int long long
using u32 = unsigned;
using i64 = long long;
using u64 = unsigned long long;
using namespace std;
void solve() {
    int n;
    std::cin >> n;

    std::vector<int> t(n);
    for (int i = 0; i < n; i++) {
        std::cin >> t[i];
        int ansx = t[i] + 1, ansy = 2;
        int g = std::gcd(ansx, ansy);
        ansx /= g, ansy /= g;
        int f=max((int)(sqrt(t[i]/2)),3ll);
        /*
        for(int j= 0;j<20;j++)
        {
            int now=no+j;
            if(now<2||now>t[i])
                break;
            int _=t[i]/now;
            int nx=(t[i]-_)*2+(_+1)*(_);
            int ny=_*2;
            int ng = std::gcd(nx, ny);
            nx/=ng,ny/=ng;
            if(ansx * ny > nx * ansy)
            {
                ansx=nx;
                ansy=ny;
                f=now;
            }
        }
        */
        for(int j=t[i]/(f+1);j<t[i]/(f-1);j++)
        {
            int nx=(t[i]-j)*2+(j+1)*(j);
            int ny=j*2;
            int ng = std::gcd(nx, ny);
            nx/=ng,ny/=ng;
            if(ansx * ny > nx * ansy)
            {
                ansx=nx;
                ansy=ny;
            }
        }
        std::cout << ansx <<" "<< ansy << "\n";
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    //std::cin >> t;
    t = 1;

    while (t--) {
        solve();
    }
}