QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#582015 | #9381. 502 Bad Gateway | Wood# | WA | 190ms | 3552kb | C++23 | 1.1kb | 2024-09-22 14:59:37 | 2024-09-22 14:59:37 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using i128 = __int128;
std::istream &operator>>(std::istream &is, i128 &n) {
n = 0;
std::string s;
is >> s;
for (auto c : s) {
n = 10 * n + c - '0';
}
return is;
}
std::ostream &operator<<(std::ostream &os, i128 n) {
if (n == 0) {
return os << 0;
}
std::string s;
while (n > 0) {
s += '0' + n % 10;
n /= 10;
}
std::reverse(s.begin(), s.end());
return os << s;
}
i128 gcd(i128 a, i128 b) {
return b ? gcd(b, a % b) : a;
}
void solve() {
int n;
std::cin >> n;
if (n == 2) {
std::cout << "3 2\n";
return;
}
i128 x = (n + 1) / 2, y = n - x;
i128 num = x * x * (x + 1) + y * (x * (x + 1) + 2 * n);
i128 den = x * n * 2;
i128 g = gcd(num, den);
num /= g;
den /= g;
std::cout << num << " " << den << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 190ms
memory: 3552kb
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 500000003 2 1 1 1 1 500000003 2 1 1 500000003 2 1 1 1 1 1 1 500000003 2 1 1 1 1 500000003 2 1 1 500000003 2 500000003 2 1 1 500000003 2 1 1 1 1 500000003 2 1 1 500000003 2 500000003 2 1 1 500000003 2 500000003 2 500000003 2 500000003 2 500000003 2 500000003 2 1 1 1 1 500000003 2 1 1 500000003 2 ...
result:
wrong answer 2nd lines differ - expected: '1999961560 44721', found: '500000003 2'