結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー mesame3993mesame3993
提出日時 2021-09-16 00:10:44
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 489 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,816 KB
実行使用メモリ 817,108 KB
最終ジャッジ日時 2023-09-11 11:49:36
合計ジャッジ時間 3,051 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,040 KB
testcase_01 AC 16 ms
7,952 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def prime_number(n):
	# n >= 2
	prime = []
	limit = math.sqrt(n)
	data = [i + 1 for i in range(1, n)]
	while True:
		p = data[0]
		if limit <= p:
			return prime + data
		prime.append(p)
		data = [e for e in data if e % p != 0]

l, r = map(int, input().split())
if r*(r+1) - l*(l-1) // 2 <= 1:
	p = set()
else:
	p = set(prime_number((r*(r+1) - l*(l-1)) // 2))
	
ans = 0
for i in range(l, r+1):
	tmp = 0
	for j in range(i, r+1):
		tmp += j
		if tmp in p:
			ans += 1
print(ans)
0