結果

問題 No.1058 素敵な数
ユーザー tentententen
提出日時 2020-09-28 14:28:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 75,116 KB
実行使用メモリ 55,592 KB
最終ジャッジ日時 2024-07-02 01:36:23
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		TreeSet<Integer> primes = new TreeSet<>();
		int num = 100001;
		while (primes.size() < 10) {
		    if (isPrime(num)) {
		        primes.add(num);
		    }
		    num += 2;
		}
		TreeSet<Long> ans = new TreeSet<>();
		ans.add(1L);
		for (int x : primes) {
		    for (int y : primes) {
		        ans.add((long)x * y);
		    }
		}
		int idx = 1;
		for (long x : ans) {
		    if (idx == n) {
		        System.out.println(x);
		        return;
		    }
		    idx++;
		}
	}
	
	static boolean isPrime(int x) {
	    for (int i = 2; i <= Math.sqrt(x); i++) {
	        if (x % i == 0) {
	            return false;
	        }
	    }
	    return true;
	}
}
0