QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#883#582823#9381. 502 Bad Gatewaychenzq7jackFailed.2024-09-22 18:26:502024-09-22 18:26:50

詳細信息

Extra Test:

Accepted
time: 0ms
memory: 3660kb

input:

1
1

output:

1 1

result:

ok single line: '1 1'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#582823#9381. 502 Bad GatewayjackAC ✓236ms3668kbC++14781b2024-09-22 17:33:262024-09-24 14:56:49

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;


void solve()
{
    int n;
    cin>>n;
    ll p=(ll)sqrt((ll)2*n);
   
    ll q=p+1;
    ll f1=p*p-p+2*n;
    ll s1=2*p;
    double h=1.0*f1/s1;
    ll f2=q*q-q+2*n;
    ll s2=2*q;
    double h1=1.0*f2/s2;
    
    // cout<<h<<' '<<h1<<endl;
    if(q>n)
    {
       h1=1e18;   
    }
     //cout<<f2/__gcd(f2,s2)<<' '<<s2/__gcd(f2,s2)<<'\n';
    if(h<=h1)
    {
        cout<<f1/__gcd(f1,s1)<<' '<<s1/__gcd(f1,s1)<<'\n';
    }else
    {
         cout<<f2/__gcd(f2,s2)<<' '<<s2/__gcd(f2,s2)<<'\n';
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--) solve();
    return 0;
}