結果

問題 No.36 素数が嫌い!
ユーザー ぴろずぴろず
提出日時 2014-12-16 21:45:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 312 ms / 5,000 ms
コード長 1,631 bytes
コンパイル時間 2,058 ms
コンパイル使用メモリ 74,532 KB
実行使用メモリ 82,192 KB
最終ジャッジ日時 2023-09-09 07:06:16
合計ジャッジ時間 9,973 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
67,264 KB
testcase_01 AC 269 ms
75,348 KB
testcase_02 AC 125 ms
55,708 KB
testcase_03 AC 126 ms
56,108 KB
testcase_04 AC 126 ms
55,544 KB
testcase_05 AC 130 ms
55,980 KB
testcase_06 AC 129 ms
55,516 KB
testcase_07 AC 127 ms
55,708 KB
testcase_08 AC 129 ms
55,660 KB
testcase_09 AC 130 ms
55,648 KB
testcase_10 AC 129 ms
56,076 KB
testcase_11 AC 196 ms
65,084 KB
testcase_12 AC 311 ms
80,696 KB
testcase_13 AC 312 ms
80,216 KB
testcase_14 AC 240 ms
71,936 KB
testcase_15 AC 125 ms
55,740 KB
testcase_16 AC 125 ms
53,620 KB
testcase_17 AC 125 ms
55,692 KB
testcase_18 AC 127 ms
55,836 KB
testcase_19 AC 221 ms
66,400 KB
testcase_20 AC 308 ms
78,716 KB
testcase_21 AC 260 ms
75,152 KB
testcase_22 AC 263 ms
77,744 KB
testcase_23 AC 224 ms
67,100 KB
testcase_24 AC 243 ms
68,136 KB
testcase_25 AC 229 ms
67,652 KB
testcase_26 AC 241 ms
71,588 KB
testcase_27 AC 310 ms
82,192 KB
testcase_28 AC 237 ms
71,600 KB
testcase_29 AC 309 ms
79,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no036;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		SeiveOfEratosthenes.init(n+1);
		if (SeiveOfEratosthenes.primeFactor(n).size() >= 3) {
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}

}
class SeiveOfEratosthenes {
	private static long max_number;
	private static int max_number_sieve;
	private static boolean[] is_not_prime;
	private static ArrayList<Integer> prime = new ArrayList<Integer>();
	public static void init(long maxnum) {
		max_number = maxnum;
		max_number_sieve = (int) Math.sqrt(max_number);
		is_not_prime = new boolean[max_number_sieve+1];
		is_not_prime[0] = is_not_prime[1] = true;
		for(int i=2;i*i<=max_number_sieve;i++) {
			if (!is_not_prime[i]) {
				int j = 2;
				while(i*j<=max_number_sieve) {
					is_not_prime[i*j] = true;
					j++;
				}
			}
		}
		for(int i=2;i<=max_number_sieve;i++) {
			if(!is_not_prime[i]) {
				prime.add(i);
			}
		}
	}
	public static boolean isPrime(long n) {
		if (n>max_number) {
			return false;
		}
		if (n<=max_number_sieve) {
			return !is_not_prime[(int) n];
		}else{
			for(int p:prime) {
				if (n%p==0 && n!=p) {
					return false;
				}
			}
			return true;
		}
	}
	public static ArrayList<Long> primeFactor(long n) {
		ArrayList<Long> factor = new ArrayList<Long>();
		for(int p:prime) {
			while(n%p==0) {
				n/=p;
				factor.add((long) p);
			}
		}
		if (n > 1) {
			factor.add(n);
		}
		return factor;
	}
}
0