結果

問題 No.144 エラトステネスのざる
ユーザー diginatudiginatu
提出日時 2015-02-06 00:44:06
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 2,171 ms
コンパイル使用メモリ 151,420 KB
実行使用メモリ 11,424 KB
最終ジャッジ日時 2023-09-02 19:47:11
合計ジャッジ時間 3,277 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 56 ms
11,040 KB
testcase_14 AC 53 ms
11,424 KB
testcase_15 AC 56 ms
11,024 KB
testcase_16 AC 54 ms
10,660 KB
testcase_17 AC 54 ms
11,172 KB
testcase_18 AC 57 ms
10,720 KB
testcase_19 AC 56 ms
10,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.conv, std.math, std.string, std.range, std.array,
       std.algorithm;

double[] is_prime;

void Eratosthenes(long lim, double q){
  is_prime[] = 1.0;
  is_prime[0] = 0.0;
  is_prime[1] = 0.0;
  for(long p=2; p<=lim; p++) {
    for(long k=2*p; k<=lim; k+=p) is_prime[k] *= q;
  }
}

void main(){
  auto buf = readln().strip().split();
  immutable N = buf[0].to!int;
  immutable p = buf[1].to!double;

  is_prime.length = N + 5;

  Eratosthenes(N, 1-p);

  double ans = 0;
  foreach(immutable i; 2 .. N+1) {
    ans += is_prime[i];
  }

  writefln("%.10f", ans);
}
0