結果

問題 No.917 Make One With GCD
ユーザー tpynerivertpyneriver
提出日時 2019-11-07 20:53:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 194 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 78,424 KB
最終ジャッジ日時 2023-09-06 16:45:14
合計ジャッジ時間 8,017 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 181 ms
77,932 KB
testcase_01 AC 167 ms
77,324 KB
testcase_02 AC 165 ms
77,552 KB
testcase_03 AC 165 ms
77,588 KB
testcase_04 AC 163 ms
77,604 KB
testcase_05 AC 164 ms
77,576 KB
testcase_06 AC 194 ms
78,300 KB
testcase_07 AC 183 ms
78,332 KB
testcase_08 AC 167 ms
78,028 KB
testcase_09 AC 181 ms
77,624 KB
testcase_10 AC 181 ms
77,744 KB
testcase_11 AC 180 ms
77,716 KB
testcase_12 AC 185 ms
78,424 KB
testcase_13 AC 180 ms
77,636 KB
testcase_14 AC 181 ms
77,924 KB
testcase_15 AC 183 ms
78,036 KB
testcase_16 AC 182 ms
78,040 KB
testcase_17 AC 169 ms
77,736 KB
testcase_18 AC 173 ms
77,664 KB
testcase_19 AC 166 ms
77,384 KB
testcase_20 AC 170 ms
77,780 KB
testcase_21 AC 176 ms
77,460 KB
testcase_22 AC 172 ms
77,440 KB
testcase_23 AC 179 ms
77,516 KB
testcase_24 AC 175 ms
77,732 KB
testcase_25 AC 182 ms
77,880 KB
testcase_26 AC 170 ms
77,584 KB
testcase_27 AC 171 ms
77,376 KB
testcase_28 AC 169 ms
77,548 KB
testcase_29 AC 166 ms
77,704 KB
testcase_30 AC 166 ms
77,408 KB
testcase_31 AC 165 ms
77,448 KB
testcase_32 AC 167 ms
77,464 KB
testcase_33 AC 166 ms
77,448 KB
testcase_34 AC 167 ms
77,480 KB
testcase_35 AC 166 ms
77,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

def divi(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n//i)
    return res

from collections import Counter
def prsh(N):
    prime = [2]
    for L in range(3,N):
        for p in prime:
            if not L % p:
                break
            if p > L**(1/2):
                prime.append(L)
                break
    return prime

def popcount(i):
    assert 0 <= i < 0x100000000
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

primes = prsh(10**5)
def munum(N, C = Counter()):
    diviprimes = []
    cnt = 0
    p = 0
    while N >= p**2:
        p = primes[cnt]
        if N % p == 0:
            diviprimes.append(p)
            N //= p
            while N % p == 0:
                N //= p
        cnt += 1
    if N != 1:
        diviprimes.append(N)
    
    M = len(diviprimes)
    for i in range(1<<M):
        res = 1
        k = popcount(i)
        for j in range(M):
            if i & (1<<j):
                res *= diviprimes[j]
        C[res] = (-1)**k
    
    return C


N = int(readline())
A = list(map(int, readline().split()))

divis = set()
Mu = Counter()
for a in A:
    Mu = munum(a, Mu)
    divis |= set(divi(a))

divis = list(divis)


res = 0
for d in divis:
    if Mu[d] == 0:
        continue
   
    cnt = sum(1 for a in A if a % d == 0)
    
    res += Mu[d] * (pow(2, cnt) - 1)

print(res)
0