QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#581173#9381. 502 Bad GatewayMENDAXWA 199ms3624kbC++14933b2024-09-22 10:24:222024-09-22 10:24:23

Judging History

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

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

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=2e5+5;

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

void slove(){
	int n;cin>>n;
	int x=(1+n)*n/2+n,y=n*n; 
	int d=gcd(x,y);
	x/=d,y/=d; 
	//二分找到第一个大于d的数
	int l=1,r=n+1;
	while(l<r){
		int mid=(l+r)/2;
		if(mid*y<=x*n) l=mid+1;
		else r=mid;
	}
	if(r==n+1){
		int p1=(1+n)*n/2,p2=n;
		int d1=gcd(p1,p2);
		cout<<p1/d1<<" "<<p2/d1<<endl; 
	} 
	else { 
		int p1=(l-1+1)*(l-1)/2,p2=n;
		int d1=gcd(p1,p2);
		p1/=d1,p2/=d1;
		//后面的期望都是x/y;
		x*=(n-l+1);
		d=gcd(x,y);
		x/=d,y/=d;
		int d2=gcd(p2,y);
		int lc=p2/d2*y;
		int n1=lc/p2*p1,n2=lc/y*x;
		int x=n1+n2,y=lc;
		int d3=gcd(x,y);
		cout<<x/d3<<" "<<y/d3<<endl;
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T=1;
	cin>>T;
	while(T--) slove();
} 

詳細信息

Test #1:

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

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 199ms
memory: 3552kb

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
750000001999999999 2000000000
1 1
1 1
750000001999999999 2000000000
1 1
750000001999999999 2000000000
1 1
1 1
1 1
750000001999999999 2000000000
1 1
1 1
750000001999999999 2000000000
1 1
750000001999999999 2000000000
750000001999999999 2000000000
1 1
750000001999999999 2000000000
1 1
1 1
75000000...

result:

wrong answer 2nd lines differ - expected: '1999961560 44721', found: '750000001999999999 2000000000'