結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー sjgq5302sjgq5302
提出日時 2017-07-27 23:24:24
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 602 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-18 08:59:42
合計ジャッジ時間 3,232 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
12,160 KB
testcase_01 AC 90 ms
12,288 KB
testcase_02 AC 85 ms
12,288 KB
testcase_03 AC 87 ms
12,160 KB
testcase_04 AC 83 ms
12,160 KB
testcase_05 AC 89 ms
12,160 KB
testcase_06 AC 89 ms
12,160 KB
testcase_07 AC 80 ms
12,288 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 85 ms
12,160 KB
testcase_11 AC 85 ms
12,288 KB
testcase_12 AC 85 ms
12,288 KB
testcase_13 AC 86 ms
12,160 KB
testcase_14 AC 88 ms
12,160 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 95 ms
12,288 KB
testcase_18 AC 87 ms
12,416 KB
testcase_19 AC 85 ms
12,288 KB
testcase_20 AC 86 ms
12,288 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

biscuit = gets.to_i
n = 0

while 2**n < biscuit do #maxの枚数を超えるまで倍々
    n += 1
end

if 2**n == biscuit then #初期値からピッタリで終わる時
    puts n
elsif (biscuit - 2**(n-1)) == 1 #2の累乗より1多い時
    puts n
elsif (biscuit - 2**(n-1)) ==  2 #2の累乗より2多い時
    puts n + 1
elsif ((biscuit - 2**(n-1)) % 2) == 0 #初期値からmaxの枚数を超えない回数で残りの枚数が偶数の時
    puts n
elsif ((biscuit - 2**(n-1)) % 2) == 1 #初期値からmaxの枚数を超えない回数で残りの枚数が奇数の時
    puts n + 1
end
0