QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580190#9381. 502 Bad GatewayKopicyWA 388ms3668kbC++23803b2024-09-21 20:26:022024-09-21 20:26:03

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-21 20:26:03]
  • 评测
  • 测评结果:WA
  • 用时:388ms
  • 内存:3668kb
  • [2024-09-21 20:26:02]
  • 提交

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'