結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
![]() |
提出日時 | 2016-09-01 18:19:07 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 196 ms / 1,000 ms |
コード長 | 1,832 bytes |
コンパイル時間 | 4,902 ms |
コンパイル使用メモリ | 114,924 KB |
実行使用メモリ | 47,852 KB |
最終ジャッジ日時 | 2024-12-16 01:13:20 |
合計ジャッジ時間 | 4,366 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray(); int kamoCount = inpt[0]; int maxX = inpt[1]; int[] primeList = this.GetPrimeNumbers(maxX); long ans = 0; for (int i = 0; i < primeList.Length; i++) { int prime = primeList[i]; long pos = ((long)kamoCount - 1) * prime; if (pos > maxX) { break; } ans += (maxX - (pos) + 1); } Console.WriteLine(ans); } private int[] GetPrimeNumbers(int max) { bool[] flag = new bool[max + 1]; List<int> ans = new List<int>(); for (int i = 2; i < flag.Length; i++) { if (!flag[i]) { ans.Add(i); for (int j = 1; j <= max / i; j++) { flag[i * j] = true; } } } return ans.ToArray(); } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 8 964853 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }