結果

問題 No.1036 Make One With GCD 2
ユーザー gew1fw
提出日時 2025-06-12 16:45:21
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 382 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,092 KB
実行使用メモリ 190,464 KB
最終ジャッジ日時 2025-06-12 16:45:49
合計ジャッジ時間 17,603 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
total = 0
prev_gcds = defaultdict(int)

for num in a:
    curr_gcds = defaultdict(int)
    curr_gcds[num] = 1
    for g in prev_gcds:
        new_g = math.gcd(g, num)
        curr_gcds[new_g] += prev_gcds[g]
    total += curr_gcds.get(1, 0)
    prev_gcds = curr_gcds

print(total)
0