結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 90 ms
12,288 KB
testcase_03 AC 89 ms
12,288 KB
testcase_04 AC 91 ms
12,160 KB
testcase_05 AC 90 ms
12,160 KB
testcase_06 AC 88 ms
12,288 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 89 ms
12,160 KB
testcase_11 AC 89 ms
12,160 KB
testcase_12 AC 90 ms
12,160 KB
testcase_13 AC 90 ms
12,288 KB
testcase_14 AC 91 ms
12,160 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 89 ms
12,288 KB
testcase_18 AC 90 ms
12,160 KB
testcase_19 AC 90 ms
12,160 KB
testcase_20 AC 89 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)) ==  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