QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588377#9381. 502 Bad GatewayJTaoWA 148ms3644kbC++111.1kb2024-09-25 10:09:022024-09-25 10:09:03

Judging History

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

  • [2024-09-25 10:09:03]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:3644kb
  • [2024-09-25 10:09:02]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e7 + 5;
const int mod = 1e9 + 7;

int n;
int gcd(int a, int b) {
    int c;
    while (b) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
void prin(int a, int b, int c, int d) {
    int t1 = a * d + b * c;
    int t2 = b * d;
    int t = gcd(t1, t2);
    cout << t1 / t << " " << t2 / t << '\n';
}
void solve() {
    cin >> n;
    int t = sqrt(2 * n);
    if (t * t == n) {
        prin(t - 1, 2, n, t);
    }
    else {
        int t1, t2;
        if (t * t > n) {
            t1 = t - 1; 
            t2 = t;
        }
        else {
            t1 = t;
            t2 = t + 1;
        }
        if ((t1 - 1) / 2 + n / t1 > (t2 - 1) / 2 + n / t2) {
            prin(t2 - 1, 2, n, t2);
        }
        else {
            prin(t1 - 1, 2, n, t1);
        }
    }

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

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

詳細信息

Test #1:

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

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 148ms
memory: 3644kb

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
49997921 1118
1 1
1 1
49997921 1118
1 1
49997921 1118
1 1
1 1
1 1
49997921 1118
1 1
1 1
49997921 1118
1 1
49997921 1118
49997921 1118
1 1
49997921 1118
1 1
1 1
49997921 1118
1 1
49997921 1118
49997921 1118
1 1
49997921 1118
49997921 1118
49997921 1118
49997921 1118
49997921 1118
49997921 1118
1 ...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '49997921 1118'