結果

問題 No.638 Sum of "not power of 2"
ユーザー denderaKawazu
提出日時 2018-02-13 19:11:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 1,325 bytes
コンパイル時間 2,747 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 55,040 KB
最終ジャッジ日時 2024-11-30 06:05:05
合計ジャッジ時間 5,712 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
            }
        }

    }
}

0