結果

問題 No.12 限定された素数
ユーザー gigurururugigurururu
提出日時 2014-11-27 18:34:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,629 ms / 5,000 ms
コード長 446 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 11,536 KB
実行使用メモリ 74,520 KB
最終ジャッジ日時 2023-08-15 22:28:44
合計ジャッジ時間 40,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,296 ms
74,436 KB
testcase_01 AC 1,445 ms
74,368 KB
testcase_02 AC 1,349 ms
74,296 KB
testcase_03 AC 1,443 ms
74,492 KB
testcase_04 AC 1,370 ms
74,336 KB
testcase_05 AC 1,561 ms
74,440 KB
testcase_06 AC 1,568 ms
74,436 KB
testcase_07 AC 1,582 ms
74,272 KB
testcase_08 AC 1,524 ms
74,200 KB
testcase_09 AC 1,453 ms
74,332 KB
testcase_10 AC 1,555 ms
74,356 KB
testcase_11 AC 1,524 ms
74,240 KB
testcase_12 AC 1,584 ms
74,500 KB
testcase_13 AC 1,546 ms
74,512 KB
testcase_14 AC 1,472 ms
74,340 KB
testcase_15 AC 1,510 ms
74,192 KB
testcase_16 AC 1,629 ms
74,520 KB
testcase_17 AC 1,300 ms
74,204 KB
testcase_18 AC 1,294 ms
74,356 KB
testcase_19 AC 1,263 ms
74,292 KB
testcase_20 AC 1,448 ms
74,400 KB
testcase_21 AC 1,487 ms
74,360 KB
testcase_22 AC 1,285 ms
74,292 KB
testcase_23 AC 1,301 ms
74,200 KB
testcase_24 AC 1,291 ms
74,440 KB
testcase_25 AC 1,532 ms
74,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def prime(max)
m=max
s=[1]*x=(m-3)/2
(0..(m**0.5-3)/2).each{|i|s[i]&&(k=i+i+3;j=k*(i+1)+i;(s[j]=nil;j+=k)until j>x)}
[2]+(0...x).map{|i|s[i]&&i+i+3}.compact
end

gets
a=gets.split

max=5000000
start=1
rest=a.dup
ans=-1
prime(max).each{|i|
  l=i.to_s.chars
  if (l-a)[0]
    ans=i-1-start if rest==[] && ans<i-1-start
    start=i+1
    rest=a.dup
  else
    rest-=l
  end
}
ans=max-start if rest==[] && ans<max-start
p ans
0