結果

問題 No.36 素数が嫌い!
ユーザー scachescache
提出日時 2014-10-08 01:26:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 353 ms / 5,000 ms
コード長 1,301 bytes
コンパイル時間 3,508 ms
コンパイル使用メモリ 74,816 KB
実行使用メモリ 100,628 KB
最終ジャッジ日時 2023-09-09 07:03:55
合計ジャッジ時間 14,872 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 334 ms
100,344 KB
testcase_01 AC 323 ms
99,732 KB
testcase_02 AC 329 ms
99,992 KB
testcase_03 AC 334 ms
100,184 KB
testcase_04 AC 341 ms
100,600 KB
testcase_05 AC 330 ms
99,952 KB
testcase_06 AC 333 ms
99,912 KB
testcase_07 AC 318 ms
99,948 KB
testcase_08 AC 307 ms
99,936 KB
testcase_09 AC 308 ms
100,052 KB
testcase_10 AC 326 ms
100,012 KB
testcase_11 AC 326 ms
100,096 KB
testcase_12 AC 342 ms
99,972 KB
testcase_13 AC 353 ms
99,932 KB
testcase_14 AC 313 ms
99,920 KB
testcase_15 AC 319 ms
100,180 KB
testcase_16 AC 344 ms
100,400 KB
testcase_17 AC 331 ms
97,752 KB
testcase_18 AC 322 ms
99,876 KB
testcase_19 AC 349 ms
100,348 KB
testcase_20 AC 347 ms
99,812 KB
testcase_21 AC 342 ms
100,628 KB
testcase_22 AC 337 ms
100,100 KB
testcase_23 AC 334 ms
100,492 KB
testcase_24 AC 327 ms
100,340 KB
testcase_25 AC 334 ms
100,208 KB
testcase_26 AC 337 ms
100,060 KB
testcase_27 AC 348 ms
99,996 KB
testcase_28 AC 337 ms
100,216 KB
testcase_29 AC 331 ms
99,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class NotLikePrimeNumber{
	public static void main(String[] args) {
		NotLikePrimeNumber p = new NotLikePrimeNumber();
	}

	public NotLikePrimeNumber(){
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		System.out.println(solve(n));
	}
	
	public String solve(long n) {
		
		// 素数のリストを作る
		// 最低でもsqrt(N)以下の素数を求める
		// ここではエラトステネスのふるいを使っている
		boolean[] hurui = new boolean[10000000+1];
		Arrays.fill(hurui, true);
		hurui[0] = hurui[1] = false;
		ArrayList<Long> primeList = new ArrayList<Long>(); 
		for(int i=2;i<hurui.length;i++){
			if(hurui[i]){
				primeList.add((long)i);
				
				for(int j=i*2;j<hurui.length;j+=i){
					hurui[j] = false;
				}
			}
		}
		
		// 上で求めた素数リストを元に
		// Nを素因数分解
		int count = 0;
		ArrayList<Long> primeFactorList = new ArrayList<Long>();
		for(long prime: primeList){
			while(n%prime == 0){
				n /= prime;
				count++;
				primeFactorList.add(prime);
			}
			
			if(count>=3)
				break;
		}
		
		if(count>=3 || (count==2 && n!=1))
			return "YES";
		else
			return "NO";
		
	}
}
0