結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー mbanmban
提出日時 2017-01-09 22:51:39
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 108 ms / 1,000 ms
コード長 2,231 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 104,740 KB
実行使用メモリ 32,576 KB
最終ジャッジ日時 2023-08-22 21:55:06
合計ジャッジ時間 7,544 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
29,896 KB
testcase_01 AC 105 ms
27,792 KB
testcase_02 AC 106 ms
29,748 KB
testcase_03 AC 106 ms
31,800 KB
testcase_04 AC 103 ms
30,680 KB
testcase_05 AC 106 ms
31,816 KB
testcase_06 AC 106 ms
29,808 KB
testcase_07 AC 107 ms
29,800 KB
testcase_08 AC 106 ms
29,792 KB
testcase_09 AC 107 ms
31,820 KB
testcase_10 AC 105 ms
27,920 KB
testcase_11 AC 106 ms
31,948 KB
testcase_12 AC 106 ms
29,996 KB
testcase_13 AC 106 ms
31,880 KB
testcase_14 AC 106 ms
29,780 KB
testcase_15 AC 106 ms
31,784 KB
testcase_16 AC 107 ms
32,576 KB
testcase_17 AC 107 ms
31,860 KB
testcase_18 AC 105 ms
29,824 KB
testcase_19 AC 106 ms
31,864 KB
testcase_20 AC 106 ms
29,856 KB
testcase_21 AC 104 ms
27,840 KB
testcase_22 AC 105 ms
29,784 KB
testcase_23 AC 105 ms
29,972 KB
testcase_24 AC 106 ms
31,788 KB
testcase_25 AC 108 ms
27,728 KB
testcase_26 AC 106 ms
29,832 KB
testcase_27 AC 105 ms
29,832 KB
testcase_28 AC 104 ms
32,496 KB
testcase_29 AC 105 ms
29,908 KB
testcase_30 AC 106 ms
29,808 KB
testcase_31 AC 106 ms
29,772 KB
testcase_32 AC 105 ms
29,812 KB
testcase_33 AC 108 ms
31,824 KB
testcase_34 AC 107 ms
29,844 KB
testcase_35 AC 105 ms
29,968 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;


class Magatro
{
    static int N,L;
    static Scanner sc = new Scanner();
    static int[] Primes;
 static void Main()
    {
        N = sc.NextInt();
        L = sc.NextInt();
        int[] Primes = PrimeCalc(5000000);
        long ans = 0;
        for(int i = 0; i < Primes.Length; i++)
        {
            int q = Primes[i] * (N - 1);
            if (L>=q)
            {
                ans += (L - q + 1);
            }
            else
            {
                break;
            }
        }
        Console.WriteLine(ans);
    }
    static int[] PrimeCalc(int max)
    {
        int loop = (int)Math.Sqrt(max);
        bool[] num = new bool[max + 1];
        num[0] = true;
        num[1] = true;
        for(int i = 2 * 2; i <= max; i += 2)
        {
            num[i] = true;
        }
        for(int i = 3; i <= loop; i += 2)
        {
            if (!num[i])
            {
                for(int j = i + i; j <= max; j += i)
                {
                    num[j] = true;
                }
            }
        }
        List<int> res = new List<int>();
        res.Add(2);
        for(int i = 3; i <= max; i += 2)
        {
            if (!num[i])
            {
                res.Add(i);
            }
        }
        return res.ToArray();
    }
}

public class Scanner
{
    private string[] S;
    private int Index;
    private char Separator;
    public Scanner(char separator=' ')
    {
        Index = 0;
        Separator = separator;
    }
    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    } 
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
0