結果
問題 |
No.1036 Make One With GCD 2
|
ユーザー |
![]() |
提出日時 | 2025-06-12 19:09:55 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 659 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,288 KB |
実行使用メモリ | 198,556 KB |
最終ジャッジ日時 | 2025-06-12 19:10:15 |
合計ジャッジ時間 | 18,251 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 TLE * 1 -- * 6 |
ソースコード
import math n = int(input()) a = list(map(int, input().split())) prev_gcds = {} ans = 0 for num in a: current_gcds = {} # Process previous GCDs for g in prev_gcds: new_g = math.gcd(g, num) if new_g in current_gcds: current_gcds[new_g] += prev_gcds[g] else: current_gcds[new_g] = prev_gcds[g] # Add the current number itself new_g = num if new_g in current_gcds: current_gcds[new_g] += 1 else: current_gcds[new_g] = 1 # Update the answer ans += current_gcds.get(1, 0) # Update prev_gcds for next iteration prev_gcds = current_gcds.copy() print(ans)