結果

問題 No.889 素数!
ユーザー wipexwipex
提出日時 2019-09-21 19:46:54
言語 Ruby
(3.4.1)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 485 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-09-19 03:04:17
合計ジャッジ時間 8,582 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

n = gets.chomp.to_i
sum =0
case n
when 4,9,16,25,36,49
  puts "Heihosu!"
  exit
when 8,27
  puts  "Ripposu!"
  exit
when 0
  puts n
  exit
end

def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1
    }.product(ary).map{ |a, b| a * b }
  end.sort
end

eval = divisors(n)
if eval.length ==2
  puts "Sosu!"
else
  eval.each do |elem|
    sum+=elem if elem < n
  end

  if sum == n
    puts "Kanzensu!"
  else
    puts n
  end
end
0