結果

問題 No.1036 Make One With GCD 2
コンテスト
ユーザー gew1fw
提出日時 2025-06-12 14:12:12
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 659 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 228 ms
コンパイル使用メモリ 95,212 KB
実行使用メモリ 182,308 KB
最終ジャッジ日時 2026-07-11 11:13:23
合計ジャッジ時間 19,400 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import math

n = int(input())
a = list(map(int, input().split()))

prev_gcds = {}
ans = 0

for num in a:
    current_gcds = {}
    # Process previous GCDs
    for g in prev_gcds:
        new_g = math.gcd(g, num)
        if new_g in current_gcds:
            current_gcds[new_g] += prev_gcds[g]
        else:
            current_gcds[new_g] = prev_gcds[g]
    # Add the current number itself
    new_g = num
    if new_g in current_gcds:
        current_gcds[new_g] += 1
    else:
        current_gcds[new_g] = 1
    # Update the answer
    ans += current_gcds.get(1, 0)
    # Update prev_gcds for next iteration
    prev_gcds = current_gcds.copy()

print(ans)
0