QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#580190 | #9381. 502 Bad Gateway | Kopicy | WA | 388ms | 3668kb | C++23 | 803b | 2024-09-21 20:26:02 | 2024-09-21 20:26:03 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int m1=1;
int gcd(int a,int b){
return b?gcd(b,a%b):a;
}
void solve() {
int n;
cin>>n;
int lo=1,ro=n-1,po=-1;
if(n==1){
cout<<1<<" "<<1;
return;
}
if(n==2){
cout<<3<<" "<<2;
return;
}
auto get=[&](int x){
return (x+1)*x/2+n-x;
};
while(lo<=ro){
int mid=(lo+ro)/2;
if(get(mid)<mid*(mid+1)) ro=(po=mid)-1;
else lo=mid+1;
}
int d=gcd(get(po),po);
cout<<get(po)/d<<" "<<po/d;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int32_t tt = 1;
cin >> tt;
while (tt--) {
solve();
if(tt) cout<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3668kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 388ms
memory: 3592kb
input:
1000000 1 1000000000 1 1 1000000000 1 1000000000 1 1 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1000000000 1 1 1000000000 1 1000000000 1000000000 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1000000000 1 1000000000 1000000000 1000000000 1000000000 1 1 1 10000000...
output:
1 1 966890147 604995651 1 1 1 1 966890147 604995651 1 1 966890147 604995651 1 1 1 1 1 1 966890147 604995651 1 1 1 1 966890147 604995651 1 1 966890147 604995651 966890147 604995651 1 1 966890147 604995651 1 1 1 1 966890147 604995651 1 1 966890147 604995651 966890147 604995651 1 1 966890147 604995651 ...
result:
wrong answer 2nd lines differ - expected: '1999961560 44721', found: '966890147 604995651'