結果

問題 No.589 Counting Even
ユーザー GrenacheGrenache
提出日時 2017-11-04 14:08:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 663 bytes
コンパイル時間 5,733 ms
コンパイル使用メモリ 75,384 KB
実行使用メモリ 41,688 KB
最終ジャッジ日時 2024-05-02 22:42:55
合計ジャッジ時間 9,475 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,168 KB
testcase_01 AC 129 ms
41,080 KB
testcase_02 AC 132 ms
41,108 KB
testcase_03 AC 131 ms
41,176 KB
testcase_04 AC 120 ms
39,980 KB
testcase_05 AC 131 ms
41,308 KB
testcase_06 AC 134 ms
41,196 KB
testcase_07 AC 133 ms
41,280 KB
testcase_08 AC 135 ms
41,384 KB
testcase_09 AC 133 ms
41,688 KB
testcase_10 AC 132 ms
41,044 KB
testcase_11 AC 134 ms
41,620 KB
testcase_12 AC 121 ms
40,356 KB
testcase_13 AC 134 ms
41,200 KB
testcase_14 AC 119 ms
40,192 KB
testcase_15 AC 119 ms
40,028 KB
testcase_16 AC 134 ms
41,256 KB
testcase_17 AC 133 ms
40,984 KB
testcase_18 AC 134 ms
41,272 KB
testcase_19 AC 132 ms
41,392 KB
testcase_20 AC 118 ms
40,112 KB
testcase_21 AC 131 ms
41,152 KB
testcase_22 AC 130 ms
41,280 KB
testcase_23 AC 134 ms
41,084 KB
testcase_24 AC 132 ms
41,360 KB
testcase_25 AC 125 ms
41,140 KB
testcase_26 AC 132 ms
41,660 KB
testcase_27 AC 134 ms
41,292 KB
testcase_28 AC 135 ms
41,268 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;
		}

		return 2 * cntOdd(Long.highestOneBit(n) ^ n);
	}

	// ---------------------------------------------------
	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