結果

問題 No.713 素数の和
ユーザー YamaKasa
提出日時 2018-07-14 00:21:19
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 2,608 ms
コンパイル使用メモリ 79,396 KB
実行使用メモリ 41,268 KB
最終ジャッジ日時 2024-10-09 05:50:12
合計ジャッジ時間 3,777 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6
権限があれば一括ダウンロードができます

ソースコード

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