QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#580317#9381. 502 Bad Gatewaysyhyyds#TL 13ms10628kbPython3521b2024-09-21 21:04:422024-09-21 21:04:43

Judging History

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

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

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


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 10628kb

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