結果

問題 No.917 Make One With GCD
ユーザー finefine
提出日時 2019-09-13 14:29:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 344 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 69,412 KB
最終ジャッジ日時 2024-06-24 11:03:02
合計ジャッジ時間 3,142 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict
from copy import deepcopy

def main():
	n = int(input())
	a = list(map(int, input().split()))

	dp = defaultdict(int)

	for x in a:
		new_dp = deepcopy(dp)
		for k, v in dp.items():
			new_dp[math.gcd(k, x)] += v

		new_dp[x] += 1
		dp = new_dp

	print(dp[1])

if __name__ == "__main__":
	main()
0