結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー とりゐとりゐ
提出日時 2021-11-26 23:06:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 419 ms / 2,000 ms
コード長 967 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 148,552 KB
最終ジャッジ日時 2024-04-25 17:53:24
合計ジャッジ時間 6,328 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
115,812 KB
testcase_01 AC 71 ms
70,800 KB
testcase_02 AC 71 ms
78,412 KB
testcase_03 AC 78 ms
83,792 KB
testcase_04 AC 75 ms
81,584 KB
testcase_05 AC 77 ms
80,608 KB
testcase_06 AC 76 ms
80,620 KB
testcase_07 AC 76 ms
82,324 KB
testcase_08 AC 66 ms
70,280 KB
testcase_09 AC 74 ms
76,064 KB
testcase_10 AC 81 ms
81,708 KB
testcase_11 AC 64 ms
70,276 KB
testcase_12 AC 63 ms
70,200 KB
testcase_13 AC 419 ms
145,528 KB
testcase_14 AC 389 ms
144,932 KB
testcase_15 AC 377 ms
145,228 KB
testcase_16 AC 415 ms
145,052 KB
testcase_17 AC 398 ms
145,688 KB
testcase_18 AC 296 ms
142,088 KB
testcase_19 AC 324 ms
148,552 KB
testcase_20 AC 157 ms
113,288 KB
testcase_21 AC 156 ms
113,592 KB
testcase_22 AC 147 ms
113,520 KB
testcase_23 AC 123 ms
111,896 KB
testcase_24 AC 130 ms
112,024 KB
testcase_25 AC 324 ms
148,320 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
tmp=1
for i in range(0,n):
  tmp=max(ans[i],tmp)
  print(tmp)
0