結果
問題 | No.144 エラトステネスのざる |
ユーザー |
|
提出日時 | 2016-09-12 13:48:27 |
言語 | D (dmd 2.106.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,117 bytes |
コンパイル時間 | 2,598 ms |
コンパイル使用メモリ | 174,412 KB |
実行使用メモリ | 23,252 KB |
最終ジャッジ日時 | 2024-06-12 04:16:56 |
合計ジャッジ時間 | 11,672 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 1 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 1,163 ms
21,476 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 1,196 ms
21,304 KB |
testcase_19 | AC | 1,161 ms
21,556 KB |
ソースコード
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 primes = primes(n); auto ri = new real[](n + 1); foreach (i; 2..n + 1) { auto d = divisors(i, primes).length; if (d == 0) ri[i] = 1; else ri[i] = (1 - p) ^^ d; } writefln("%.7f", ri[2..$].sum); } int[] primes(int n) { auto sieve = new bool[](n + 1); sieve[0..2] = false; sieve[2..$] = true; foreach (p; 2..n.to!real.sqrt.to!int + 1) if (sieve[p]) foreach (q; iota(p * 2, n + 1, p)) sieve[q] = false; return sieve.enumerate .filter!("a[1]") .map!("a[0]").map!(to!int).array; } int[] divisors(int n, int[] primes) { int[] ri; auto limit = n.to!real.sqrt.to!int; foreach (p; primes) { if (p > n.to!real.sqrt) break; if (n % p == 0) { if (n == p * p) ri ~= p; else ri ~= [p, n / p]; } } return ri; }