QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#580354 | #9381. 502 Bad Gateway | syhyyds# | WA | 201ms | 3716kb | C++17 | 1.2kb | 2024-09-21 21:22:09 | 2024-09-21 21:22:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
__int128 n;
__int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(!isdigit(ch)&&ch!='-')ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
void print(__int128 x)
{
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);//注意这里是x>9不是x>10 (2019.10 wa哭了回来标记一下)
putchar(x%10+'0');
}
__int128 gcd(__int128 a,__int128 b)
{ if(!b) return a;
return gcd(b,a%b);
}
__int128 sum(__int128 x){
return x*(x+1)/2;
}
int main(){
int T;
cin>>T;
while(T--)
{
n=read();
__int128 sm=sum(n);
if(n*n-n<=sm)
{
__int128 d=gcd(sm,n);
sm/=d;
n/=d;
print(sm);
printf(" ");
print(n);
printf("\n");
}
else
{
__int128 x=(sm/n+1);
__int128 ans=n*sum(x);
ans=ans+(sm+n)*(n-x);
n=n*n;
__int128 d=gcd(ans,n);
ans/=d;
n/=d;
print(ans);
printf(" ");
print(n);
printf("\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3716kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 201ms
memory: 3692kb
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'