結果

問題 No.308 素数は通れません
ユーザー pekempey
提出日時 2015-12-05 01:24:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 756 bytes
コンパイル時間 2,026 ms
コンパイル使用メモリ 77,516 KB
実行使用メモリ 41,824 KB
最終ジャッジ日時 2024-11-27 18:40:01
合計ジャッジ時間 15,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 107
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigInteger N = new BigInteger(sc.next());
		int[] ans = {1,1,1,1,3,1,5,1,7,7,7,1,11,1,13,7,7,1,8,1,19,19,7,1,23,23,8,8,8,1,8,1,8,8,8,8,8,1,8,8,8,1,8,1,8,8,8,1,8,14,8,8,8,1,8,8,8,8,8,1,8,1,8,8,8,8,8,1,8,8,8,1,8,1,8,8,8,8,8,1,8,14,8,1,8,8,8,8,8,1,8,8,8,8,8,8,8,1,8,8};
		if (N.compareTo(BigInteger.valueOf(100)) < 0) {
			int n = N.intValue();
			System.out.println(ans[n]);
		} else {
			if (N.mod(BigInteger.valueOf(8)).intValue() != 1) {
				System.out.println(8);
			} else if (!N.subtract(BigInteger.valueOf(8)).isProbablePrime(30)) {
				System.out.println(8);
			} else {
				System.out.println(14);
			}
		}
	}
}
0