QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#584987#9381. 502 Bad GatewayIron_gainerWA 0ms3580kbC++20981b2024-09-23 18:14:572024-09-23 18:14:58

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-23 18:14:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3580kb
  • [2024-09-23 18:14:57]
  • 提交

answer

#include<bits/stdc++.h>
#include<array>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	else return gcd(b, a % b);
}
void solve()
{
	ll num;
	cin >> num;
	if (num == 1)
	{
		cout << 1 << " " << 1 << endl;
	}
	else if (num == 2)
	{
		cout << 2 << " " << 3 << endl;
	}
	else if (num == 3)
	{
		cout << 2 << " "<<1 << endl;
	}
	else
	{
		ll c = sqrt(2*num);
		ld fz1 = (c - 1) * c + num * 2;
		ld fm1 = 2 * c;
		c++;
		ld fz2 = (c - 1) * c + num * 2;
		ld fm2 = 2 * c;
		ll fz, fm;
		if (fz1 / fm1 < fz2 / fm2)
		{
			fz = fz1;
			fm = fm1;
		}
		else
		{
			fz = fz2;
			fm = fm2;
		}
		ll g = gcd(fz, fm);
		fz /= g;
		fm /= g;
		cout << fz << " " << fm << endl;
	}
}
void speed()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main()
{
	speed();
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3580kb

input:

3
1
2
3

output:

1 1
2 3
2 1

result:

wrong answer 2nd lines differ - expected: '3 2', found: '2 3'