結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 208 ms
56,784 KB
testcase_02 AC 130 ms
54,212 KB
testcase_03 AC 127 ms
54,368 KB
testcase_04 AC 129 ms
54,304 KB
testcase_05 AC 162 ms
56,980 KB
testcase_06 AC 173 ms
57,152 KB
testcase_07 AC 163 ms
56,852 KB
testcase_08 AC 131 ms
53,716 KB
testcase_09 WA -
testcase_10 AC 128 ms
54,232 KB
testcase_11 AC 385 ms
58,752 KB
testcase_12 AC 629 ms
58,584 KB
testcase_13 AC 630 ms
58,848 KB
testcase_14 WA -
testcase_15 AC 128 ms
54,236 KB
testcase_16 AC 128 ms
54,348 KB
testcase_17 AC 126 ms
53,988 KB
testcase_18 WA -
testcase_19 AC 127 ms
54,276 KB
testcase_20 AC 228 ms
57,032 KB
testcase_21 AC 130 ms
53,916 KB
testcase_22 AC 130 ms
54,172 KB
testcase_23 AC 130 ms
54,128 KB
testcase_24 AC 313 ms
58,720 KB
testcase_25 AC 128 ms
54,312 KB
testcase_26 AC 486 ms
58,788 KB
testcase_27 AC 634 ms
59,100 KB
testcase_28 AC 483 ms
58,760 KB
testcase_29 AC 696 ms
59,000 KB
権限があれば一括ダウンロードができます

ソースコード

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.equals(two)) {
			return true;
		}

		boolean once = false;
		if (n.mod(two).equals(BigInteger.ZERO)) {
			once = true;
		}

		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)) {
				if (once) {
					return false;
				} else {
					once = true;
				}
			}
		}

		return true;
	}

}
0