結果
問題 | No.713 素数の和 |
ユーザー | chika0707 |
提出日時 | 2019-09-12 12:25:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 60 ms / 2,000 ms |
コード長 | 1,797 bytes |
コンパイル時間 | 1,626 ms |
コンパイル使用メモリ | 58,292 KB |
実行使用メモリ | 15,728 KB |
最終ジャッジ日時 | 2023-09-15 14:11:46 |
合計ジャッジ時間 | 1,968 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
15,728 KB |
testcase_01 | AC | 58 ms
15,580 KB |
testcase_02 | AC | 58 ms
15,660 KB |
testcase_03 | AC | 58 ms
15,628 KB |
testcase_04 | AC | 59 ms
15,684 KB |
testcase_05 | AC | 59 ms
15,676 KB |
testcase_06 | AC | 58 ms
15,668 KB |
testcase_07 | AC | 59 ms
15,668 KB |
testcase_08 | AC | 58 ms
15,728 KB |
ソースコード
using System; using System.Collections.Generic; using System.Linq; using static Input; public class Prog { public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } } public static void Solve() { int N = NextInt(); bool[] memo = Enumerable.Repeat(false, N + 1).ToArray(); long ans = 0; for (int x = 2; x <= N; x++) { if (memo[x]) continue; ans += x; for (int j = 2; j * x <= N; j++) memo[j * x] = true; } Console.WriteLine(ans); ; } public static void Main() { var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); Solve(); Console.Out.Flush(); } } public class Input { public const long MOD = 1000000007; public const int INF = 1000000007; private static Queue<string> q = new Queue<string>(); private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); } public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); } public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); } public static string NextString() { Confirm(); return q.Dequeue(); } public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); } public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); } public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); } public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); } public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); } }