QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749269#9381. 502 Bad Gatewayiwew#WA 166ms3628kbC++20566b2024-11-14 23:16:162024-11-14 23:16:17

Judging History

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

  • [2024-11-14 23:16:17]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:3628kb
  • [2024-11-14 23:16:16]
  • 提交

answer

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

typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int T;
	cin >> T;
	while(T -- ) {
		ll n;
		cin >> n;

		auto check = [&](ll x) -> bool {
			return x * x <= x + n;
		};

		ll l = 1, r = n;
		while(l < r) {
			ll mid = (l + r + 1) >> 1;
			if(check(mid)) l = mid;
			else r = mid - 1;
		}

		ll x = l * (l - 1) / 2 + n, y = l;
		cout << x / gcd(x, y) << ' ' << y / gcd(x, y) << '\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3552kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 166ms
memory: 3628kb

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
1499991253 31623
1 1
1 1
1499991253 31623
1 1
1499991253 31623
1 1
1 1
1 1
1499991253 31623
1 1
1 1
1499991253 31623
1 1
1499991253 31623
1499991253 31623
1 1
1499991253 31623
1 1
1 1
1499991253 31623
1 1
1499991253 31623
1499991253 31623
1 1
1499991253 31623
1499991253 31623
1499991253 31623
14...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '1499991253 31623'