結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー 👑 KazunKazun
提出日時 2021-11-05 22:43:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 697 ms / 2,000 ms
コード長 1,611 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 122,556 KB
最終ジャッジ日時 2024-04-25 17:30:55
合計ジャッジ時間 7,753 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 697 ms
122,428 KB
testcase_01 AC 34 ms
53,412 KB
testcase_02 AC 60 ms
78,148 KB
testcase_03 AC 67 ms
81,404 KB
testcase_04 AC 63 ms
77,924 KB
testcase_05 AC 61 ms
78,836 KB
testcase_06 AC 59 ms
78,108 KB
testcase_07 AC 63 ms
78,180 KB
testcase_08 AC 37 ms
52,828 KB
testcase_09 AC 55 ms
74,276 KB
testcase_10 AC 67 ms
77,728 KB
testcase_11 AC 34 ms
53,208 KB
testcase_12 AC 34 ms
53,056 KB
testcase_13 AC 359 ms
121,836 KB
testcase_14 AC 314 ms
121,896 KB
testcase_15 AC 328 ms
122,196 KB
testcase_16 AC 358 ms
122,232 KB
testcase_17 AC 363 ms
122,180 KB
testcase_18 AC 243 ms
109,712 KB
testcase_19 AC 274 ms
122,192 KB
testcase_20 AC 280 ms
116,692 KB
testcase_21 AC 287 ms
116,824 KB
testcase_22 AC 697 ms
118,196 KB
testcase_23 AC 101 ms
103,700 KB
testcase_24 AC 120 ms
119,712 KB
testcase_25 AC 249 ms
122,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Smallest_Prime_Factor(N):
    """ 0,1,2,...,N の最小の素因数のリスト (0,1 については 1 にしている)
    """

    if N==0:
        return [1]

    N=abs(N)
    L=list(range(N+1))
    L[0]=L[1]=1

    x=4
    while x<=N:
        L[x]=2
        x+=2

    x=9
    while x<=N:
        if L[x]==x:
            L[x]=3
        x+=6

    x=5
    Flag=0
    while x*x<=N:
        if L[x]==x:
            y=x*x
            while y<=N:
                if L[y]==y:
                    L[y]=x
                y+=x<<1
        x+=2+2*Flag
        Flag^=1

    return L

def Faster_Prime_Factorization(N,L):
    """ Smallest_Prime_Factors(N)で求めたリストを利用して, N を高速素因数分解する.

    L: Smallest_Prime_Factors(N)で求めたリスト
    """
    N=abs(N)

    D=[]
    while N>1:
        a=L[N]
        k=0
        while L[N]==a:
            k+=1
            N//=a
        D.append([a,k])
    return D

def Divisors_from_Prime_Factor(P,sorting=False):
    X=[1]
    for p,e in P:
        q=1
        n=len(X)
        for _ in range(e):
            q*=p
            for j in range(n):
                X.append(X[j]*q)

    if sorting:
        X.sort()

    return X
#==================================================

N=int(input())
A=list(map(int,input().split()))

alpha=max(A)
L=Smallest_Prime_Factor(alpha)
T=[0]*(alpha+1)

for a in A:
    P=Faster_Prime_Factorization(a,L)
    for d in Divisors_from_Prime_Factor(P):
        T[d]+=1

X=[0]*(N+1)
for i in range(alpha+1):
    X[T[i]]=i

for i in range(N-1,0,-1):
    X[i]=max(X[i],X[i+1])

print(*X[:0:-1],sep="\n")
0