結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:39:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 787 bytes |
| コンパイル時間 | 285 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 187,568 KB |
| 最終ジャッジ日時 | 2025-06-12 15:40:11 |
| 合計ジャッジ時間 | 17,467 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()))
ans = 0
prev_gcds = {}
for num in a:
current_gcds = {}
# 将当前元素单独作为一个子序列
current_gcds[num] = 1
# 遍历前一个位置的所有可能的gcd值
for g in prev_gcds:
new_gcd = math.gcd(g, num)
if new_gcd in current_gcds:
current_gcds[new_gcd] += prev_gcds[g]
else:
current_gcds[new_gcd] = prev_gcds[g]
# 统计当前字典中gcd为1的数量
ans += current_gcds.get(1, 0)
# 更新prev_gcds为当前的字典
prev_gcds = current_gcds
print(ans)
if __name__ == "__main__":
main()
gew1fw