QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#580286 | #9381. 502 Bad Gateway | syhyyds | TL | 15ms | 10608kb | Python3 | 516b | 2024-09-21 20:55:55 | 2024-09-21 20:55:56 |
Judging History
answer
def gcd(x, y):
if x == 0: return y
if y == 0: return x
return gcd(x, y%x) if x < y else gcd(y, x%y)
def sum(n):
return n*(n+1)/2
T=int(input())
while T:
n=int(input())
sm=int(sum(n))
if(n*n-n<=sm):
d=gcd(sm,n)
sm//=d
n//=d
print(sm,n)
else:
x=int(sm//n+1)
ans=int(n*sum(x))
ans+=(sm+n)*(n-x)
n=n*n
d=int(gcd(ans,n))
ans=ans//d
n=n//d
print(ans,n)
T=T-1
詳細信息
Test #1:
score: 100
Accepted
time: 15ms
memory: 10608kb
input:
3 1 2 3
output:
1 1 3 2 2 1
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
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 1464843753906250021761233 3906250000000000 1 1 1 1 1464843753906250021761233 3906250000000000 1 1 1464843753906250021761233 3906250000000000 1 1 1 1 1 1 1464843753906250021761233 3906250000000000 1 1 1 1 1464843753906250021761233 3906250000000000 1 1 1464843753906250021761233 3906250000000000 14...