結果
問題 |
No.12 限定された素数
|
ユーザー |
![]() |
提出日時 | 2020-09-03 09:32:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 433 ms / 5,000 ms |
コード長 | 778 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 82,116 KB |
実行使用メモリ | 115,584 KB |
最終ジャッジ日時 | 2024-11-22 20:56:39 |
合計ジャッジ時間 | 11,857 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
n = int(input()) a = [False] * 10 for x in map(int, input().split()): a[x] = True sieve = [True] * 5000002 ans = -1 k = 1 d = [False] * 10 for p in range(2, 5000002): if sieve[p] or p == 5000001: for i in range(p * p, 5000002, p): sieve[i] = False if p < 5000001: ok = True for x in map(int, str(p)): if not a[x]: ok = False break if not ok or p == 5000001: for i in range(10): if a[i] != d[i]: break else: ans = max(ans, p - 1 - k) k = p + 1 d = [False] * 10 else: for x in map(int, str(p)): d[x] = True print(ans)