結果
| 問題 |
No.1730 GCD on Blackboard in yukicoder
|
| コンテスト | |
| ユーザー |
👑 Kazun
|
| 提出日時 | 2021-11-05 22:43:20 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 936 ms / 2,000 ms |
| コード長 | 1,611 bytes |
| コンパイル時間 | 336 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 122,240 KB |
| 最終ジャッジ日時 | 2024-11-08 04:48:14 |
| 合計ジャッジ時間 | 9,630 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
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")
Kazun