結果

問題 No.589 Counting Even
ユーザー GrenacheGrenache
提出日時 2017-11-04 13:48:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 3,123 ms
コンパイル使用メモリ 74,680 KB
実行使用メモリ 41,756 KB
最終ジャッジ日時 2024-05-02 22:42:16
合計ジャッジ時間 7,417 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
41,380 KB
testcase_01 AC 124 ms
41,268 KB
testcase_02 AC 124 ms
41,176 KB
testcase_03 AC 103 ms
41,364 KB
testcase_04 AC 113 ms
41,472 KB
testcase_05 AC 113 ms
41,212 KB
testcase_06 AC 105 ms
41,296 KB
testcase_07 AC 104 ms
41,424 KB
testcase_08 AC 112 ms
41,348 KB
testcase_09 AC 104 ms
41,432 KB
testcase_10 AC 107 ms
40,016 KB
testcase_11 AC 115 ms
41,292 KB
testcase_12 AC 99 ms
41,484 KB
testcase_13 AC 110 ms
40,064 KB
testcase_14 AC 116 ms
41,324 KB
testcase_15 AC 117 ms
41,260 KB
testcase_16 AC 104 ms
41,420 KB
testcase_17 AC 112 ms
41,560 KB
testcase_18 AC 104 ms
41,312 KB
testcase_19 AC 115 ms
41,320 KB
testcase_20 AC 111 ms
41,388 KB
testcase_21 AC 99 ms
41,752 KB
testcase_22 AC 121 ms
41,364 KB
testcase_23 AC 104 ms
41,456 KB
testcase_24 AC 104 ms
41,440 KB
testcase_25 AC 117 ms
41,756 KB
testcase_26 AC 112 ms
41,612 KB
testcase_27 AC 115 ms
41,300 KB
testcase_28 AC 102 ms
41,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder589_1 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long n = sc.nextLong();

		pr.println(n + 1 - cntOdd(n));
	}

	private static long cntOdd(long n) {
		if (n == 0) {
			return 1;
		} else if (n == 1) {
			return 2;
		}

		long tmp = 2;
		while (n >= tmp * 2) {
			tmp *= 2;
		}

		return 2 * cntOdd(n - tmp);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0