結果
問題 |
No.1036 Make One With GCD 2
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:16:48 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 915 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 163,588 KB |
最終ジャッジ日時 | 2025-06-12 16:18:09 |
合計ジャッジ時間 | 17,052 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 34 TLE * 1 -- * 6 |
ソースコード
import sys import math def main(): input = sys.stdin.read().split() n = int(input[0]) A = list(map(int, input[1:n+1])) total = 0 prev_gcd = {} for num in A: current_gcd = {} # Process each GCD from the previous step for g in prev_gcd: cnt = prev_gcd[g] new_g = math.gcd(g, num) if new_g in current_gcd: current_gcd[new_g] += cnt else: current_gcd[new_g] = cnt # Add the current number as a new subarray if num in current_gcd: current_gcd[num] += 1 else: current_gcd[num] = 1 # Update the total with the count of GCD 1 if 1 in current_gcd: total += current_gcd[1] # Set current_gcd as prev_gcd for the next iteration prev_gcd = current_gcd print(total) if __name__ == '__main__': main()