結果

問題 No.1058 素敵な数
ユーザー htensaihtensai
提出日時 2020-05-26 11:46:47
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 2,488 ms
コンパイル使用メモリ 77,076 KB
実行使用メモリ 41,740 KB
最終ジャッジ日時 2024-04-21 04:13:08
合計ジャッジ時間 4,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
41,344 KB
testcase_01 AC 129 ms
41,504 KB
testcase_02 AC 131 ms
41,668 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
 	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if (n == 1) {
		    System.out.println(1);
		    return;
		}
		ArrayList<Integer> primes = new ArrayList<>();
		for (int i = 100001; primes.size() < n; i++) {
		    if (isPrime(i)) {
		        primes.add(i);
		    }
		}
		PriorityQueue<Long> queue = new PriorityQueue<>();
		for (int x : primes) {
		    for (int y : primes) {
		        queue.add((long)x * y);
		    }
		}
		for (int i = 0; i < n - 2; i++) {
		    queue.poll();
		}
		System.out.println(queue.poll());
	}
	
	static boolean isPrime(int x) {
	    for (int i = 2; i <= Math.sqrt(x); i++) {
	        if (x % i == 0) {
	            return false;
	        }
	    }
	    return true;
	}
}
0