結果

問題 No.713 素数の和
ユーザー MatumoMatumo
提出日時 2018-07-13 22:31:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 74,192 KB
実行使用メモリ 41,248 KB
最終ジャッジ日時 2024-04-17 11:12:43
合計ジャッジ時間 4,022 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
41,044 KB
testcase_01 AC 127 ms
41,248 KB
testcase_02 AC 129 ms
41,224 KB
testcase_03 AC 120 ms
40,288 KB
testcase_04 AC 118 ms
40,288 KB
testcase_05 AC 117 ms
40,000 KB
testcase_06 AC 118 ms
40,956 KB
testcase_07 AC 111 ms
40,052 KB
testcase_08 AC 122 ms
41,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = sc.nextInt();

		int index = 0;
		int[] prime = new int[n];

		int ans = 0;
		for(int i = 2; i <= n; i++) {
			boolean isPrime = true;
			for(int j = 0; j < index; j++) {
				if(i%prime[j] == 0) {
					isPrime = false;
					break;
				}
			}
			if(isPrime) {
				ans += i;
				prime[index] = i;
				index++;
			}
		}

		System.out.println(ans);
    }
}
0