結果
問題 | No.312 置換処理 |
ユーザー |
![]() |
提出日時 | 2016-02-02 21:52:28 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 155 ms / 2,000 ms |
コード長 | 767 bytes |
コンパイル時間 | 2,367 ms |
コンパイル使用メモリ | 76,972 KB |
実行使用メモリ | 42,440 KB |
最終ジャッジ日時 | 2024-11-15 12:02:30 |
合計ジャッジ時間 | 9,666 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 |
ソースコード
import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner scan = new Scanner(System.in);long N = scan.nextLong();int M = (int)Math.sqrt(N)+1;boolean primeList[] = new boolean[M+1];for(int i=2; i<=M; i++) {primeList[i] = true;}for(int i=2; i<=M; i++) {if(primeList[i]) {for(int j=i+i; j<=M; j=j+i) {primeList[j] = false;}}}if(M >= 5) {primeList[4] = true;}boolean find = false;int i;for(i=3; i<=M; i++) {if(primeList[i]) {if(N%i == 0) {find = true;break;}}}if(find) {System.out.println(i);} else {if(N % 2 == 0 && N > 4) {System.out.println(N/2);} else {System.out.println(N);}}}}