結果

問題 No.713 素数の和
ユーザー YamaKasaYamaKasa
提出日時 2018-07-14 00:21:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 2,549 ms
コンパイル使用メモリ 74,212 KB
実行使用メモリ 41,432 KB
最終ジャッジ日時 2024-04-17 11:45:21
合計ジャッジ時間 4,044 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
40,116 KB
testcase_01 AC 122 ms
41,320 KB
testcase_02 AC 119 ms
40,720 KB
testcase_03 AC 115 ms
39,996 KB
testcase_04 AC 111 ms
39,840 KB
testcase_05 AC 124 ms
41,108 KB
testcase_06 AC 112 ms
40,052 KB
testcase_07 AC 111 ms
40,264 KB
testcase_08 AC 127 ms
41,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		for(int i = 1; i <= N; i++) {
			if(isPrime(i)) {
				sum += i;
			}
		}
		scan.close();
		System.out.println(sum);
	}
 public static boolean isPrime(long n) {
        if(n == 1) {
        	return false;
        }
        for(long i = 2; i <= (int)Math.sqrt(n); i++){
            if(n % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0