QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#580286#9381. 502 Bad GatewaysyhyydsTL 15ms10608kbPython3516b2024-09-21 20:55:552024-09-21 20:55:56

Judging History

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

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-21 20:55:56]
  • 评测
  • 测评结果:TL
  • 用时:15ms
  • 内存:10608kb
  • [2024-09-21 20:55:55]
  • 提交

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...

result: