結果

問題 No.192 合成数
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-05-03 22:08:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,251 bytes
コンパイル時間 3,585 ms
コンパイル使用メモリ 75,248 KB
実行使用メモリ 57,968 KB
最終ジャッジ日時 2023-09-09 08:27:14
合計ジャッジ時間 8,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,720 KB
testcase_01 AC 125 ms
55,904 KB
testcase_02 AC 125 ms
55,892 KB
testcase_03 AC 125 ms
56,088 KB
testcase_04 AC 125 ms
57,968 KB
testcase_05 AC 126 ms
55,716 KB
testcase_06 AC 126 ms
56,152 KB
testcase_07 AC 125 ms
55,948 KB
testcase_08 AC 124 ms
55,560 KB
testcase_09 AC 124 ms
56,044 KB
testcase_10 AC 124 ms
56,276 KB
testcase_11 AC 129 ms
55,556 KB
testcase_12 AC 124 ms
55,648 KB
testcase_13 AC 124 ms
56,040 KB
testcase_14 AC 125 ms
55,724 KB
testcase_15 AC 126 ms
56,220 KB
testcase_16 AC 124 ms
55,848 KB
testcase_17 AC 126 ms
55,592 KB
testcase_18 AC 124 ms
53,996 KB
testcase_19 AC 126 ms
56,100 KB
testcase_20 AC 124 ms
55,728 KB
testcase_21 AC 125 ms
56,060 KB
testcase_22 AC 126 ms
55,720 KB
testcase_23 AC 126 ms
56,020 KB
testcase_24 AC 126 ms
56,012 KB
testcase_25 AC 125 ms
55,788 KB
testcase_26 AC 125 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.192 合成数

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No0192 {
    
    static final Scanner in = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        boolean[] isPrime = sieveOfEratosthenes(2000);
        int n = in.nextInt();
        for (int i=n-100; i<=n+100; i++) {
            if (!isPrime[i] && i != 1) {
                out.println(i);
                return;
            }
        }
    }

    static boolean[] sieveOfEratosthenes(int n) {
        boolean[] isPrime = new boolean[n];
        Arrays.fill(isPrime,true);
        isPrime[0] = isPrime[1] = false;
        for (int i=2; i<n; i++) {
            if (isPrime[i]) {
                for (int j=i+i; j<n; j+=i) isPrime[j] = false;
            }
        }
        return isPrime;
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        in.close();
        out.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0