結果

問題 No.12 限定された素数
ユーザー square1001square1001
提出日時 2022-02-17 11:53:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 4,008 ms / 5,000 ms
コード長 876 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 10,832 KB
実行使用メモリ 61,020 KB
最終ジャッジ日時 2023-09-11 17:35:59
合計ジャッジ時間 105,392 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,857 ms
60,984 KB
testcase_01 AC 3,868 ms
60,836 KB
testcase_02 AC 3,778 ms
60,872 KB
testcase_03 AC 4,008 ms
60,972 KB
testcase_04 AC 3,763 ms
60,860 KB
testcase_05 AC 3,874 ms
60,960 KB
testcase_06 AC 3,705 ms
60,860 KB
testcase_07 AC 3,912 ms
60,928 KB
testcase_08 AC 3,865 ms
60,948 KB
testcase_09 AC 3,778 ms
60,844 KB
testcase_10 AC 3,886 ms
61,020 KB
testcase_11 AC 3,767 ms
60,900 KB
testcase_12 AC 3,808 ms
60,908 KB
testcase_13 AC 3,859 ms
61,020 KB
testcase_14 AC 3,865 ms
60,912 KB
testcase_15 AC 3,859 ms
60,852 KB
testcase_16 AC 3,844 ms
60,924 KB
testcase_17 AC 3,830 ms
60,960 KB
testcase_18 AC 3,814 ms
60,848 KB
testcase_19 AC 3,840 ms
60,836 KB
testcase_20 AC 3,843 ms
60,896 KB
testcase_21 AC 3,926 ms
60,976 KB
testcase_22 AC 3,725 ms
60,876 KB
testcase_23 AC 3,723 ms
60,780 KB
testcase_24 AC 3,810 ms
60,780 KB
testcase_25 AC 3,817 ms
60,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Input
M = int(input())
A = list(map(int, input().split()))
bit = sum(2 ** x for x in A)

# Eratosthenes' sieve
LIMIT = 5000000
prime = [ False ] * (LIMIT + 1)
prime[2] = True
for i in range(3, LIMIT + 1, 2):
	prime[i] = True
for i in range(3, LIMIT + 1, 2):
	if prime[i]:
		for j in range(i * i, LIMIT + 1, 2 * i):
			prime[j] = False
plist = list(filter(lambda x: prime[x], range(2, LIMIT + 1)))

# Calculation
K = len(plist)
recent = [ -1 ] * 10
answer = -1
for i in range(K):
	x = plist[i]
	while x > 0:
		recent[x % 10] = i
		x //= 10
	recmin, recmax = i + 1, -1
	for j in range(10):
		if ((bit >> j) & 1) == 1:
			recmin = min(recmin, recent[j])
		else:
			recmax = max(recmax, recent[j])
	if recmax < recmin:
		truel = (plist[recmax] + 1 if recmax != -1 else 1)
		truer = (plist[i + 1] - 1 if i != K - 1 else LIMIT)
		answer = max(answer, truer - truel)

print(answer)
0