結果
| 問題 |
No.12 限定された素数
|
| コンテスト | |
| ユーザー |
taisuke
|
| 提出日時 | 2023-02-22 19:26:52 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,966 ms / 5,000 ms |
| コード長 | 1,317 bytes |
| コンパイル時間 | 418 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 44,348 KB |
| 最終ジャッジ日時 | 2024-07-22 20:23:19 |
| 合計ジャッジ時間 | 52,795 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
def Eratosthenes(n):
sieve = [True] * ((n + 1) // 2)
for i in range(1, (int(n ** 0.5) + 1) // 2):
if sieve[i]:
for j in range(i * 3 + 1, (n + 1) // 2, i * 2 + 1):
sieve[j] = False
res = [i * 2 + 1 for i, s in enumerate(sieve) if s]
res[0] = 2
return res
def check(nums, used, n):
cnt = [0, 0]
for i in range(10):
if used[i] > 0:
cnt[nums[i]] += 1
if cnt[0] > 0:
return -1
if cnt[1] < n:
return 0
return 1
def getDigits(x):
ret = []
while x > 0:
ret.append(x % 10)
x //= 10
return ret
n = int(input())
a = list(map(int, input().split()))
MAX = 5000000
prime = Eratosthenes(MAX)
nums = [0] * 10
for i in a:
nums[i] = 1
idx = 0
l = 1
k = 1
ans = -1
state = 0
pre = 0
while idx < len(prime):
d = []
state = 0
used = [0] * 10
while state != -1:
pre = state
k = prime[idx]
d.clear()
d = getDigits(k)
for i in d:
used[i] += 1
state = check(nums, used, n)
idx += 1
if idx >= len(prime):
pre = state
break
if pre == 1:
ans = max(ans, k - 1 - l)
if idx < len(prime):
l = k + 1
if state == 1:
ans = max(ans, MAX - l)
print(ans)
taisuke