結果
問題 |
No.1036 Make One With GCD 2
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:09:15 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 874 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,212 KB |
実行使用メモリ | 171,600 KB |
最終ジャッジ日時 | 2025-06-12 21:10:22 |
合計ジャッジ時間 | 16,943 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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()