結果

問題 No.106 素数が嫌い!2
ユーザー 14番14番
提出日時 2017-06-22 02:58:26
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 404 ms / 5,000 ms
コード長 2,222 bytes
コンパイル時間 1,087 ms
コンパイル使用メモリ 114,948 KB
実行使用メモリ 76,784 KB
最終ジャッジ日時 2024-04-10 10:17:04
合計ジャッジ時間 3,612 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
72,600 KB
testcase_01 AC 32 ms
25,332 KB
testcase_02 AC 31 ms
25,624 KB
testcase_03 AC 32 ms
27,372 KB
testcase_04 AC 313 ms
69,924 KB
testcase_05 AC 78 ms
34,040 KB
testcase_06 AC 66 ms
30,832 KB
testcase_07 AC 63 ms
28,700 KB
testcase_08 AC 50 ms
30,536 KB
testcase_09 AC 32 ms
23,196 KB
testcase_10 AC 64 ms
28,788 KB
testcase_11 AC 46 ms
26,864 KB
testcase_12 AC 404 ms
76,784 KB
testcase_13 AC 32 ms
25,340 KB
testcase_14 AC 30 ms
27,240 KB
testcase_15 AC 32 ms
25,456 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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        this.MaxNum = inpt[0];
        int primeCount = inpt[1];
        this.PrimeList = GetPrimeList(this.MaxNum);
        GetAns(0, 1, primeCount);
        Console.WriteLine(Flag.Count());
    }

    private int[] PrimeList;
    private int MaxNum;

    private Dictionary<int, bool> Flag = new Dictionary<int, bool>();
    private void GetAns(int idx, int subTotal, int remain) {
        if(subTotal > MaxNum) {
            return;
        }
        if(remain == 0) {
            for (long i = 1; i * subTotal <= MaxNum; i++) {
                Flag[(int)(i * subTotal)] = true;
            }
            return;
        }
        if(idx>=this.PrimeList.Length) {
            return;
        }
        for (int i = idx; i < PrimeList.Length; i++)
        {
            long tmp = 1;
            tmp = tmp * subTotal;
            tmp = tmp * PrimeList[i];
            if(tmp>MaxNum||tmp<=0) {
                return;
            }
            GetAns(i + 1, subTotal * PrimeList[i], remain - 1);
        }
    }


    private int[] GetPrimeList(int max) {
        bool[] flags = new bool[max + 1];
        List<int> primeList = new List<int>();
        for (int i = 2; i <= max; i++) {
            if (flags[i]) {
                continue;
            }
            primeList.Add(i);
            int tmp = max / i;
            for (int j = 1; j <= tmp;j++) {
                flags[i * j] = true;
            }
        }
        return primeList.ToArray();
    } 


	public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


1000000 2


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}
0