結果

問題 No.106 素数が嫌い!2
ユーザー 14番14番
提出日時 2017-06-22 02:50:59
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,153 bytes
コンパイル時間 2,904 ms
コンパイル使用メモリ 113,184 KB
実行使用メモリ 77,872 KB
最終ジャッジ日時 2024-04-10 10:16:59
合計ジャッジ時間 7,009 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
70,452 KB
testcase_01 AC 32 ms
27,640 KB
testcase_02 AC 32 ms
25,460 KB
testcase_03 AC 31 ms
25,212 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 70 ms
28,528 KB
testcase_07 AC 68 ms
28,688 KB
testcase_08 AC 49 ms
30,324 KB
testcase_09 AC 33 ms
25,104 KB
testcase_10 AC 68 ms
28,552 KB
testcase_11 AC 48 ms
26,868 KB
testcase_12 WA -
testcase_13 AC 32 ms
25,460 KB
testcase_14 AC 30 ms
25,200 KB
testcase_15 AC 31 ms
23,220 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++)
        {
            if(subTotal*PrimeList[i]>MaxNum||subTotal*PrimeList[i]<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 = @"


2 1


";
	}

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