結果
| 問題 |
No.1730 GCD on Blackboard in yukicoder
|
| コンテスト | |
| ユーザー |
とりゐ
|
| 提出日時 | 2021-11-26 23:06:47 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 523 ms / 2,000 ms |
| コード長 | 967 bytes |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 148,588 KB |
| 最終ジャッジ日時 | 2024-11-08 05:15:38 |
| 合計ジャッジ時間 | 8,135 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 24 |
ソースコード
#複数回素因数分解や約数列挙をする場合(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)
とりゐ