/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 34ms 18.375 MiB
#2 Accepted 103ms 12.074 MiB
#3 Accepted 111ms 11.875 MiB
#4 Accepted 120ms 11.879 MiB
#5 Accepted 118ms 11.879 MiB
#6 Accepted 124ms 11.879 MiB
#7 Accepted 146ms 12.219 MiB
#8 Accepted 221ms 13.062 MiB
#9 Accepted 371ms 17.387 MiB
#10 Accepted 752ms 17.457 MiB
#11 Accepted 1352ms 17.449 MiB
#12 Accepted 1245ms 17.453 MiB
#13 Accepted 1383ms 17.457 MiB
#14 Accepted 1378ms 17.457 MiB
#15 Accepted 1428ms 17.453 MiB
#16 Accepted 1466ms 17.527 MiB
#17 Accepted 1459ms 28.141 MiB
#18 Accepted 3160ms 26.395 MiB

Code

import math as m
t = int(input())
for _ in range(t):
    n,x = map(int, input().split())
    a = list(map(int,input().split()))
    ans = [0]*1000001
    
    for ai in a:
        sq = int(m.sqrt(ai))
        for ii in range(1,sq+1,1):
            if(ai%ii):
                continue
            if(ii==ai//ii):
                ans[ii] += ai
            else:
                ans[ii] += ai
                ans[ai//ii] += ai
    
    sum = ans[x]
    sol = x
    for i in range(x,0,-1):
        if(ans[i]<=sum):
            sol=i
            sum=ans[i]
    print(sol)

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Language
Python 3 (Python 3.12.3)
Submit At
2024-03-20 17:38:36
Judged At
2024-11-11 03:40:32
Judged By
Score
100
Total Time
3160ms
Peak Memory
28.141 MiB