結果

問題 No.917 Make One With GCD
ユーザー H20
提出日時 2021-12-27 17:19:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 63,872 KB
最終ジャッジ日時 2024-09-25 11:02:21
合計ジャッジ時間 2,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    a = list(set(a))
    m=1
    for i in a:
        m*=i
    return m

N = int(input())
A = list(map(int,input().split()))
d = collections.defaultdict(int)
for a in A:
    nd = collections.defaultdict(int)
    a = prime_factorize(a)
    for k,v in d.items():
        p = math.gcd(a,k)
        if p>1:
            nd[p]+=d[k]

    for k,v in d.items():
        nd[k]+=v    
    if a>1:
        nd[a]+=1
    d = nd
s = 0
for k,v in d.items():
    s+=v
print(2**N-1-s)

0