QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581173 | #9381. 502 Bad Gateway | MENDAX | WA | 199ms | 3624kb | C++14 | 933b | 2024-09-22 10:24:22 | 2024-09-22 10:24:23 |
Judging History
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();
}
Details
Tip: Click on the bar to expand more detailed information
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'