結果

問題 No.36 素数が嫌い!
ユーザー rn4ru
提出日時 2016-04-13 03:50:40
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 734 bytes
コンパイル時間 1,758 ms
コンパイル使用メモリ 74,456 KB
実行使用メモリ 58,476 KB
最終ジャッジ日時 2024-10-04 06:52:43
合計ジャッジ時間 7,079 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		BigInteger N = new BigInteger(scanner.next());

		if (isPrime(N)) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}

	}

	private static boolean isPrime(BigInteger n) {
		if (n.equals(BigInteger.ONE)) {
			return true;
		}

		BigInteger two = new BigInteger("2");
		if (n.mod(two).equals(BigInteger.ZERO)) {
			return false;
		}

		BigInteger three = new BigInteger("3");
		for (BigInteger i = three; i.multiply(i).compareTo(n) < 1; i = i.add(two)) {
			if (n.mod(i).equals(BigInteger.ZERO)) {
				return false;
			}
		}

		return true;
	}

}
0