結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー とりゐ
提出日時 2021-11-26 23:05:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 148,456 KB
最終ジャッジ日時 2024-11-08 05:15:47
合計ジャッジ時間 7,988 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#複数回素因数分解や約数列挙をする場合(n<=10^6)

#エラトステネスの篩
m=10**6*+1
eratosthenes=[-1]*(m+1)
for i in range(2,m+1):
  if eratosthenes[i]==-1:
    eratosthenes[i]=i
    j=2
    while i*j<=m:
      eratosthenes[i*j]=i
      j+=1
#n の素因数分解
import collections
def fact(n):
  c=[]
  while n!=1:
    k=eratosthenes[n]
    c.append(k)
    n//=k
  #return c
  return collections.Counter(c)
#n の約数列挙
def div(n):
  s=[1]
  while n!=1:
    p=eratosthenes[n]
    cnt=1
    n//=p
    while eratosthenes[n]==p:
      cnt+=1
      n//=p
    t=s.copy()
    for i in t:
      for j in range(1,cnt+1):
        s.append(i*(p**j))
  return s

n=int(input())
a=list(map(int,input().split()))
mx=max(a)
c=collections.Counter(a)
cnt=[0]*(mx+1)
for i in c:
  j=c[i]
  for k in div(i):
    cnt[k]+=j
ans=[1]*(n)
for i in range(2,mx+1):
  if cnt[i]!=0:
    ans[n-cnt[i]]=i
for i in range(1,n):
  ans[i]=max(ans[i],ans[i-1])
for i in range(n):
  print(ans[i])
0