結果

問題 No.12 限定された素数
ユーザー letrangerjpletrangerjp
提出日時 2017-05-15 00:30:37
言語 Ruby
(3.2.2)
結果
WA  
実行時間 -
コード長 626 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 46,636 KB
最終ジャッジ日時 2023-10-14 11:03:24
合計ジャッジ時間 73,611 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,687 ms
46,360 KB
testcase_01 AC 2,657 ms
46,636 KB
testcase_02 AC 2,641 ms
46,344 KB
testcase_03 WA -
testcase_04 AC 2,658 ms
46,324 KB
testcase_05 AC 2,635 ms
46,552 KB
testcase_06 AC 2,642 ms
46,344 KB
testcase_07 AC 2,665 ms
46,460 KB
testcase_08 AC 2,654 ms
46,568 KB
testcase_09 AC 2,640 ms
46,472 KB
testcase_10 AC 2,625 ms
46,276 KB
testcase_11 AC 2,631 ms
46,600 KB
testcase_12 AC 2,638 ms
46,324 KB
testcase_13 AC 2,636 ms
46,368 KB
testcase_14 AC 2,668 ms
46,332 KB
testcase_15 AC 2,638 ms
46,488 KB
testcase_16 AC 2,723 ms
46,584 KB
testcase_17 AC 2,630 ms
46,344 KB
testcase_18 AC 2,639 ms
46,320 KB
testcase_19 AC 2,631 ms
46,500 KB
testcase_20 AC 2,684 ms
46,524 KB
testcase_21 AC 2,655 ms
46,368 KB
testcase_22 AC 2,644 ms
46,256 KB
testcase_23 AC 2,734 ms
46,268 KB
testcase_24 AC 2,648 ms
46,380 KB
testcase_25 AC 2,627 ms
46,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require "prime"

def a2m(a)
  a.inject(0){|r, n| r | 1<<n}
end

def f(a)
  mask = a2m(a)

  max = -1
  start = 1
  curr_mask = 0
  primes = Prime.each(PRIME_MAX).map{|pr|
    [pr, a2m(pr.to_s.chars.map(&:to_i))]
  }
  primes.size.times{|i|
    pr, pr_mask = primes[i]

    curr_mask |= pr_mask
    if (curr_mask & ~mask) != 0
      start = pr + 1
      curr_mask = 0
    elsif curr_mask == mask
      last = i == primes.size-1 ? PRIME_MAX : primes[i+1][0]
      max = [max, last - start - 1].max
    end
  }
  max
end

PRIME_MAX = 5_000_000
N = gets.to_i
A = gets.split.take(N).map(&:to_i)

puts PRIME_MAX-1 if N == 10
p f(A)
0