QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#903#589042#9381. 502 Bad GatewayjjjjjxsjjjjjxsFailed.2024-09-25 15:52:462024-09-25 15:52:46

Details

Extra Test:

Accepted
time: 0ms
memory: 3588kb

input:

1
1000000000

output:

1999961560 44721

result:

ok single line: '1999961560 44721'

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#589042#9381. 502 Bad GatewayjjjjjxsAC ✓465ms3660kbC++141.1kb2024-09-25 15:52:102024-09-25 15:52:11

answer

#include <bits/stdc++.h>
#define int long long 
#define INF 0x3f3f3f3f
#define fr first
#define se second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;

const int N = 1e6 + 10;
ll t;

ll A(ll c,ll t)
{
	return c*(c-1)+2*t;
}

ll B(ll c,ll t)
{
	return 2*c;
}

double f(double c)
{
	return (c-1)/2 + t/c;
}

void solve()
{
	cin>>t;
	
	//三分解对勾函数
	ll lmid , rmid;
	ll lo = 0 , hi = t + 1;//[1,t]
	while(lo + 3 < hi)
	{
		ll lmid = lo + (hi - lo) / 3;
		ll rmid = hi - (hi - lo) / 3;
		if(f(lmid) < f(rmid)) hi = rmid;
		else lo = lmid;
	}

	//cout << hi - 1 << endl;
	ll c = lo;
	for(ll i = lo + 1; i <= hi; i++)
	{
		if(f(i) < f(c))
		{
			c = i;
		}
	}

	//ll ansc = (A(hi-1,t)*B(hi,t)<A(hi,t)*B(hi-1,t)) ? hi-1  : hi ;
	ll above = A(c,t);
	ll below = B(c,t);
	ll g = __gcd(above,below);
	above /= g;
	below /= g;
	cout << above <<' '<< below << endl;
}


signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T=1; cin>>T;
	while(T--) solve();
	return 0;
}