結果

問題 No.12 限定された素数
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-09 21:19:46
言語 Python2
(2.7.18)
結果
AC  
実行時間 4,489 ms / 5,000 ms
コード長 1,023 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 6,608 KB
実行使用メモリ 283,532 KB
最終ジャッジ日時 2023-08-15 22:36:48
合計ジャッジ時間 103,978 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,525 ms
283,488 KB
testcase_01 AC 3,668 ms
283,344 KB
testcase_02 AC 3,555 ms
283,424 KB
testcase_03 AC 4,489 ms
283,468 KB
testcase_04 AC 3,659 ms
283,520 KB
testcase_05 AC 3,725 ms
283,408 KB
testcase_06 AC 4,042 ms
283,356 KB
testcase_07 AC 4,072 ms
283,352 KB
testcase_08 AC 3,680 ms
283,436 KB
testcase_09 AC 3,685 ms
283,340 KB
testcase_10 AC 3,632 ms
283,360 KB
testcase_11 AC 4,233 ms
283,468 KB
testcase_12 AC 4,070 ms
283,448 KB
testcase_13 AC 3,935 ms
283,468 KB
testcase_14 AC 3,685 ms
283,532 KB
testcase_15 AC 3,974 ms
283,308 KB
testcase_16 AC 4,041 ms
283,356 KB
testcase_17 AC 3,563 ms
283,352 KB
testcase_18 AC 3,498 ms
283,468 KB
testcase_19 AC 3,509 ms
283,280 KB
testcase_20 AC 3,557 ms
283,420 KB
testcase_21 AC 3,628 ms
283,356 KB
testcase_22 AC 3,547 ms
283,344 KB
testcase_23 AC 3,583 ms
283,424 KB
testcase_24 AC 3,580 ms
283,356 KB
testcase_25 AC 3,751 ms
283,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(raw_input())
A=map(int,raw_input().split())
isPrime=[True for i in range(5000001)]
isPrime[0]=False
isPrime[1]=False
primes=[0]
isOK=[False for i in range(10)]
for a in A:
   isOK[a]=True
for i in range(5000001):
   if isPrime[i]:
      primes.append(i)
      for j in range(i+i,5000001,i):
         isPrime[j]=False
primes.append(5000001)
ans = -1
i = 1
while i < len(primes)-1:
   p=primes[i]
   ok=True
   s= set([])
   #print primes[i]
   while p != 0:
      if isOK[p%10] == False :
         ok=False
         break
      s.add(p%10)
      p/=10
   if ok==False:
      i+=1
      continue
   j = i+1
   while j < len(primes)-1:
      p = primes[j]
      ok2=True
      while p != 0:
         if isOK[p%10] == False:
            ok2=False
            break
         p/=10
      if ok2== False:
         break
      p=primes[j]
      while p != 0:
         s.add(p%10)
         p/=10
      j+=1
   if len(s)==N:
      ans = max(ans, primes[j]-1-(primes[i-1]+1) )
   #print primes[i-1],primes[j]
   i=j+1
print ans
0