結果
| 問題 |
No.407 鴨等素数間隔列の数え上げ
|
| コンテスト | |
| ユーザー |
mban
|
| 提出日時 | 2017-01-09 22:47:17 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,231 bytes |
| コンパイル時間 | 1,069 ms |
| コンパイル使用メモリ | 110,248 KB |
| 実行使用メモリ | 33,660 KB |
| 最終ジャッジ日時 | 2024-12-18 00:20:22 |
| 合計ジャッジ時間 | 4,563 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 29 WA * 2 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
class Magatro
{
static int N,L;
static Scanner sc = new Scanner();
static int[] Primes;
static void Main()
{
N = sc.NextInt();
L = sc.NextInt();
int[] Primes = PrimeCalc(4000000);
long ans = 0;
for(int i = 0; i < Primes.Length; i++)
{
int q = Primes[i] * (N - 1);
if (L>=q)
{
ans += (L - q + 1);
}
else
{
break;
}
}
Console.WriteLine(ans);
}
static int[] PrimeCalc(int max)
{
int loop = (int)Math.Sqrt(max);
bool[] num = new bool[max + 1];
num[0] = true;
num[1] = true;
for(int i = 2 * 2; i <= max; i += 2)
{
num[i] = true;
}
for(int i = 3; i <= loop; i += 2)
{
if (!num[i])
{
for(int j = i + i; j <= max; j += i)
{
num[j] = true;
}
}
}
List<int> res = new List<int>();
res.Add(2);
for(int i = 3; i <= max; i += 2)
{
if (!num[i])
{
res.Add(i);
}
}
return res.ToArray();
}
}
public class Scanner
{
private string[] S;
private int Index;
private char Separator;
public Scanner(char separator=' ')
{
Index = 0;
Separator = separator;
}
public string Next()
{
string result;
if (S == null || Index >= S.Length)
{
S = Line();
Index = 0;
}
result = S[Index];
Index++;
return result;
}
private string[] Line()
{
return Console.ReadLine().Split(Separator);
}
public int NextInt()
{
return int.Parse(Next());
}
public double NextDouble()
{
return double.Parse(Next());
}
public long NextLong()
{
return long.Parse(Next());
}
}
mban