結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー とりゐとりゐ
提出日時 2021-11-26 23:05:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 480 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 87,308 KB
実行使用メモリ 159,452 KB
最終ジャッジ日時 2023-08-07 23:42:21
合計ジャッジ時間 8,286 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 197 ms
126,640 KB
testcase_01 AC 119 ms
84,960 KB
testcase_02 AC 128 ms
92,844 KB
testcase_03 AC 134 ms
93,908 KB
testcase_04 AC 129 ms
93,420 KB
testcase_05 AC 134 ms
93,360 KB
testcase_06 AC 132 ms
93,048 KB
testcase_07 AC 133 ms
93,364 KB
testcase_08 AC 120 ms
84,960 KB
testcase_09 AC 129 ms
90,648 KB
testcase_10 AC 135 ms
91,356 KB
testcase_11 AC 120 ms
84,972 KB
testcase_12 AC 120 ms
84,940 KB
testcase_13 AC 470 ms
155,736 KB
testcase_14 AC 446 ms
155,756 KB
testcase_15 AC 445 ms
155,692 KB
testcase_16 AC 480 ms
155,656 KB
testcase_17 AC 460 ms
155,868 KB
testcase_18 AC 361 ms
152,732 KB
testcase_19 AC 386 ms
159,452 KB
testcase_20 AC 209 ms
121,928 KB
testcase_21 AC 210 ms
121,732 KB
testcase_22 AC 196 ms
124,220 KB
testcase_23 AC 181 ms
116,016 KB
testcase_24 AC 186 ms
123,696 KB
testcase_25 AC 370 ms
159,172 KB
権限があれば一括ダウンロードができます

ソースコード

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