結果
| 問題 |
No.889 素数!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-30 16:43:38 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 2,000 ms |
| コード長 | 766 bytes |
| コンパイル時間 | 251 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-09-14 21:54:20 |
| 合計ジャッジ時間 | 7,311 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
コンパイルメッセージ
Syntax OK
ソースコード
$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