結果
問題 |
No.144 エラトステネスのざる
|
ユーザー |
![]() |
提出日時 | 2019-07-11 22:31:44 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 54 ms / 2,000 ms |
コード長 | 504 bytes |
コンパイル時間 | 1,276 ms |
コンパイル使用メモリ | 31,104 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-11-08 16:59:30 |
合計ジャッジ時間 | 2,571 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
// yukicoder: No.144 エラトステネスのざる // 2019.7.11 bal4u #include <stdio.h> #include <math.h> #define EQ(a, b) (fabs((a)-(b)) < 1e-8) int f[1000005]; int main() { int i, j, n, N; double p, ans; scanf("%d%lf", &N, &p); n = N >> 1; for (i = 2; i <= n; i++) for (j = i << 1; j <= N; j += i) f[j]++; if (EQ(p, 0)) ans = N-1; else if (EQ(p, 1)) while (N > 1) ans += (f[N--] == 0); else { ans = 0; while (N > 1) ans += pow(1-p, f[N--]); } printf("%.10lf\n", ans); return 0; }