結果

問題 No.917 Make One With GCD
ユーザー convexineqconvexineq
提出日時 2019-10-25 22:32:55
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 1,435 bytes
コンパイル時間 640 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 76,580 KB
最終ジャッジ日時 2023-09-06 16:39:23
合計ジャッジ時間 5,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
76,260 KB
testcase_01 AC 72 ms
71,132 KB
testcase_02 AC 71 ms
71,144 KB
testcase_03 AC 70 ms
71,184 KB
testcase_04 AC 71 ms
71,124 KB
testcase_05 AC 71 ms
70,940 KB
testcase_06 AC 95 ms
76,392 KB
testcase_07 AC 89 ms
76,408 KB
testcase_08 AC 83 ms
76,268 KB
testcase_09 AC 120 ms
76,252 KB
testcase_10 AC 132 ms
76,372 KB
testcase_11 AC 142 ms
76,276 KB
testcase_12 AC 231 ms
76,548 KB
testcase_13 AC 116 ms
76,104 KB
testcase_14 AC 136 ms
76,272 KB
testcase_15 AC 146 ms
76,580 KB
testcase_16 AC 128 ms
76,400 KB
testcase_17 AC 76 ms
75,520 KB
testcase_18 AC 86 ms
76,308 KB
testcase_19 AC 72 ms
75,464 KB
testcase_20 AC 74 ms
75,224 KB
testcase_21 AC 83 ms
76,304 KB
testcase_22 AC 80 ms
76,196 KB
testcase_23 AC 94 ms
76,144 KB
testcase_24 AC 84 ms
76,276 KB
testcase_25 AC 101 ms
76,444 KB
testcase_26 AC 78 ms
76,060 KB
testcase_27 AC 70 ms
71,280 KB
testcase_28 AC 70 ms
71,140 KB
testcase_29 AC 68 ms
71,424 KB
testcase_30 AC 78 ms
76,112 KB
testcase_31 AC 71 ms
71,176 KB
testcase_32 AC 72 ms
75,100 KB
testcase_33 AC 74 ms
75,508 KB
testcase_34 AC 74 ms
71,348 KB
testcase_35 AC 74 ms
75,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!

import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

def prime_factorize(N): #素因数分解
    exponent = 0
    while N%2 == 0:
        exponent += 1
        N //= 2
    if exponent: factorization = [[2,exponent]]
    else: factorization = []
    i=1
    while i*i <=N:
        i += 2
        if N%i: continue
        exponent = 0
        while N%i == 0:
            exponent += 1
            N //= i
        factorization.append([i,exponent])
    if N!= 1: factorization.append([N,1])
    assert N != 0, "zero"
    return factorization

def divisor_list(N): #約数のリスト
    if N == 1: return [1]
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    return res

n = int(input())
a = [int(i) for i in readline().split()]
    
res = set()
pres = set()

for i in a:
    res|=set(divisor_list(i))
    P = prime_factorize(i)
    P = [pi[0] for pi in P]
    pres|=set(P)



ans = {i:0 for i in res}
for i in a: ans[i] += 1
res = sorted(list(res),reverse=True)


    
for p in pres:
    for c in res:
        if c%p==0: ans[c//p] += ans[c]

p2 = [1]
for i in range(100): p2.append(p2[-1]*2)


for i in ans:
    ans[i] = p2[ans[i]]-1


res = list(reversed(res))

for p in pres:
    for c in res:
        if c*p in res: ans[c] -= ans[c*p]

print(ans[1])

0