結果
| 問題 |
No.144 エラトステネスのざる
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-29 02:04:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 764 ms / 2,000 ms |
| コード長 | 647 bytes |
| コンパイル時間 | 1,828 ms |
| コンパイル使用メモリ | 172,504 KB |
| 実行使用メモリ | 7,800 KB |
| 最終ジャッジ日時 | 2024-10-07 15:16:13 |
| 合計ジャッジ時間 | 7,608 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
double p;
cin >> p;
vector<int> a(n + 1);
for (int i = 2; i <= n; i++) {
int x = i;
vector<int> b;
for (int j = 2; j * j <= x; j++) {
int c = 0;
while (x % j == 0) {
c++;
x /= j;
}
if (c != 0) b.push_back(c);
}
if (x != 1) b.push_back(1);
int cnt = 1;
for (auto &j : b) {
cnt *= j + 1;
}
a[i] = cnt;
}
double ans = 0;
for (int i = 2; i <= n; i++) {
ans += pow(1.0 - p, a[i] - 2);
}
cout << setprecision(20) << fixed << ans << '\n';
return 0;
}