結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー maimai
提出日時 2018-05-20 11:27:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 165 ms / 1,000 ms
コード長 966 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 11,312 KB
実行使用メモリ 15,592 KB
最終ジャッジ日時 2023-09-10 23:56:43
合計ジャッジ時間 6,300 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
15,284 KB
testcase_01 AC 92 ms
15,204 KB
testcase_02 AC 91 ms
15,284 KB
testcase_03 AC 91 ms
15,524 KB
testcase_04 AC 92 ms
15,196 KB
testcase_05 AC 89 ms
15,248 KB
testcase_06 AC 90 ms
15,128 KB
testcase_07 AC 94 ms
15,212 KB
testcase_08 AC 91 ms
15,132 KB
testcase_09 AC 93 ms
15,332 KB
testcase_10 AC 96 ms
15,240 KB
testcase_11 AC 91 ms
15,212 KB
testcase_12 AC 92 ms
15,200 KB
testcase_13 AC 91 ms
15,180 KB
testcase_14 AC 91 ms
15,592 KB
testcase_15 AC 92 ms
15,132 KB
testcase_16 AC 92 ms
15,224 KB
testcase_17 AC 92 ms
15,388 KB
testcase_18 AC 91 ms
15,240 KB
testcase_19 AC 91 ms
15,324 KB
testcase_20 AC 93 ms
15,216 KB
testcase_21 AC 91 ms
15,204 KB
testcase_22 AC 92 ms
15,108 KB
testcase_23 AC 92 ms
15,128 KB
testcase_24 AC 98 ms
15,196 KB
testcase_25 AC 105 ms
15,212 KB
testcase_26 AC 165 ms
15,408 KB
testcase_27 AC 98 ms
15,376 KB
testcase_28 AC 102 ms
15,132 KB
testcase_29 AC 97 ms
15,276 KB
testcase_30 AC 101 ms
15,276 KB
testcase_31 AC 97 ms
15,124 KB
testcase_32 AC 98 ms
15,200 KB
testcase_33 AC 95 ms
15,356 KB
testcase_34 AC 97 ms
15,384 KB
testcase_35 AC 97 ms
15,104 KB
testcase_36 AC 95 ms
15,116 KB
testcase_37 AC 101 ms
15,288 KB
testcase_38 AC 97 ms
15,144 KB
testcase_39 AC 111 ms
15,160 KB
testcase_40 AC 109 ms
15,304 KB
testcase_41 AC 106 ms
15,244 KB
testcase_42 AC 105 ms
15,268 KB
testcase_43 AC 98 ms
15,224 KB
testcase_44 AC 121 ms
15,400 KB
testcase_45 AC 90 ms
15,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_i);end

require 'prime'

def my_unko_algorithm(n)
    return 2 if n.even?
    1.upto(n) do |i|
        f = i*2+1
        return f if n%f == 0
    end
    throw "hoge"
end

L, H = ascan
sqrtH = Math.sqrt(H).to_i
ans = [0,0]

sqrtH.downto(2) do |x|
    # この枝刈りの計算量が分からん(素数の間隔を使う?)
    break if ans[0] > x
    
    next unless x.prime? ## 篩を使えばこの計算量をループの外に出せる
    y = H / x
    
    ## niceな実装なら計算量O(素数の個数(sqrt(N)))
    #yfact =  y.prime_division.map(&:shift).min
    #yfact = my_unko_algorithm(y)
    
    y.downto(2) do |y2|
        break if x*y2 < L
        
        # この枝刈りの計算量が分からん(素数の間隔を使う?)
        break if ans[0] > y2
        
        y2fact = my_unko_algorithm(y2)
        
        curr = [ [x,y2fact].min, x*y2 ]
        ans = [curr, ans].max
    end
    
end

p ans[1]
0