結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー springspring
提出日時 2019-06-12 17:07:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 681 bytes
コンパイル時間 1,986 ms
コンパイル使用メモリ 74,312 KB
実行使用メモリ 41,976 KB
最終ジャッジ日時 2024-04-19 08:02:57
合計ジャッジ時間 6,029 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
41,636 KB
testcase_01 AC 126 ms
41,756 KB
testcase_02 AC 127 ms
41,760 KB
testcase_03 AC 114 ms
41,396 KB
testcase_04 AC 127 ms
41,760 KB
testcase_05 AC 132 ms
41,808 KB
testcase_06 AC 129 ms
41,444 KB
testcase_07 AC 128 ms
41,436 KB
testcase_08 AC 128 ms
41,452 KB
testcase_09 AC 127 ms
41,556 KB
testcase_10 AC 124 ms
40,180 KB
testcase_11 AC 116 ms
40,144 KB
testcase_12 AC 127 ms
41,320 KB
testcase_13 AC 123 ms
39,892 KB
testcase_14 AC 127 ms
41,380 KB
testcase_15 AC 128 ms
41,704 KB
testcase_16 AC 128 ms
41,276 KB
testcase_17 AC 115 ms
41,464 KB
testcase_18 AC 130 ms
41,976 KB
testcase_19 AC 131 ms
41,356 KB
testcase_20 AC 127 ms
41,408 KB
testcase_21 AC 130 ms
41,396 KB
testcase_22 AC 128 ms
41,848 KB
testcase_23 AC 125 ms
41,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cookie = sc.nextInt();
		sc.close();
		int count = 0;
		int k = 0;
		int status = 0;
		int pocket = 1;
		while (k < 1) {
			pocket = pocket * 2;
			if (pocket < cookie) {
				count += 1;
				continue;
			} else if (pocket == cookie) {
				count += 1;
				k += 1;
				status = 1;
				break;
			} else {
				pocket = pocket / 2;
				k += 1;
			}
		}
		if (cookie == 1) {
			System.out.println(0);
		} else if (status == 0) {
			System.out.println(count + 1);
		} else if (status == 1) {
			System.out.println(count);
		}

	}// mainmethod

} // class
0