結果

問題 No.713 素数の和
ユーザー tentententen
提出日時 2020-09-02 13:07:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 74,048 KB
実行使用メモリ 41,644 KB
最終ジャッジ日時 2024-05-01 10:30:15
合計ジャッジ時間 3,427 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
41,340 KB
testcase_01 AC 110 ms
41,156 KB
testcase_02 AC 114 ms
41,452 KB
testcase_03 AC 111 ms
41,280 KB
testcase_04 AC 99 ms
41,540 KB
testcase_05 AC 101 ms
41,520 KB
testcase_06 AC 99 ms
41,644 KB
testcase_07 AC 113 ms
41,396 KB
testcase_08 AC 115 ms
41,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] isNotPrimes = new boolean[n + 1];
        isNotPrimes[0] = true;
        isNotPrimes[1] = true;
        for (int i = 2; i <= n; i++) {
            if (!isNotPrimes[i]) {
                for (int j = 2; i * j <= n; j++) {
                    isNotPrimes[i * j] = true;
                }
            }
        }
        long sum = 0;
        for (int i = 2; i <= n; i++) {
            if (!isNotPrimes[i]) {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}
0