結果

問題 No.1036 Make One With GCD 2
ユーザー lam6er
提出日時 2025-04-16 16:30:33
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 624 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 191,344 KB
最終ジャッジ日時 2025-04-16 16:31:50
合計ジャッジ時間 18,267 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
from collections import defaultdict

def main():
    n = int(sys.stdin.readline())
    a = list(map(int, sys.stdin.readline().split()))
    total = 0
    prev = dict()
    for num in a:
        curr = defaultdict(int)
        # Process previous GCDs
        for g in prev:
            new_g = math.gcd(g, num)
            curr[new_g] += prev[g]
        # Add the current number as a single-element subarray
        curr[num] += 1
        # Update total
        total += curr.get(1, 0)
        # Update prev for next iteration
        prev = curr
    print(total)

if __name__ == "__main__":
    main()
0