結果
| 問題 |
No.106 素数が嫌い!2
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2017-06-22 02:58:26 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 392 ms / 5,000 ms |
| コード長 | 2,222 bytes |
| コンパイル時間 | 1,038 ms |
| コンパイル使用メモリ | 115,972 KB |
| 実行使用メモリ | 68,040 KB |
| 最終ジャッジ日時 | 2024-10-02 12:06:39 |
| 合計ジャッジ時間 | 3,569 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番