結果

問題 No.6 使いものにならないハッシュ
ユーザー takakintakakin
提出日時 2020-04-23 21:40:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 80 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 10,884 KB
最終ジャッジ日時 2023-10-14 23:23:13
合計ジャッジ時間 2,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,504 KB
testcase_01 AC 16 ms
8,484 KB
testcase_02 AC 80 ms
10,884 KB
testcase_03 AC 26 ms
8,732 KB
testcase_04 AC 32 ms
9,180 KB
testcase_05 AC 35 ms
9,088 KB
testcase_06 AC 52 ms
9,956 KB
testcase_07 AC 41 ms
9,800 KB
testcase_08 AC 49 ms
9,956 KB
testcase_09 AC 48 ms
10,764 KB
testcase_10 AC 15 ms
8,376 KB
testcase_11 AC 27 ms
8,604 KB
testcase_12 AC 59 ms
9,748 KB
testcase_13 AC 39 ms
10,664 KB
testcase_14 AC 42 ms
10,608 KB
testcase_15 AC 50 ms
9,708 KB
testcase_16 AC 48 ms
10,580 KB
testcase_17 AC 66 ms
10,788 KB
testcase_18 AC 78 ms
10,812 KB
testcase_19 AC 65 ms
10,500 KB
testcase_20 AC 58 ms
10,136 KB
testcase_21 AC 21 ms
8,708 KB
testcase_22 AC 62 ms
10,660 KB
testcase_23 AC 58 ms
10,148 KB
testcase_24 AC 61 ms
10,292 KB
testcase_25 AC 43 ms
9,812 KB
testcase_26 AC 69 ms
10,672 KB
testcase_27 AC 57 ms
10,608 KB
testcase_28 AC 42 ms
9,440 KB
testcase_29 AC 71 ms
10,496 KB
testcase_30 AC 65 ms
10,148 KB
testcase_31 AC 60 ms
10,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
k=int(input())
n=int(input())
import bisect
def primes(n):
  is_prime=[True]*(n+1)
  is_prime[0]=False
  is_prime[1]=False
  for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:
      continue
    for j in range(i*2,n+1,i):
      is_prime[j]=False
  return [i for i in range(n+1) if is_prime[i]]
P=primes(n)

def f(x):
  if len(str(x))==1:
    return x
  else:
    ret=x%10+f(x//10)
    if ret>=10:
      return ret%10+1
    else:
      return ret

kk=bisect.bisect_left(P,k)
nn=len(P)
C=[kk-1]*10
lr=0
l=kk-1
for i in range(kk,nn):
  p=P[i]
  pp=f(p)
  if i-max(l,C[pp])>=lr:
    ans=P[max(l,C[pp])+1]
    lr=i-max(l,C[pp])
  l=max(l,C[pp])
  C[pp]=i
print(ans)
0