QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588015#9381. 502 Bad GatewayroufuboTL 1ms3800kbC++14706b2024-09-24 23:37:542024-09-24 23:37:55

Judging History

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

  • [2024-09-24 23:37:55]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3800kb
  • [2024-09-24 23:37:54]
  • 提交

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...

output:


result: