結果

問題 No.106 素数が嫌い!2
ユーザー sekiya9311sekiya9311
提出日時 2017-10-01 23:06:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 2,987 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 114,412 KB
実行使用メモリ 32,932 KB
最終ジャッジ日時 2024-04-27 17:37:54
合計ジャッジ時間 1,946 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
24,016 KB
testcase_01 AC 25 ms
25,260 KB
testcase_02 AC 22 ms
24,012 KB
testcase_03 AC 22 ms
24,232 KB
testcase_04 AC 36 ms
29,284 KB
testcase_05 AC 56 ms
32,932 KB
testcase_06 AC 56 ms
30,924 KB
testcase_07 AC 54 ms
31,356 KB
testcase_08 AC 24 ms
26,112 KB
testcase_09 AC 23 ms
23,724 KB
testcase_10 AC 54 ms
30,888 KB
testcase_11 AC 35 ms
26,772 KB
testcase_12 AC 62 ms
31,020 KB
testcase_13 AC 22 ms
23,884 KB
testcase_14 AC 22 ms
24,148 KB
testcase_15 AC 22 ms
26,004 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 ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().Solve();
        }

        const bool DEBUG = false;   // TODO: must check!!
        void Solve()
        {
            if (DEBUG)
            {
                string backPath = "..";
                char dirSep = System.IO.Path.DirectorySeparatorChar;
                string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
                sc = new Scanner(new System.IO.StreamReader(inFilePath));
            }
            else
            {
                sc = new Scanner();
            }
            int n = sc.NextInt;
            int k = sc.NextInt;
            if (k == 1)
            {
                Console.WriteLine(n - 1);
                System.Environment.Exit(0);
            }
            int ans = 0;
            for (int i = 2; i <= n; i++)
            {
                if (cnt[i] == 0)
                {
                    for (int j = i * 2; j <= n; j += i)
                    {
                        cnt[j]++;
                    }
                }
            }
            for (int i = 2; i <= n; i++)
            {
                if (cnt[i] >= k)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
        int[] cnt = new int[(int) 2e6 + 10];
    }

    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader ?? Console.In);
        }
        private void CheckBuffer()
        {
            if (this.buffer.Count == 0)
            {
                String[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool IsEmpty
        {
            get
            {
                this.CheckBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0