QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#593972#9381. 502 Bad GatewayicesmokeWA 235ms3656kbC++201.3kb2024-09-27 17:41:492024-09-27 17:41:49

Judging History

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

  • [2024-09-27 17:41:49]
  • 评测
  • 测评结果:WA
  • 用时:235ms
  • 内存:3656kb
  • [2024-09-27 17:41:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

struct val {
    int x, y;
    val(int _x, int _y)
    {
        int _g = __gcd(_x, _y);
        x = _x / _g, y = _y / _g;
    }
    val operator+(const val& it) const&
    {
        int ny = y / __gcd(y, it.y) * it.y;
        int nx = ny / y * x + ny / it.y * it.x;
        return val(nx, ny);
    }
    val operator*(const val& it) const&
    {
        return val(x * it.x, y * it.y);
    }
    bool operator<(const val& it) const&
    {
        return x * it.y < it.x * y;
    }
};

int n;

val cal(int c)
{
    // 	c*(1+c)/2 + (n-c)*(c+1)
    val res = val(c * (1 + c), 2) + val((n - c) * (c + 1), 1);
    return res * val(1, n);
}

void solve()
{
    cin >> n;
    val ans(2e9, 1);
    int v = sqrt(2 * n);
    // cout << v << ' ' << sqrt(2 * n) << '\n';
    for (int i = 0; i <= 1; i++) {
        if (v + i > 0) {
            // 	(x+1)/2 + n/x - 1
            val t = cal(min(v + i, n));
            if (t < ans)
                ans = t;
        }
    }
    cout << ans.x << ' ' << ans.y << '\n';
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 235ms
memory: 3580kb

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
44720999993719 1000000000
1 1
1 1
44720999993719 1000000000
1 1
44720999993719 1000000000
1 1
1 1
1 1
44720999993719 1000000000
1 1
1 1
44720999993719 1000000000
1 1
44720999993719 1000000000
44720999993719 1000000000
1 1
44720999993719 1000000000
1 1
1 1
44720999993719 1000000000
1 1
4472099999...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '44720999993719 1000000000'