結果

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

ソースコード

diff #

import sys
import math

def main():
    n = int(sys.stdin.readline())
    A = list(map(int, sys.stdin.readline().split()))
    result = 0
    prev = {}

    for a in A:
        if a == 1:
            count = sum(prev.values()) + 1
            result += count
            prev = {1: count}
            continue
        temp = {a: 1}
        prev_list = list(prev.items())
        for g, cnt in prev_list:
            new_g = math.gcd(g, a)
            if new_g in temp:
                temp[new_g] += cnt
            else:
                temp[new_g] = cnt
        if 1 in temp:
            result += temp[1]
        prev = temp

    print(result)

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