結果

問題 No.144 エラトステネスのざる
ユーザー diginatudiginatu
提出日時 2015-02-06 00:36:51
言語 D
(dmd 2.107.1)
結果
WA  
実行時間 -
コード長 577 bytes
コンパイル時間 2,209 ms
コンパイル使用メモリ 151,508 KB
実行使用メモリ 11,916 KB
最終ジャッジ日時 2023-09-02 19:47:07
合計ジャッジ時間 4,102 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,368 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 1 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,372 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,372 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 46 ms
10,916 KB
testcase_14 AC 45 ms
10,968 KB
testcase_15 WA -
testcase_16 AC 46 ms
11,916 KB
testcase_17 AC 46 ms
11,176 KB
testcase_18 AC 49 ms
11,244 KB
testcase_19 AC 46 ms
11,904 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];
  }

  writeln(ans);
}
0