結果

問題 No.192 合成数
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-12 00:35:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 2,007 ms
コンパイル使用メモリ 71,952 KB
実行使用メモリ 56,424 KB
最終ジャッジ日時 2023-09-09 09:14:15
合計ジャッジ時間 6,932 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,280 KB
testcase_01 AC 118 ms
55,772 KB
testcase_02 AC 118 ms
55,848 KB
testcase_03 AC 118 ms
55,956 KB
testcase_04 AC 119 ms
55,668 KB
testcase_05 AC 122 ms
55,824 KB
testcase_06 AC 118 ms
55,848 KB
testcase_07 AC 119 ms
55,752 KB
testcase_08 AC 119 ms
55,844 KB
testcase_09 AC 119 ms
55,744 KB
testcase_10 AC 120 ms
55,988 KB
testcase_11 AC 119 ms
55,820 KB
testcase_12 AC 119 ms
55,708 KB
testcase_13 AC 120 ms
56,064 KB
testcase_14 AC 120 ms
55,904 KB
testcase_15 AC 118 ms
53,660 KB
testcase_16 AC 120 ms
55,764 KB
testcase_17 AC 118 ms
54,488 KB
testcase_18 AC 119 ms
56,180 KB
testcase_19 AC 122 ms
56,296 KB
testcase_20 AC 118 ms
55,824 KB
testcase_21 AC 120 ms
53,956 KB
testcase_22 AC 122 ms
55,724 KB
testcase_23 AC 122 ms
56,076 KB
testcase_24 AC 117 ms
56,424 KB
testcase_25 AC 119 ms
56,136 KB
testcase_26 AC 122 ms
56,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int a = n-100;
		int b = n+100;
		for (int i=a; i<=b; i++) {
			boolean boo = isPrime(i);
			if (boo==false && i!=1) {System.out.println(i); break;}
		}
	}
	public static boolean isPrime(int num) {
	    if (num < 2) return false;
	    else if (num == 2) return true;
	    else if (num % 2 == 0) return false;
	    double sqrtNum = Math.sqrt(num);
	    for (int i = 3; i <= sqrtNum; i += 2) {
	        if (num % i == 0) {return false;}
	    }
	    return true;
	}
}
0