結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2017-01-09 22:51:39 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 77 ms / 1,000 ms |
コード長 | 2,231 bytes |
コンパイル時間 | 952 ms |
コンパイル使用メモリ | 113,004 KB |
実行使用メモリ | 35,228 KB |
最終ジャッジ日時 | 2024-12-18 00:20:32 |
合計ジャッジ時間 | 4,638 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 31 |
コンパイルメッセージ
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(5000000); 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()); } }