結果
問題 |
No.1871 divisXor
|
ユーザー |
![]() |
提出日時 | 2022-03-18 12:50:42 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,984 bytes |
コンパイル時間 | 3,195 ms |
コンパイル使用メモリ | 78,716 KB |
実行使用メモリ | 50,256 KB |
最終ジャッジ日時 | 2024-10-02 15:47:33 |
合計ジャッジ時間 | 7,343 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 WA * 1 |
ソースコード
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(); } }