結果

問題 No.889 素数!
コンテスト
ユーザー gemmaro
提出日時 2019-10-30 16:43:38
言語 Ruby
(4.0.6 + ACL)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 52 ms / 2,000 ms
+ 307µs
コード長 766 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 29 ms
コンパイル使用メモリ 8,832 KB
実行使用メモリ 14,592 KB
最終ジャッジ日時 2026-08-27 11:52:06
合計ジャッジ時間 6,002 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

$primes = (2...64).to_a.filter {|i|
    j = Math.sqrt(i).floor
    flag = true
    (2..j).each {|k|
        if i % k == 0
            flag = false
        end
    }
    flag
}

$squares = (2...64).to_a.filter {|i|
    i * i <= 64 - 1
}.map{|i| i * i }

$cubes = (2...64).to_a.filter {|i|
    i * i * i <= 64 - 1
}.map{|i| i * i * i }

$perfects = [6, 28]

n = gets.chomp.to_i

def is_prime(n)
    $primes.include?(n)
end

def is_sq(n)
    $squares.include?(n)
end

def is_cube(n)
    $cubes.include?(n)
end

def is_perfect(n)
    $perfects.include?(n)
end

response = if is_prime(n) then "Sosu!"
           elsif is_sq(n) then "Heihosu!"
           elsif is_cube(n) then "Ripposu!"
           elsif is_perfect(n) then "Kanzensu!"
           else n end

puts response
0