結果

問題 No.1058 素敵な数
ユーザー tentententen
提出日時 2022-08-04 14:00:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,751 bytes
コンパイル時間 5,273 ms
コンパイル使用メモリ 75,528 KB
実行使用メモリ 51,216 KB
最終ジャッジ日時 2023-10-12 11:28:44
合計ジャッジ時間 3,851 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,280 KB
testcase_01 AC 53 ms
51,088 KB
testcase_02 AC 52 ms
50,376 KB
testcase_03 AC 54 ms
50,868 KB
testcase_04 AC 55 ms
51,216 KB
testcase_05 AC 53 ms
51,152 KB
testcase_06 AC 53 ms
50,844 KB
testcase_07 AC 52 ms
50,972 KB
testcase_08 AC 54 ms
48,760 KB
testcase_09 AC 53 ms
50,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println(1);
            return;
        }
        n--;
        boolean[] isNotPrimes = new boolean[110000];
        for (int i = 2; i <= 100000; i++) {
            if (!isNotPrimes[i]) {
                for (int j = 2; j * i < 110000; j++) {
                    isNotPrimes[j * i] = true;
                }
            }
        }
        ArrayList<Long> primes = new ArrayList<>();
        for (int i = 100000; i < 100100; i++) {
            if (!isNotPrimes[i]) {
                primes.add((long)i);
            }
        }
        TreeSet<Long> ans = new TreeSet<>();
        for (long x : primes) {
            for (long y : primes) {
                ans.add(x * y);
            }
        }
        for (int i = 0; i < n - 1; i++) {
            ans.pollFirst();
        }
        System.out.println(ans.pollFirst());
    }
}

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 {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0