結果
問題 | No.420 mod2漸化式 |
ユーザー |
|
提出日時 | 2016-11-18 02:10:00 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 83 ms / 1,000 ms |
コード長 | 564 bytes |
コンパイル時間 | 422 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-12-24 13:05:53 |
合計ジャッジ時間 | 4,096 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 35 |
コンパイルメッセージ
Main.rb:26: warning: `-' after local variable or literal is interpreted as binary operator Main.rb:26: warning: even though it seems like unary operator Syntax OK
ソースコード
class Integerdef factorialreturn 1 if self == 0(1..self).inject(:*)enddef permutation(k)self.factorial/(self-k).factorialenddef combination(k)self.factorial/((self-k).factorial*k.factorial)endendx = gets.to_idef cal(x)if x == 0puts "#{1} #{0}"returnelsif x > 31puts "#{0} #{0}"returnendn = 31.combination(x)sum = (2**31 -1) * 30.combination(x-1)puts "#{n} #{sum}"endcal(x)