結果
問題 | No.12 限定された素数 |
ユーザー | vwxyz |
提出日時 | 2021-06-28 21:11:06 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 791 ms / 5,000 ms |
コード長 | 3,024 bytes |
コンパイル時間 | 326 ms |
コンパイル使用メモリ | 86,976 KB |
実行使用メモリ | 180,280 KB |
最終ジャッジ日時 | 2023-09-07 22:13:37 |
合計ジャッジ時間 | 21,218 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 671 ms
180,280 KB |
testcase_01 | AC | 688 ms
177,936 KB |
testcase_02 | AC | 672 ms
173,420 KB |
testcase_03 | AC | 777 ms
165,304 KB |
testcase_04 | AC | 672 ms
178,124 KB |
testcase_05 | AC | 716 ms
175,172 KB |
testcase_06 | AC | 718 ms
173,048 KB |
testcase_07 | AC | 744 ms
166,992 KB |
testcase_08 | AC | 701 ms
172,220 KB |
testcase_09 | AC | 689 ms
176,696 KB |
testcase_10 | AC | 712 ms
172,104 KB |
testcase_11 | AC | 791 ms
165,240 KB |
testcase_12 | AC | 740 ms
167,144 KB |
testcase_13 | AC | 704 ms
171,644 KB |
testcase_14 | AC | 704 ms
174,820 KB |
testcase_15 | AC | 717 ms
171,464 KB |
testcase_16 | AC | 791 ms
167,368 KB |
testcase_17 | AC | 671 ms
179,904 KB |
testcase_18 | AC | 668 ms
177,112 KB |
testcase_19 | AC | 682 ms
176,736 KB |
testcase_20 | AC | 664 ms
177,104 KB |
testcase_21 | AC | 683 ms
177,420 KB |
testcase_22 | AC | 666 ms
173,884 KB |
testcase_23 | AC | 672 ms
173,880 KB |
testcase_24 | AC | 670 ms
179,592 KB |
testcase_25 | AC | 717 ms
172,272 KB |
ソースコード
import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys from collections import Counter, deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as GCD read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines class Prime: def __init__(self,N): self.smallest_prime_factor=[None]*(N+1) for i in range(2,N+1,2): self.smallest_prime_factor[i]=2 n=int(N**.5)+1 for p in range(3,n,2): if self.smallest_prime_factor[p]==None: self.smallest_prime_factor[p]=p for i in range(p**2,N+1,2*p): if self.smallest_prime_factor[i]==None: self.smallest_prime_factor[i]=p for p in range(n,N+1): if self.smallest_prime_factor[p]==None: self.smallest_prime_factor[p]=p self.primes=[p for p in range(N+1) if p==self.smallest_prime_factor[p]] def Factorize(self,N): assert N>=1 factorize=defaultdict(int) if N<=len(self.smallest_prime_factor)-1: while N!=1: factorize[self.smallest_prime_factor[N]]+=1 N//=self.smallest_prime_factor[N] else: for p in self.primes: while N%p==0: N//=p factorize[p]+=1 if N<p*p: if N!=1: factorize[N]+=1 break if N<=len(self.smallest_prime_factor)-1: while N!=1: factorize[self.smallest_prime_factor[N]]+=1 N//=self.smallest_prime_factor[N] break else: if N!=1: factorize[N]+=1 return factorize def Divisors(self,N): assert N>0 divisors=[1] for p,e in self.Factorize(N).items(): A=[1] for _ in range(e): A.append(A[-1]*p) divisors=[i*j for i in divisors for j in A] N=int(readline()) A=set(readline().split()) P=Prime(5*10**6) lst_lst=[[]] num_lst=[0] for p in P.primes: S=str(p) for s in S: if not s in A: num_lst.append(p) lst_lst.append([]) break else: lst_lst[-1].append(p) num_lst.append(5*10**6+1) ans=-float('inf') for i in range(len(lst_lst)): se=set() for p in lst_lst[i]: S=str(p) for s in S: se.add(s) if A==se: ans=max(ans,num_lst[i+1]-num_lst[i]-2) if ans==-float('inf'): ans=-1 print(ans)