結果

問題 No.12 限定された素数
ユーザー mkawa2mkawa2
提出日時 2020-01-02 10:11:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,379 ms / 5,000 ms
コード長 1,597 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 69,096 KB
最終ジャッジ日時 2023-08-16 01:06:24
合計ジャッジ時間 40,753 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,334 ms
69,004 KB
testcase_01 AC 1,379 ms
68,984 KB
testcase_02 AC 1,365 ms
69,056 KB
testcase_03 AC 1,332 ms
68,868 KB
testcase_04 AC 1,372 ms
69,032 KB
testcase_05 AC 1,337 ms
68,872 KB
testcase_06 AC 1,343 ms
69,008 KB
testcase_07 AC 1,350 ms
68,876 KB
testcase_08 AC 1,339 ms
69,004 KB
testcase_09 AC 1,342 ms
68,944 KB
testcase_10 AC 1,326 ms
69,024 KB
testcase_11 AC 1,338 ms
68,980 KB
testcase_12 AC 1,345 ms
68,868 KB
testcase_13 AC 1,337 ms
68,980 KB
testcase_14 AC 1,334 ms
68,992 KB
testcase_15 AC 1,328 ms
68,988 KB
testcase_16 AC 1,342 ms
68,864 KB
testcase_17 AC 1,327 ms
68,956 KB
testcase_18 AC 1,340 ms
69,012 KB
testcase_19 AC 1,343 ms
69,008 KB
testcase_20 AC 1,371 ms
68,972 KB
testcase_21 AC 1,341 ms
68,960 KB
testcase_22 AC 1,339 ms
69,096 KB
testcase_23 AC 1,351 ms
69,016 KB
testcase_24 AC 1,334 ms
68,992 KB
testcase_25 AC 1,349 ms
69,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import *
from bisect import *
from math import *
from collections import *
from heapq import *
from random import *
from decimal import *
import numpy as np
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def MF(): return map(float, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LF(): return list(map(float, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    def xtobit(x):
        res=0
        for c in str(x):
            res|=1<<int(c)
        return res

    n=II()
    aa=LI()
    a=sum(1<<ak for ak in aa)
    #print(format(a,'b'))

    prime=[0,1]*2500005
    prime[1]=0
    prime[2]=1
    #pp=[]
    l=1
    s=0
    ans=-1
    for x in range(1,5000001):
        #if x**2>5000000:break
        if prime[x]:
            bit=xtobit(x)
            if bit|a!=a:
                if s==a:
                    ans=max(ans,x-l-1)
                    #print(l,x,x-l-1,ans)
                l=x+1
                s=0
            else:
                s|=bit
            #pp.append(x)
            if x==2:continue
            for y in range(x**2,5000001,x*2):
                prime[y]=0
    if s==a:
        ans=max(ans,5000000-l)
    print(ans)

main()
0