結果

問題 No.308 素数は通れません
コンテスト
ユーザー pekempey
提出日時 2015-12-05 01:24:46
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 67 ms / 1,000 ms
コード長 756 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,671 ms
コンパイル使用メモリ 86,092 KB
実行使用メモリ 42,096 KB
最終ジャッジ日時 2026-05-21 23:57:46
合計ジャッジ時間 10,173 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 107
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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