結果

問題 No.144 エラトステネスのざる
ユーザー te-shte-sh
提出日時 2016-09-12 14:00:28
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 162,376 KB
実行使用メモリ 24,732 KB
最終ジャッジ日時 2023-09-02 22:04:12
合計ジャッジ時間 3,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 1 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,368 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 94 ms
23,444 KB
testcase_14 AC 132 ms
24,516 KB
testcase_15 AC 132 ms
24,004 KB
testcase_16 AC 131 ms
22,972 KB
testcase_17 AC 132 ms
24,052 KB
testcase_18 AC 133 ms
24,732 KB
testcase_19 AC 99 ms
24,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split;
  auto n = rd[0].to!int, p = rd[1].to!real;

  auto memo = new int[](n + 1);
  foreach (i; 2..n + 1)
    foreach (j; iota(i * 2, n + 1, i))
      memo[j] += 1;

  auto ri = new real[](n + 1);
  foreach (i; 2..n + 1) {
    auto d = memo[i];
    if (d == 0)
      ri[i] = 1;
    else
      ri[i] = (1 - p) ^^ d;
  }

  writefln("%.7f", ri[2..$].sum);
}
0