結果

問題 No.1871 divisXor
ユーザー tentententen
提出日時 2022-03-18 12:50:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,984 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 78,604 KB
実行使用メモリ 51,300 KB
最終ジャッジ日時 2024-04-10 13:43:14
合計ジャッジ時間 6,587 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
50,300 KB
testcase_01 AC 45 ms
50,176 KB
testcase_02 AC 81 ms
51,252 KB
testcase_03 AC 73 ms
51,072 KB
testcase_04 AC 69 ms
51,052 KB
testcase_05 AC 65 ms
51,080 KB
testcase_06 AC 64 ms
51,076 KB
testcase_07 AC 73 ms
51,208 KB
testcase_08 AC 79 ms
51,044 KB
testcase_09 AC 78 ms
51,208 KB
testcase_10 AC 73 ms
51,032 KB
testcase_11 AC 72 ms
51,192 KB
testcase_12 AC 64 ms
51,056 KB
testcase_13 AC 58 ms
51,036 KB
testcase_14 AC 72 ms
51,088 KB
testcase_15 AC 67 ms
51,188 KB
testcase_16 AC 75 ms
51,164 KB
testcase_17 AC 75 ms
51,156 KB
testcase_18 AC 62 ms
51,300 KB
testcase_19 AC 65 ms
51,152 KB
testcase_20 AC 77 ms
51,196 KB
testcase_21 AC 70 ms
51,100 KB
testcase_22 AC 46 ms
50,148 KB
testcase_23 WA -
testcase_24 AC 46 ms
50,232 KB
testcase_25 AC 46 ms
50,144 KB
testcase_26 AC 87 ms
51,176 KB
testcase_27 AC 81 ms
51,064 KB
testcase_28 AC 63 ms
51,116 KB
testcase_29 AC 88 ms
51,056 KB
testcase_30 AC 74 ms
51,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        if (n == 0) {
            System.out.println(-1);
            return;
        }
        ArrayList<Long> ans = new ArrayList<>();
        for (int i = 60; i >= 0 && n >= 4; i--) {
            if (n < (1L << i)) {
                continue;
            }
            long x = (1L << i) + 1;
            while (!isPrime(x)) {
                x += 2;
            }
            ans.add(x);
            n ^= x + 1;
        }
        if (n == 3) {
            ans.add(2L);
        } else if (n == 2) {
            ans.add(2L);
            ans.add(1L);
        } else if (n == 1) {
            ans.add(1L);
        }
        System.out.println(ans.size());
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ans.size(); i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(ans.get(i));
        }
        System.out.println(sb);
    }
    
    static boolean isPrime(long x) {
        for (int i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0