QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#593972 | #9381. 502 Bad Gateway | icesmoke | WA | 235ms | 3656kb | C++20 | 1.3kb | 2024-09-27 17:41:49 | 2024-09-27 17:41:49 |
Judging History
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();
}
}
详细
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'