結果

問題 No.312 置換処理
ユーザー jp_stejp_ste
提出日時 2016-02-02 21:52:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 162 ms / 2,000 ms
コード長 767 bytes
コンパイル時間 2,387 ms
コンパイル使用メモリ 77,800 KB
実行使用メモリ 54,372 KB
最終ジャッジ日時 2024-04-27 10:41:15
合計ジャッジ時間 10,158 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 153 ms
54,076 KB
testcase_01 AC 158 ms
54,372 KB
testcase_02 AC 159 ms
53,984 KB
testcase_03 AC 155 ms
54,256 KB
testcase_04 AC 132 ms
54,168 KB
testcase_05 AC 153 ms
54,076 KB
testcase_06 AC 148 ms
54,284 KB
testcase_07 AC 152 ms
53,828 KB
testcase_08 AC 160 ms
54,340 KB
testcase_09 AC 150 ms
54,296 KB
testcase_10 AC 153 ms
54,344 KB
testcase_11 AC 157 ms
54,192 KB
testcase_12 AC 152 ms
54,112 KB
testcase_13 AC 162 ms
53,816 KB
testcase_14 AC 155 ms
54,240 KB
testcase_15 AC 157 ms
54,144 KB
testcase_16 AC 147 ms
54,088 KB
testcase_17 AC 151 ms
54,328 KB
testcase_18 AC 154 ms
54,140 KB
testcase_19 AC 157 ms
54,152 KB
testcase_20 AC 156 ms
54,252 KB
testcase_21 AC 153 ms
54,128 KB
testcase_22 AC 134 ms
54,100 KB
testcase_23 AC 134 ms
54,008 KB
testcase_24 AC 138 ms
54,352 KB
testcase_25 AC 143 ms
54,036 KB
testcase_26 AC 135 ms
54,228 KB
testcase_27 AC 133 ms
54,072 KB
testcase_28 AC 133 ms
53,944 KB
testcase_29 AC 137 ms
54,180 KB
testcase_30 AC 153 ms
53,960 KB
testcase_31 AC 149 ms
54,140 KB
testcase_32 AC 146 ms
54,112 KB
testcase_33 AC 159 ms
53,868 KB
testcase_34 AC 157 ms
54,236 KB
testcase_35 AC 159 ms
54,340 KB
testcase_36 AC 137 ms
53,972 KB
testcase_37 AC 136 ms
54,092 KB
testcase_38 AC 139 ms
54,092 KB
testcase_39 AC 152 ms
53,960 KB
testcase_40 AC 142 ms
54,124 KB
testcase_41 AC 137 ms
53,984 KB
testcase_42 AC 138 ms
54,220 KB
testcase_43 AC 133 ms
54,136 KB
testcase_44 AC 135 ms
54,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
			}
		}
	}
}
0