結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー sironekotorosironekotoro
提出日時 2018-12-12 14:22:13
言語 Perl
(5.38.2)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 6,200 KB
実行使用メモリ 6,212 KB
最終ジャッジ日時 2023-10-25 08:24:22
合計ジャッジ時間 1,602 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,212 KB
testcase_01 AC 6 ms
6,212 KB
testcase_02 AC 6 ms
6,212 KB
testcase_03 AC 6 ms
6,212 KB
testcase_04 AC 7 ms
6,212 KB
testcase_05 AC 6 ms
6,212 KB
testcase_06 AC 6 ms
6,212 KB
testcase_07 AC 6 ms
6,212 KB
testcase_08 AC 6 ms
6,212 KB
testcase_09 AC 6 ms
6,212 KB
testcase_10 AC 6 ms
6,212 KB
testcase_11 AC 6 ms
6,212 KB
testcase_12 AC 5 ms
6,212 KB
testcase_13 AC 6 ms
6,212 KB
testcase_14 AC 7 ms
6,212 KB
testcase_15 AC 6 ms
6,212 KB
testcase_16 AC 6 ms
6,212 KB
testcase_17 AC 6 ms
6,212 KB
testcase_18 AC 6 ms
6,212 KB
testcase_19 AC 6 ms
6,212 KB
testcase_20 AC 7 ms
6,212 KB
testcase_21 AC 6 ms
6,208 KB
testcase_22 AC 5 ms
6,212 KB
testcase_23 AC 6 ms
6,212 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

use strict;
use warnings;
use v5.16;

# https://yukicoder.me/problems/89

# 欲しいクッキーの数
my $want = <>;
# my $want = 4;
chomp $want;

# ポケットの中のクッキーの数
my $cookie = 1;

# ポケットを叩いた回数
my $count = 0;

# ループ内でぴったり欲しいクッキーの枚数に
# ならなくとも、最終的に欲しい枚数になれば良い
#
# 1000枚の場合
# 1 2 4 8 16 32 64 128 256 512
# ここまでで9回、残りは488枚
# 1000 - 512 = 488
#
# 残り488枚は 現在の512枚のうち488枚を抜いて
# ポケットで叩く
# ( 512 - x ) + 2x = 1000
# x = 488
#
# 問題で問われているのは「何回叩いたか?」なので
# 最後に何枚を調整で叩いたかは問われていない

while (1) {
    last if ( $want <= $cookie );

    $cookie = $cookie * 2;
    $count++;
}

say $count;
0