import sequtils,strutils,strscans,algorithm,math,future,sets,queues,tables,macros macro unpack*(rhs: seq,cnt: static[int]): auto = let t = genSym(); result = quote do:(let `t` = `rhs`;()) for i in 0.. 9: result = hash(result) let K = get().parseInt N = get().parseInt primes = getPrimes(N,start=K) if false: # 愚直な実装 var L = 0 hashes : set[int8] = {} ans = (prime:0, card:0) for p in primes: let h = hash(p) if h in hashes: while h in hashes: hashes -= hash(primes[L]) L += 1 hashes += h if hashes.card >= ans.card: ans.prime = primes[L] ans.card = hashes.card echo ans.prime else: # 最適化 # hash は 0,3,6,9にならない (3は一度だけ) => 124578の6が最大だが、大きい方を優先するので大きい方から回す if K <= 3: if N <= 3:# 12 13 23 if K == 1: echo N else: echo 3 else: if N < 11: echo 2 else: echo 3 quit() var L = 0 hashes : set[int8] = {} ans = (prime:0, card:0) let primeHashReverseds = primes.mapIt(it.hash()).reversed() for i,h in primeHashReverseds: if h in hashes: while h in hashes: hashes -= primeHashReverseds[L] #hash(primes[R]) L += 1 hashes += h if hashes.card >= ans.card: ans.prime = primes[^(i+1)] ans.card = hashes.card if ans.card == 6: break echo ans.prime