結果
| 問題 |
No.106 素数が嫌い!2
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2018-10-03 19:11:56 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 514 ms / 5,000 ms |
| コード長 | 939 bytes |
| コンパイル時間 | 4,038 ms |
| コンパイル使用メモリ | 105,984 KB |
| 実行使用メモリ | 34,688 KB |
| 最終ジャッジ日時 | 2024-10-12 10:25:49 |
| 合計ジャッジ時間 | 5,362 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.Collections.Generic;
using System.Linq;
using System;
public class Hello
{
public static void Main()
{
string[] line = Console.ReadLine().Trim().Split(' ');
var n = int.Parse(line[0]);
var k = int.Parse(line[1]);
var p = GeneratePrime(n);
var a = new int[n + 1];
for (int i = 0; i < p.Count(); i++)
for (int j = 1; p[i] * j <= n; j++)
a[p[i] * j]++;
var ans = a.Count(x => x >= k);
Console.WriteLine(ans);
}
public static List<int> GeneratePrime( int m)
{
var p = new List<int>();
int prime;
var sqrtMax = Math.Sqrt(m);
var s = Enumerable.Range(2, m - 1).ToList();
do
{
prime = s.First();
p.Add(prime);
s.RemoveAll(n => n % prime == 0);
}
while (prime < sqrtMax);
p.AddRange(s);
return p;
}
}
bluemegane