QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#588015 | #9381. 502 Bad Gateway | roufubo | TL | 1ms | 3800kb | C++14 | 706b | 2024-09-24 23:37:54 | 2024-09-24 23:37:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll t, ti;
ll gcd(ll a, ll b) {
if (b == 0)return a;
return gcd(b, a % b);
}
void solve() {
scanf("%d",&t);
if (t == 1)printf("1 1\n");
else if (t == 2)printf("3 2\n");
else if (t == 3)printf("2 1\n");
else {
ll dz = 100000, dm = 1, mi;
for (int i = 1; i < t; i++) {
ll z = (t + 1) / 2 ;
z = i;
ll h = t - z;
ll fz = (1 + z) * z / 2 + h;
ll fm = t - h;
ll gcds = gcd(fz, fm);
fz /= gcds, fm /= gcds;
if (fz * dm < dz * fm)dz = fz, dm = fm, mi = i;
}
printf("%lld %lld\n", dz, dm);
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3800kb
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...