結果
問題 | No.308 素数は通れません |
ユーザー |
|
提出日時 | 2015-12-12 03:43:06 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 150 ms / 1,000 ms |
コード長 | 587 bytes |
コンパイル時間 | 2,053 ms |
コンパイル使用メモリ | 75,568 KB |
実行使用メモリ | 54,344 KB |
最終ジャッジ日時 | 2024-11-27 18:45:39 |
合計ジャッジ時間 | 18,795 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 107 |
ソースコード
import java.util.*;import java.math.*;class main{public static BigInteger trans(int x){return BigInteger.valueOf(x);}public static void main(String[] args){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};Scanner sc = new Scanner(System.in);BigInteger n = sc.nextBigInteger();if(n.compareTo( trans(25) )<=0)System.out.println(ans[n.intValue()]);else{if( n.mod(trans(8)).compareTo(trans(1))==0 && n.subtract(trans(8)).isProbablePrime(20) )System.out.println(14);elseSystem.out.println(8);}}}