結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー bluemeganebluemegane
提出日時 2021-08-28 09:05:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 407 ms / 2,000 ms
コード長 1,108 bytes
コンパイル時間 1,053 ms
コンパイル使用メモリ 112,632 KB
実行使用メモリ 34,864 KB
最終ジャッジ日時 2024-05-01 15:46:29
合計ジャッジ時間 5,980 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
25,308 KB
testcase_01 AC 30 ms
26,972 KB
testcase_02 AC 393 ms
30,732 KB
testcase_03 AC 25 ms
21,944 KB
testcase_04 AC 29 ms
25,312 KB
testcase_05 AC 29 ms
27,104 KB
testcase_06 AC 30 ms
27,156 KB
testcase_07 AC 29 ms
24,956 KB
testcase_08 AC 29 ms
25,136 KB
testcase_09 AC 30 ms
25,180 KB
testcase_10 AC 30 ms
27,088 KB
testcase_11 AC 30 ms
25,024 KB
testcase_12 AC 386 ms
30,140 KB
testcase_13 AC 188 ms
30,608 KB
testcase_14 AC 323 ms
33,088 KB
testcase_15 AC 332 ms
29,476 KB
testcase_16 AC 136 ms
27,404 KB
testcase_17 AC 157 ms
27,912 KB
testcase_18 AC 170 ms
28,264 KB
testcase_19 AC 354 ms
31,676 KB
testcase_20 AC 234 ms
29,340 KB
testcase_21 AC 406 ms
32,444 KB
testcase_22 AC 407 ms
34,864 KB
testcase_23 AC 404 ms
32,604 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var L = int.Parse(line[0]);
        var r = int.Parse(line[1]);
        getAns(L, r);
    }
    static void getAns(int L, int r)
    {
        if (r == 1) { Console.WriteLine(0); return; }
        var count = 0;
        foreach (var x in GeneratePrime(2 * r - 1))
        {
            if (x >= L && x <= r) count++;
            if (x != 2)
            {
                var t = (x + 1) / 2;
                if ((t >= L && t <= r) && (t - 1 >= L && t - 1 <= r)) count++;
            }
        }
        Console.WriteLine(count);
    }
    static List<int> GeneratePrime(int m)
    {
        var a = new List<int>();
        int p;
        var sqrtMax = Math.Sqrt(m);
        var s = Enumerable.Range(2, m - 1).ToList();
        do
        {
            p = s.First();
            a.Add(p);
            s.RemoveAll(n => n % p == 0);
        }
        while (p < sqrtMax);
        a.AddRange(s);
        return a;
    }
}
0