結果
問題 | No.638 Sum of "not power of 2" |
ユーザー | denderaKawazu |
提出日時 | 2018-02-13 19:11:46 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 160 ms / 1,000 ms |
コード長 | 1,325 bytes |
コンパイル時間 | 2,509 ms |
コンパイル使用メモリ | 83,708 KB |
実行使用メモリ | 55,240 KB |
最終ジャッジ日時 | 2024-05-07 13:10:17 |
合計ジャッジ時間 | 5,172 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 115 ms
52,828 KB |
testcase_01 | AC | 124 ms
54,152 KB |
testcase_02 | AC | 126 ms
54,140 KB |
testcase_03 | AC | 130 ms
54,084 KB |
testcase_04 | AC | 150 ms
54,984 KB |
testcase_05 | AC | 126 ms
54,132 KB |
testcase_06 | AC | 160 ms
55,188 KB |
testcase_07 | AC | 136 ms
54,508 KB |
testcase_08 | AC | 152 ms
55,156 KB |
testcase_09 | AC | 153 ms
55,240 KB |
testcase_10 | AC | 153 ms
55,084 KB |
testcase_11 | AC | 156 ms
55,128 KB |
testcase_12 | AC | 129 ms
54,224 KB |
testcase_13 | AC | 149 ms
55,000 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashSet; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); solver.solve(1, in, out); out.close(); } static class Task { static HashSet<Long> twoPow = new HashSet<>(); static void setTwoPow(long max) { long n = 1; while (n < max) { twoPow.add(n); n *= 2; } } public void solve(int testNumber, Scanner in, PrintWriter out) { long n = in.nextLong(); setTwoPow(n); long a = 1; long b = n - a; while (a < n && twoPow.contains(a) || twoPow.contains(b)) { a++; b--; } if (a >= n) { out.println(-1); } else { out.println(a + " " + b); } } } }