結果

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

ソースコード

diff #

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()
0