結果
問題 | No.12 限定された素数 |
ユーザー |
![]() |
提出日時 | 2024-11-07 17:19:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 4,329 ms / 5,000 ms |
コード長 | 888 bytes |
コンパイル時間 | 1,457 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 291,260 KB |
最終ジャッジ日時 | 2024-11-07 17:21:25 |
合計ジャッジ時間 | 117,421 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 26 |
ソースコード
def seachPrimeNum(N):if N < 2:return []max = int(N ** 0.5)seachList = [i for i in range(3, N + 1, 2)]primeNum = [2]while seachList[0] <= max:primeNum.append(seachList[0])tmp = seachList[0]seachList = [i for i in seachList if i % tmp != 0]primeNum.extend(seachList)return primeNumdef conv(x):ret = 0while x:ret |= (1 << x % 10)x //= 10return retPL = seachPrimeNum(5 * 10 ** 6)NP = len(PL)PL.append(5 * 10 ** 6 + 1)l = 1N = int(input())A = list(map(int,input().split()))B = 0for a in A:B |= (1<<a)NB = ((1<<10)-1) ^ Bans = 0tmp = 0for i in range(NP):p = PL[i]if conv(p) & NB:l = p + 1tmp = 0else:tmp |= conv(p)if tmp == B:ans = max(ans,PL[i + 1] - 1 - l)if ans == 0:print(-1)else:print(ans)