結果

問題 No.420 mod2漸化式
ユーザー kkkk
提出日時 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

ソースコード

diff #

class Integer
    def factorial
        return 1 if self == 0
        (1..self).inject(:*)
    end

    def permutation(k)
        self.factorial/(self-k).factorial
    end

    def combination(k)
        self.factorial/((self-k).factorial*k.factorial)
    end
end
x = gets.to_i
    def cal(x)
        if x == 0
            puts "#{1} #{0}"
            return
        elsif x > 31
            puts "#{0} #{0}"
            return
        end

        n = 31.combination(x)
        sum = (2**31 -1) * 30.combination(x-1)
        puts "#{n} #{sum}"
    end
    cal(x)
0