QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#580706#9381. 502 Bad GatewaytieguodundaeWA 323ms3704kbC++141.4kb2024-09-21 23:15:332024-09-21 23:15:38

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-21 23:15:38]
  • 评测
  • 测评结果:WA
  • 用时:323ms
  • 内存:3704kb
  • [2024-09-21 23:15:33]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", print_args(__VA_ARGS__)
template <class... T>
void print_args(T... args) { ((cerr << args << ' '), ...) << '\n'; }
using u32 = unsigned;
using u64 = unsigned long long;
using i64 = long long;
using i128 = __int128_t;
const int mod = 998244353;
void solve() {
    int n;
    cin >> n;
    int l = 1, r = sqrtl(2 * n) + 1;
    int t;
    while (l <= r) {
        int mid = (l + r + 1) / 2;
        if ((mid - 1) * mid >= 2 * n) {
            t = mid, r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    t -= 1;
    int x = 0, y = 1;
    if (t > 0) {
        x = t * (t + 1) / 2;
    }
    if (t + 1 <= n) {
        int fz = t * t + t + 2 * n;
        int fm = 2 * t;
        int g = __gcd(fz, fm);
        fz /= g;
        fm /= g;
        fz *= (n - t);
        x = x * fm + y * fz;
        y = y * fm;
        g = __gcd(fz, fm);
        x /= g;
        y /= g;
    }
    y = y * n;
    int g = __gcd(x, y);
    x /= g;
    y /= g;
    cout << x << ' ' << y << '\n';
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int _ = 1;
    cin >> _;
    while (_--) {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3704kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 223ms
memory: 3652kb

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
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1999961560 44721
19...

result:

ok 1000000 lines

Test #3:

score: -100
Wrong Answer
time: 323ms
memory: 3500kb

input:

1000000
158260522
877914575
602436426
24979445
861648772
623690081
433933447
476190629
262703497
211047202
971407775
628894325
731963982
822804784
450968417
430302156
982631932
161735902
880895728
923078537
707723857
189330739
910286918
802329211
404539679
303238506
317063340
492686568
773361868
125...

output:

316511467 17791
3933689276516783016 877914575
1204845831 34711
49954223 7068
983422319129195754 215412193
623676492 17659
3933689276516783016 433933447
3933689276516783016 476190629
3933689276516783016 262703497
1966844638258391508 105523601
1942776701 44077
251551941 7093
1463896912 38261
164558467...

result:

wrong answer 2nd lines differ - expected: '1755824328 41903', found: '3933689276516783016 877914575'