結果

問題 No.1036 Make One With GCD 2
ユーザー gew1fw
提出日時 2025-06-12 15:39:16
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 741 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 188,948 KB
最終ジャッジ日時 2025-06-12 15:39:36
合計ジャッジ時間 16,012 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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
    last_gcds = dict()

    for a in A:
        current_gcds = dict()
        # 单独成一个子序列
        current_gcds[a] = 1
        # 处理上一步的gcd
        for g in last_gcds:
            new_gcd = math.gcd(g, a)
            if new_gcd in current_gcds:
                current_gcds[new_gcd] += last_gcds[g]
            else:
                current_gcds[new_gcd] = last_gcds[g]
        # 统计结果
        if 1 in current_gcds:
            result += current_gcds[1]
        # 更新last_gcds
        last_gcds = current_gcds

    print(result)

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