結果
| 問題 | 
                            No.1036 Make One With GCD 2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 20:48:09 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 741 bytes | 
| コンパイル時間 | 152 ms | 
| コンパイル使用メモリ | 82,244 KB | 
| 実行使用メモリ | 178,428 KB | 
| 最終ジャッジ日時 | 2025-06-12 20:50:24 | 
| 合計ジャッジ時間 | 17,001 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 34 TLE * 1 -- * 6 | 
ソースコード
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()
            
            
            
        
            
gew1fw