結果

問題 No.192 合成数
ユーザー jimanojimano
提出日時 2016-01-10 12:42:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 3,848 ms
コンパイル使用メモリ 72,176 KB
実行使用メモリ 58,140 KB
最終ジャッジ日時 2023-09-09 08:46:48
合計ジャッジ時間 8,575 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,768 KB
testcase_01 AC 124 ms
55,880 KB
testcase_02 AC 123 ms
58,140 KB
testcase_03 AC 125 ms
55,484 KB
testcase_04 AC 125 ms
55,564 KB
testcase_05 AC 125 ms
55,696 KB
testcase_06 AC 125 ms
55,876 KB
testcase_07 AC 123 ms
55,952 KB
testcase_08 AC 129 ms
55,556 KB
testcase_09 AC 124 ms
55,856 KB
testcase_10 AC 122 ms
55,360 KB
testcase_11 AC 119 ms
55,572 KB
testcase_12 AC 121 ms
55,776 KB
testcase_13 AC 121 ms
53,712 KB
testcase_14 AC 122 ms
55,756 KB
testcase_15 AC 121 ms
55,916 KB
testcase_16 AC 121 ms
55,992 KB
testcase_17 AC 120 ms
55,556 KB
testcase_18 AC 122 ms
55,768 KB
testcase_19 AC 121 ms
55,560 KB
testcase_20 AC 122 ms
55,644 KB
testcase_21 AC 122 ms
56,148 KB
testcase_22 AC 123 ms
56,020 KB
testcase_23 AC 125 ms
55,904 KB
testcase_24 AC 126 ms
55,808 KB
testcase_25 AC 126 ms
55,832 KB
testcase_26 AC 125 ms
55,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No0192 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int min = N - 100;
		int max = N + 100;
		int ans = 0;
		
		if(isComposite(N)){
			ans = N;
		}
		else{
			for(int i = min; i < (max + 1); i++){
				if(isComposite(i)) {
					ans = i;
					break;
				}
			}
		}
		System.out.println(ans);
	}
	
	static boolean isComposite(int num){
		
		if(num < 3) return false;
		for(int i = 2; i < num; i++){
			if(num % i == 0) return true;
		}
		return false;
	}
}
0