結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー syusyu
提出日時 2020-08-26 11:39:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 693 bytes
コンパイル時間 2,204 ms
コンパイル使用メモリ 73,752 KB
実行使用メモリ 41,468 KB
最終ジャッジ日時 2024-04-24 17:48:45
合計ジャッジ時間 6,052 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
41,328 KB
testcase_01 AC 113 ms
41,096 KB
testcase_02 AC 99 ms
40,096 KB
testcase_03 AC 106 ms
40,908 KB
testcase_04 AC 112 ms
41,084 KB
testcase_05 AC 101 ms
40,184 KB
testcase_06 AC 107 ms
40,824 KB
testcase_07 AC 111 ms
41,228 KB
testcase_08 AC 109 ms
41,256 KB
testcase_09 AC 101 ms
40,072 KB
testcase_10 AC 112 ms
40,968 KB
testcase_11 AC 113 ms
41,468 KB
testcase_12 AC 102 ms
40,160 KB
testcase_13 AC 111 ms
41,164 KB
testcase_14 AC 104 ms
40,192 KB
testcase_15 AC 107 ms
40,876 KB
testcase_16 AC 113 ms
41,316 KB
testcase_17 AC 103 ms
39,756 KB
testcase_18 AC 107 ms
40,092 KB
testcase_19 AC 109 ms
41,144 KB
testcase_20 AC 99 ms
40,048 KB
testcase_21 AC 115 ms
40,332 KB
testcase_22 AC 114 ms
40,512 KB
testcase_23 AC 106 ms
40,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int count=0;
        
        
        //nが2の累乗かどうかで判定(trueで2の累乗、falseなら違う)
        boolean checkNum=true;
        int num=n;
        while(num>1){
            if(num%2==1){
                checkNum=false;
                break;
            }
            num/=2;
        }

        while(n>1){
            n/=2;
            count++;
        }
        
        if(checkNum){
             System.out.println(count);
        }else{
             System.out.println(count+1);
        }

    }
}
0