結果
問題 |
No.1036 Make One With GCD 2
|
ユーザー |
![]() |
提出日時 | 2025-06-12 15:39:57 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 781 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 188,832 KB |
最終ジャッジ日時 | 2025-06-12 15:40:19 |
合計ジャッジ時間 | 15,506 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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())) total = 0 prev_gcds = {} for num in a: current_gcds = {} # 单独考虑当前数 current_gcds[num] = 1 # 遍历prev_gcds中的每个gcd值 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] # 统计当前的gcd=1的数量 if 1 in current_gcds: total += current_gcds[1] # 更新prev_gcds为current_gcds prev_gcds = current_gcds print(total) if __name__ == "__main__": main()