結果
問題 |
No.407 鴨等素数間隔列の数え上げ
|
ユーザー |
|
提出日時 | 2016-08-06 11:04:22 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 75 ms / 1,000 ms |
コード長 | 1,562 bytes |
コンパイル時間 | 1,150 ms |
コンパイル使用メモリ | 112,496 KB |
実行使用メモリ | 25,344 KB |
最終ジャッジ日時 | 2024-12-15 22:53:10 |
合計ジャッジ時間 | 3,144 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.Linq; using System.Text; using System.Threading.Tasks; namespace yuki_407 { class Program { static void Main(string[] args) { var a = scan(); int max = a[1]/(a[0]-1); var p = new List<int>(); if (max>1) { eratos(p, max); } long ans = 0; foreach (var i in p) { int m = a[1] - i*(a[0]-1) + 1; if (m<=0) { break; } else { ans += m; } } Console.WriteLine(ans); } //2~nまでの素数のリスト(n>=2) static void eratos(List<int> Prime,int n) { var a = new bool[n+1]; a[0] =a[1]= true; int i; for (i = 2; i*i<=n; i++) { if (!a[i]) { Prime.Add(i); int j = i << 1; while (j <= n) { a[j] = true; j = j + i; } } } for (; i <=n ; i++)if(!a[i])Prime.Add(i); } static int[] scan() { return Array.ConvertAll (Console.ReadLine().Split(' '), int.Parse); } } }