結果

問題 No.192 合成数
ユーザー kenkooookenkoooo
提出日時 2015-04-26 22:28:32
言語 Java19
(openjdk 21)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 73,344 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2023-09-09 08:23:15
合計ジャッジ時間 6,635 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,412 KB
testcase_01 AC 114 ms
55,840 KB
testcase_02 AC 111 ms
56,232 KB
testcase_03 AC 114 ms
55,828 KB
testcase_04 AC 112 ms
56,076 KB
testcase_05 AC 113 ms
55,852 KB
testcase_06 AC 113 ms
56,296 KB
testcase_07 AC 114 ms
56,340 KB
testcase_08 AC 114 ms
55,656 KB
testcase_09 AC 111 ms
55,740 KB
testcase_10 AC 115 ms
55,764 KB
testcase_11 AC 112 ms
53,932 KB
testcase_12 AC 116 ms
55,956 KB
testcase_13 AC 112 ms
55,740 KB
testcase_14 AC 112 ms
55,924 KB
testcase_15 AC 112 ms
55,976 KB
testcase_16 AC 112 ms
55,676 KB
testcase_17 AC 115 ms
55,980 KB
testcase_18 AC 115 ms
55,868 KB
testcase_19 AC 116 ms
55,968 KB
testcase_20 AC 113 ms
55,800 KB
testcase_21 AC 115 ms
55,416 KB
testcase_22 AC 112 ms
55,964 KB
testcase_23 AC 114 ms
55,880 KB
testcase_24 AC 113 ms
56,060 KB
testcase_25 AC 114 ms
53,880 KB
testcase_26 AC 115 ms
55,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		ArrayList<Integer> primes = new ArrayList<>();
		primes.add(2);
		for (int i = 1; 2 * i + 1 <= Math.sqrt(N + 100); i++) {
			int n = 2 * i + 1;
			boolean isPrime = true;
			for (Integer integer : primes) {
				if (n % integer == 0) {
					isPrime = false;
					break;
				}
			}
			if (isPrime) {
				primes.add(n);
			}
		}
		for (int i = N - 100; i <= N + 100; i++) {
			for (Integer integer : primes) {
				if (i % integer == 0 && i / integer != 1) {
					System.out.println(i);
					return;
				}
			}
		}
	}
}
0