QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581386#9381. 502 Bad GatewayYoung_CloudRE 0ms0kbC++201.0kb2024-09-22 12:25:572024-09-22 12:25:58

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-22 12:25:58]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-09-22 12:25:57]
  • 提交

answer

#include<bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0)

using i64 = long long;
using i128 = __int128_t;

constexpr i64 Mod = 998244353, Inf = 1e18;
constexpr int N = 1e5, M = 1e5;

void solve()
{
    i64 t;
    std::cin >> t;
    i64 l = 0, r = t;
    while (l <= r) {
        i64 m = l + r >> 1;
        if (m * m < 2 * t) {
            l = m + 1;
        }
        else {
            r = m - 1;
        }
    }

    auto print = [&](i64 c) -> void {
        i64 a = (c - 1) * c + t * 2;
        i64 b = 2 * c;
        i64 g = std::__gcd(a, b);
        std::cout << a / g << " " << b / g << '\n';
    };

    if (l * l == 2 * t) {
        print(l);
    }
    else if (1.0 * l / 2.0 + 1.0 * t / l < 1.0 * r / 2.0 + 1.0 * t / r) {
        print(l);
    }
    else {
        print(r);
    }
    return;
}

int main()
{
    //IOS;
    int t = 1;
    std::cin >> t;
    
    while (t--)
    {
        solve();
    }

    system("pause");

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
1
2
3

output:

1 1
3 2

result: