結果
| 問題 | 
                            No.1036 Make One With GCD 2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             gew1fw
                         | 
                    
| 提出日時 | 2025-06-12 16:15:16 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 874 bytes | 
| コンパイル時間 | 258 ms | 
| コンパイル使用メモリ | 82,776 KB | 
| 実行使用メモリ | 171,844 KB | 
| 最終ジャッジ日時 | 2025-06-12 16:15:52 | 
| 合計ジャッジ時間 | 16,996 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 34 TLE * 1 -- * 6 | 
ソースコード
import math
def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    n = int(data[0])
    a = list(map(int, data[1:n+1]))
    
    total = 0
    current_gcds = dict()
    
    for num in a:
        temp = dict()
        # Process previous GCDs
        for g in current_gcds:
            new_g = math.gcd(g, num)
            if new_g in temp:
                temp[new_g] += current_gcds[g]
            else:
                temp[new_g] = current_gcds[g]
        # Add the current number as a single-element subarray
        if num in temp:
            temp[num] += 1
        else:
            temp[num] = 1
        # Update total with the count of GCD 1
        if 1 in temp:
            total += temp[1]
        # Update current_gcds for the next iteration
        current_gcds = temp
    
    print(total)
if __name__ == "__main__":
    main()
            
            
            
        
            
gew1fw