結果

問題 No.2081 Make a Test Case of GCD Subset
ユーザー tentententen
提出日時 2023-02-09 16:19:12
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,912 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 88,124 KB
実行使用メモリ 52,196 KB
最終ジャッジ日時 2023-09-21 00:13:20
合計ジャッジ時間 9,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
51,356 KB
testcase_01 AC 58 ms
51,284 KB
testcase_02 AC 61 ms
51,116 KB
testcase_03 AC 72 ms
51,620 KB
testcase_04 AC 61 ms
51,208 KB
testcase_05 AC 58 ms
51,384 KB
testcase_06 AC 60 ms
51,652 KB
testcase_07 AC 61 ms
51,228 KB
testcase_08 AC 59 ms
51,444 KB
testcase_09 AC 58 ms
51,216 KB
testcase_10 AC 59 ms
51,548 KB
testcase_11 AC 58 ms
51,276 KB
testcase_12 AC 63 ms
52,196 KB
testcase_13 AC 63 ms
51,220 KB
testcase_14 AC 66 ms
52,004 KB
testcase_15 AC 59 ms
51,320 KB
testcase_16 AC 60 ms
51,320 KB
testcase_17 AC 63 ms
51,852 KB
testcase_18 AC 56 ms
51,132 KB
testcase_19 AC 59 ms
51,372 KB
testcase_20 AC 62 ms
50,200 KB
testcase_21 AC 58 ms
51,448 KB
testcase_22 AC 58 ms
51,700 KB
testcase_23 WA -
testcase_24 AC 56 ms
51,108 KB
testcase_25 AC 59 ms
51,868 KB
testcase_26 AC 56 ms
51,652 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        if (n == 0) {
            n = 998244353;
        }
        boolean[] isNotPrimes = new boolean[100000];
        ArrayDeque<Integer> primes = new ArrayDeque<>();
        for (int i = 2; i < isNotPrimes.length; i++) {
            if (!isNotPrimes[i]) {
                primes.add(i);
                for (int j = 2; j * i < isNotPrimes.length; j++) {
                    isNotPrimes[j * i] = true;
                }
            }
        }
        ArrayList<Integer> idxes = new ArrayList<>();
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            if ((n & (1 << i)) > 0) {
                idxes.add(i);
                ans.add(primes.pollLast());
            }
        }
        ArrayList<Integer> values = new ArrayList<>();
        for (int i = 0; i < idxes.size(); i++) {
            values.add(primes.pollFirst());
        }
        for (int i = idxes.size() - 1; i >= 0; i--) {
            int x = idxes.get(i);
            int y = values.get(i);
            if (x > 0) {
                ans.add(y);
            }
            for (int j = 1; j < x; j++) {
                ans.add(y * primes.poll());
            }
        }
        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);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0