結果

問題 No.1058 素敵な数
ユーザー htensaihtensai
提出日時 2020-05-26 11:52:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 2,383 ms
コンパイル使用メモリ 76,336 KB
実行使用メモリ 41,464 KB
最終ジャッジ日時 2024-04-21 04:13:12
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
41,392 KB
testcase_01 AC 113 ms
40,844 KB
testcase_02 AC 117 ms
41,140 KB
testcase_03 AC 119 ms
41,072 KB
testcase_04 AC 130 ms
41,464 KB
testcase_05 AC 121 ms
41,384 KB
testcase_06 AC 122 ms
40,832 KB
testcase_07 AC 115 ms
39,840 KB
testcase_08 AC 116 ms
40,308 KB
testcase_09 AC 121 ms
41,140 KB
権限があれば一括ダウンロードができます

ソースコード

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);
		    }
		}
		TreeSet<Long> set = new TreeSet<>();
		for (int x : primes) {
		    for (int y : primes) {
		        set.add((long)x * y);
		    }
		}
		for (long x : set) {
		    n--;
		    if (n == 1) {
		        System.out.println(x);
		        return;
		    }
		}
	}
	
	static boolean isPrime(int x) {
	    for (int i = 2; i <= Math.sqrt(x); i++) {
	        if (x % i == 0) {
	            return false;
	        }
	    }
	    return true;
	}
}
0