結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー bluemeganebluemegane
提出日時 2021-08-28 09:03:11
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,054 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 113,688 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-11-21 20:50:51
合計ジャッジ時間 6,166 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
    {
        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