結果

問題 No.36 素数が嫌い!
ユーザー rn4rurn4ru
提出日時 2016-04-13 03:50:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 734 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 74,532 KB
実行使用メモリ 58,476 KB
最終ジャッジ日時 2024-04-15 00:28:06
合計ジャッジ時間 8,392 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
54,368 KB
testcase_01 AC 127 ms
53,896 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 158 ms
56,692 KB
testcase_08 AC 113 ms
52,760 KB
testcase_09 AC 128 ms
54,168 KB
testcase_10 AC 127 ms
54,132 KB
testcase_11 AC 370 ms
58,448 KB
testcase_12 AC 619 ms
58,476 KB
testcase_13 WA -
testcase_14 AC 169 ms
56,612 KB
testcase_15 AC 127 ms
53,796 KB
testcase_16 AC 126 ms
53,932 KB
testcase_17 AC 127 ms
54,092 KB
testcase_18 AC 125 ms
53,984 KB
testcase_19 AC 127 ms
54,252 KB
testcase_20 AC 128 ms
53,952 KB
testcase_21 AC 129 ms
54,196 KB
testcase_22 AC 125 ms
54,116 KB
testcase_23 AC 126 ms
54,200 KB
testcase_24 AC 127 ms
54,012 KB
testcase_25 AC 128 ms
54,116 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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