結果

問題 No.192 合成数
ユーザー jimano
提出日時 2016-01-10 12:42:47
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 557 bytes
コンパイル時間 3,558 ms
コンパイル使用メモリ 74,644 KB
実行使用メモリ 41,340 KB
最終ジャッジ日時 2024-06-27 01:53:43
合計ジャッジ時間 7,584 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

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