結果
問題 | No.12 限定された素数 |
ユーザー | taisuke |
提出日時 | 2023-02-22 19:26:52 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 1,612 ms / 5,000 ms |
コード長 | 1,317 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 11,112 KB |
実行使用メモリ | 41,824 KB |
最終ジャッジ日時 | 2023-09-30 02:29:02 |
合計ジャッジ時間 | 43,708 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,594 ms
41,772 KB |
testcase_01 | AC | 1,539 ms
41,816 KB |
testcase_02 | AC | 1,567 ms
41,684 KB |
testcase_03 | AC | 1,489 ms
41,804 KB |
testcase_04 | AC | 1,602 ms
41,700 KB |
testcase_05 | AC | 1,588 ms
41,732 KB |
testcase_06 | AC | 1,526 ms
41,684 KB |
testcase_07 | AC | 1,522 ms
41,704 KB |
testcase_08 | AC | 1,550 ms
41,740 KB |
testcase_09 | AC | 1,605 ms
41,708 KB |
testcase_10 | AC | 1,558 ms
41,688 KB |
testcase_11 | AC | 1,476 ms
41,740 KB |
testcase_12 | AC | 1,509 ms
41,696 KB |
testcase_13 | AC | 1,550 ms
41,704 KB |
testcase_14 | AC | 1,566 ms
41,744 KB |
testcase_15 | AC | 1,565 ms
41,708 KB |
testcase_16 | AC | 1,527 ms
41,816 KB |
testcase_17 | AC | 1,578 ms
41,712 KB |
testcase_18 | AC | 1,585 ms
41,744 KB |
testcase_19 | AC | 1,596 ms
41,680 KB |
testcase_20 | AC | 1,557 ms
41,708 KB |
testcase_21 | AC | 1,612 ms
41,748 KB |
testcase_22 | AC | 1,559 ms
41,824 KB |
testcase_23 | AC | 1,544 ms
41,640 KB |
testcase_24 | AC | 1,590 ms
41,720 KB |
testcase_25 | AC | 1,560 ms
41,700 KB |
ソースコード
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)