QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#580887 | #9381. 502 Bad Gateway | buhuisuanfa | TL | 0ms | 3624kb | C++20 | 960b | 2024-09-22 00:40:10 | 2024-09-22 00:40:12 |
Judging History
answer
#include<bits/stdc++.h>
#define sz(x) (x).size()
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
using namespace std;
using ll = long long;
struct frac {
int a, b;
bool operator<(const frac &rhs) {
return 1ll * a * rhs.b < 1ll * b * rhs.a;
}
};
void solve() {
int T;
cin >> T;
int sqrtT = sqrt(2 * T);
int lo = max(sqrtT - 100, 1);
int hi = min(sqrtT + 100, T);
auto calc = [&](int i) {
frac res;
res.b = 2 * i;
res.a = 1ll * i * i - i + 2 * T;
int d = gcd(res.a, res.b);
res.a /= d;
res.b /= d;
return res;
};
frac ans = calc(1);
for (int i = lo; i <= hi; i++) {
frac temp = calc(i);
if(ans < temp) ;
else ans = temp;
}
cout << ans.a << " " << ans.b << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
std::cin >> t;
for (; t; t--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3624kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
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 -151989138 44621 1 1 1 1 -151989138 44621 1 1 -151989138 44621 1 1 1 1 1 1 -151989138 44621 1 1 1 1 -151989138 44621 1 1 -151989138 44621 -151989138 44621 1 1 -151989138 44621 1 1 1 1 -151989138 44621 1 1 -151989138 44621 -151989138 44621 1 1 -151989138 44621 -151989138 44621 -151989138 44621 -1...