結果
問題 |
No.713 素数の和
|
ユーザー |
![]() |
提出日時 | 2019-12-07 20:32:20 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 1,493 bytes |
コンパイル時間 | 886 ms |
コンパイル使用メモリ | 109,792 KB |
実行使用メモリ | 17,664 KB |
最終ジャッジ日時 | 2024-12-26 06:20:22 |
合計ジャッジ時間 | 1,973 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.Text; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization.Formatters; using static System.Console; using static System.Math; namespace YukiCoder { public class Program { public static void Main(string[] args) { new Program().Solve(); } public void Solve() { int N = int.Parse(Console.ReadLine()); int n = 1000; bool[] primes = SieveOfEratosthenes(n); int sum = 0; for (int i = 0; i <= N; i++) { if (primes[i]) { sum += i; } } WriteLine(sum); } public static bool[] SieveOfEratosthenes(int n) { bool[] isPrime = new bool[n+1]; for (int i = 0; i < n; i++) { isPrime[i] = true; } isPrime[0] = false; isPrime[1] = false; for (int i = 2; i < Math.Sqrt(n); i++) { int j; if (isPrime[i]) { j = i + i; while (j <= n) { isPrime[j] = false; j = j + i; } } } return isPrime; } } }