結果

問題 No.917 Make One With GCD
ユーザー tanon710tanon710
提出日時 2020-05-04 21:30:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 73,184 KB
最終ジャッジ日時 2024-06-24 11:15:49
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n=int(input())
arr=list(map(int,input().split()))
ans=2**n-1
for i in range(n):
    cand=primes(arr[i])
    for f in range(1,2**len(cand)):
        flag=format(f,'b')
        flag='0'*(len(cand)-len(flag))+flag
        tmp=1
        for k in range(len(cand)):
            if flag[k]=='1':
                tmp*=cand[k]
        cnt=0
        for j in range(i+1,n):
            if arr[j]%tmp==0:
                cnt+=1
        if flag.count('1')%2==0:
            ans+=2**cnt
        else:
            ans-=2**cnt
print(ans)    
0