QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590258#9381. 502 Bad Gatewaydaniel14311531WA 185ms3644kbC++20719b2024-09-25 22:58:322024-09-25 22:58:34

Judging History

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

  • [2024-09-25 22:58:34]
  • 评测
  • 测评结果:WA
  • 用时:185ms
  • 内存:3644kb
  • [2024-09-25 22:58:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

pair<ll, ll> calc(ll n, ll l) {
	ll x = 1ll * (l + 1) * l + n * 2ll - 2ll * l, y = 2ll * l;
	ll d = __gcd(x, y);
	return {x / d, y / d};
}
int main() {
	ios::sync_with_stdio(0); cin.tie(nullptr);
	int T; cin >> T;
	for(; T; --T) {
		int n; cin >> n;
		int l = 0, r = n, mid;
		for(; l < r;) {
			mid = (l + r + 1) >> 1;
			if(1ll * mid * mid <= 2ll * n) l = mid;
			else r = mid - 1;
		}
		pair<ll, ll> x = calc(n, l);
		pair<ll, ll> y = calc(n, l < n ? l + 1 : l);
		pair<ll, ll> ans;
		if(x.first * y.second > y.first * x.second) ans = x;
		else ans = y;
		cout << ans.first << " " << ans.second << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3564kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 185ms
memory: 3644kb

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
2000006281 44722
1 1
1 1
2000006281 44722
1 1
2000006281 44722
1 1
1 1
1 1
2000006281 44722
1 1
1 1
2000006281 44722
1 1
2000006281 44722
2000006281 44722
1 1
2000006281 44722
1 1
1 1
2000006281 44722
1 1
2000006281 44722
2000006281 44722
1 1
2000006281 44722
2000006281 44722
2000006281 44722
20...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '2000006281 44722'