結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー claw88claw88
提出日時 2016-08-06 11:04:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 104 ms / 1,000 ms
コード長 1,562 bytes
コンパイル時間 2,004 ms
コンパイル使用メモリ 105,852 KB
実行使用メモリ 30,656 KB
最終ジャッジ日時 2023-08-22 04:49:26
合計ジャッジ時間 5,411 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,772 KB
testcase_01 AC 55 ms
20,780 KB
testcase_02 AC 55 ms
22,784 KB
testcase_03 AC 56 ms
20,764 KB
testcase_04 AC 55 ms
20,664 KB
testcase_05 AC 53 ms
22,756 KB
testcase_06 AC 52 ms
22,712 KB
testcase_07 AC 52 ms
20,720 KB
testcase_08 AC 51 ms
20,816 KB
testcase_09 AC 55 ms
22,784 KB
testcase_10 AC 51 ms
20,792 KB
testcase_11 AC 52 ms
22,868 KB
testcase_12 AC 53 ms
20,596 KB
testcase_13 AC 55 ms
20,716 KB
testcase_14 AC 57 ms
20,888 KB
testcase_15 AC 56 ms
22,720 KB
testcase_16 AC 56 ms
20,740 KB
testcase_17 AC 53 ms
20,728 KB
testcase_18 AC 55 ms
18,620 KB
testcase_19 AC 59 ms
21,332 KB
testcase_20 AC 67 ms
22,692 KB
testcase_21 AC 52 ms
20,736 KB
testcase_22 AC 55 ms
22,796 KB
testcase_23 AC 53 ms
20,740 KB
testcase_24 AC 53 ms
20,728 KB
testcase_25 AC 76 ms
24,392 KB
testcase_26 AC 53 ms
20,824 KB
testcase_27 AC 57 ms
22,764 KB
testcase_28 AC 57 ms
20,804 KB
testcase_29 AC 57 ms
22,828 KB
testcase_30 AC 56 ms
20,720 KB
testcase_31 AC 55 ms
22,800 KB
testcase_32 AC 66 ms
24,360 KB
testcase_33 AC 104 ms
30,656 KB
testcase_34 AC 100 ms
28,496 KB
testcase_35 AC 74 ms
24,080 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.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yuki_407
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = scan();
            int max = a[1]/(a[0]-1);
           
            var p = new List<int>();
            if (max>1)
            {
                eratos(p, max);
            }
            long ans = 0;
            foreach (var i in p)
            {
                int m = a[1] - i*(a[0]-1) + 1;
                if (m<=0)
                {
                    break;
                }
                else
                {
                    ans += m;
                }
            }
            Console.WriteLine(ans);
        }
        
        //2~nまでの素数のリスト(n>=2)
        static void eratos(List<int> Prime,int n)
        {
            var a = new bool[n+1];
            a[0] =a[1]= true;
            int i;
            for (i = 2; i*i<=n; i++)
            {
                if (!a[i])
                {
                    Prime.Add(i);
                    int j = i << 1;
                    while (j <= n)
                    {
                        a[j] = true;
                        j = j + i;
                    }
                }    
            }
            for (; i <=n ; i++)if(!a[i])Prime.Add(i);          
        }
        static int[] scan()
        {
            return
                Array.ConvertAll
                (Console.ReadLine().Split(' '), int.Parse);
        }
    }
}
0