結果

問題 No.638 Sum of "not power of 2"
ユーザー tentententen
提出日時 2020-09-05 11:25:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 511 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 74,824 KB
実行使用メモリ 57,316 KB
最終ジャッジ日時 2023-08-18 17:20:37
合計ジャッジ時間 4,891 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
55,912 KB
testcase_01 AC 108 ms
56,460 KB
testcase_02 AC 109 ms
55,660 KB
testcase_03 AC 107 ms
55,684 KB
testcase_04 AC 127 ms
56,944 KB
testcase_05 AC 111 ms
56,144 KB
testcase_06 AC 131 ms
56,864 KB
testcase_07 AC 140 ms
56,800 KB
testcase_08 AC 134 ms
56,644 KB
testcase_09 AC 134 ms
57,316 KB
testcase_10 AC 136 ms
57,268 KB
testcase_11 AC 132 ms
56,508 KB
testcase_12 AC 106 ms
56,196 KB
testcase_13 AC 134 ms
56,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long n = sc.nextLong();
    	long base = 1;
    	HashSet<Long> ng = new HashSet<>();
    	while (base <= n) {
    	    ng.add(base);
    	    base *= 2;
    	}
    	for (long i = 1; i <= n / 2; i++) {
    	    if (!ng.contains(i) && !ng.contains(n - i)) {
    	        System.out.println(i + " " + (n - i));
    	        return;
    	    }
    	}
    	System.out.println(-1);
	}
}
0