結果

問題 No.2081 Make a Test Case of GCD Subset
ユーザー tenten
提出日時 2022-09-26 14:04:45
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 2,181 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 79,060 KB
実行使用メモリ 44,856 KB
最終ジャッジ日時 2024-12-22 15:28:37
合計ジャッジ時間 7,652 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int m = sc.nextInt();
        if (m == 0) {
            m = MOD;
        }
        boolean[] isNotPrimes = new boolean[100000];
        ArrayDeque<Integer> primes = new ArrayDeque<>();
        for (int i = 2; i < 100000; i++) {
            if (!isNotPrimes[i]) {
                primes.add(i);
                for (int j = 2; j * i < 100000; j++) {
                    isNotPrimes[j * i] = true;
                }
            }
        }
        int[] counts = new int[30];
        int idx = 2;
        for (int i = 1; i < 30; i++) {
            counts[i] = idx - 1;
            idx <<= 1;
        }
        ArrayList<Long> ans = new ArrayList<>();
        for (int i = 29; i >= 1; i--) {
            if (m < counts[i]) {
                continue;
            }
            m -= counts[i];
            long x = primes.pollFirst();
            for (int j = 0; j < i; j++) {
                ans.add(x * primes.pollLast());
            }
        }
        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(ans.size());
        System.out.println(sb);
    }
}
    
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 String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0