結果

問題 No.308 素数は通れません
コンテスト
ユーザー piyoko_212
提出日時 2015-12-25 19:05:17
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 91 ms / 1,000 ms
コード長 703 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,318 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 44,664 KB
最終ジャッジ日時 2026-05-22 00:02:44
合計ジャッジ時間 10,491 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 107
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*;
import java.math.*;
class Main{
	static int small[]={0,0,0,0,3,0,5,0,7,7,7,0,11,0,13,7,7,0,8,0,19,19,7,0,23,23};
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		BigInteger bi=s.nextBigInteger();
		if(bi.compareTo(new BigInteger("26"))==-1){
			System.out.println(small[bi.intValue()]);
			System.exit(0);
		}
		if(bi.mod(new BigInteger("8")).equals(BigInteger.ONE)&&bi.subtract(new BigInteger("8")).isProbablePrime(100)){
			if(bi.mod(new BigInteger("14")).equals(BigInteger.ONE)&&bi.subtract(new BigInteger("14")).isProbablePrime(100)){
				System.out.println(17);
			}else{
				System.out.println(14);
			}
		}else{
			System.out.println(8);
		}
	}
}
0