結果

問題 No.713 素数の和
ユーザー Pump0129Pump0129
提出日時 2018-07-17 13:37:12
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,080 bytes
コンパイル時間 3,301 ms
コンパイル使用メモリ 72,396 KB
実行使用メモリ 56,148 KB
最終ジャッジ日時 2023-08-16 09:50:16
合計ジャッジ時間 4,603 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
55,940 KB
testcase_01 RE -
testcase_02 AC 119 ms
55,728 KB
testcase_03 AC 136 ms
55,900 KB
testcase_04 AC 140 ms
56,148 KB
testcase_05 AC 131 ms
56,004 KB
testcase_06 AC 119 ms
55,776 KB
testcase_07 AC 118 ms
55,988 KB
testcase_08 AC 132 ms
56,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package net.ipipip0129.yukicoder.no713;

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

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = Integer.parseInt(scan.nextLine());
        int sqrt_num = ((int)Math.sqrt(num)) + 1;
        List<Integer> num_list = new ArrayList<>();
        for (int i = 0; i < num; i++) {
            num_list.add(i + 1);
        }
        int pt = 1;
        //エラトステネスの篩
        while (true) {
            int pt_num = num_list.get(pt);
            if (sqrt_num <= pt_num) {
                break;
            }
            for(int i = pt_num * 2; i <= num; i += pt_num) {
                if (num_list.indexOf(i) != -1) {
                    num_list.remove(num_list.indexOf(i));
                }
            }
            pt++;
        }
        int add_num = 0;
        for (int ans_num : num_list) {
            add_num += ans_num;
        }
        System.out.println(add_num - 1);
    }
}
0