QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589968 | #9381. 502 Bad Gateway | Lanzy | WA | 0ms | 3672kb | C++14 | 1.2kb | 2024-09-25 20:52:08 | 2024-09-25 20:52:09 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0)
using namespace std;
const int N=2e5+10;
int n;
double check(int x){
if(x==0){
1.0*(n+1)/2;
}
if(x>n){
return 1e18;
}
if(x==n){
return 1.0*(x-1)/2.0;
}
return 1.0*(x-1)/2.0+1.0*n/x;
}
void add(int &fz,int &fm,int z,int m){
int gcd=__gcd(fm,m);
fz*=m/gcd;
z*=fm/gcd;
fz+=z;
fm*=m/gcd;
gcd=__gcd(fz,fm);
fz/=gcd;
fm/=gcd;
}
void sol(int cases){
cin>>n;
if(n==1){
cout<<"1 1\n";
return;
}
int L=1,R=n;
while(L<=R){
int mid=(L+R)>>1;
if(check(mid)<=check(mid+1)){
R=mid-1;
}else{
L=mid+1;
}
}
int fz=L-1,fm=2;
// cout<<L<<'\n';
int gcd=__gcd(fz,fm);
fz/=gcd;
fm/=gcd;
// cout<<fz<<' '<<fm<<'\n';
// cout<<fz<<' '<<fm<<'\n';
if(L!=n){
add(fz,fm,n,L);
}
cout<<fz<<' '<<fm<<'\n';
}
signed main(){
IOS;
int t=1;
cin>>t;
for(int i=1;i<=t;++i){
sol(i);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3672kb
input:
3 1 2 3
output:
1 1 1 2 1 1
result:
wrong answer 2nd lines differ - expected: '3 2', found: '1 2'