結果

問題 No.638 Sum of "not power of 2"
ユーザー kusagame12kusagame12
提出日時 2023-11-11 22:05:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 167 ms / 1,000 ms
コード長 885 bytes
コンパイル時間 2,604 ms
コンパイル使用メモリ 76,740 KB
実行使用メモリ 58,728 KB
最終ジャッジ日時 2023-11-11 22:05:35
合計ジャッジ時間 5,148 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
57,988 KB
testcase_01 AC 124 ms
57,832 KB
testcase_02 AC 125 ms
57,700 KB
testcase_03 AC 124 ms
57,828 KB
testcase_04 AC 153 ms
58,724 KB
testcase_05 AC 114 ms
56,684 KB
testcase_06 AC 163 ms
56,880 KB
testcase_07 AC 146 ms
58,724 KB
testcase_08 AC 167 ms
56,664 KB
testcase_09 AC 157 ms
58,564 KB
testcase_10 AC 149 ms
58,600 KB
testcase_11 AC 145 ms
58,600 KB
testcase_12 AC 123 ms
57,820 KB
testcase_13 AC 146 ms
58,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        long n = sc.nextLong();
        
        long ansA = -1;
        long ansB = -1;
        for(long b = n - 2l ; b > 1 ; b--){

            long a = n - b;

            if((b % 2l == 0 && !myJudge(b)) || (a % 2l == 0 && !myJudge(a))){
                continue;
            }
            
            ansA = a;
            ansB = b;
            break;
            
        }
        
        System.out.println(ansA == -1 ? -1 : ansA+" "+ansB);
           
    }
    
    private static boolean myJudge(long num){
        
        for(int i = 1 ; i < 61 ; i++){
            if(num == (long) Math.pow(2 , i)){
                return false;
            }
        }
        return true;
        
    }
    
}








0