結果
| 問題 | No.144 エラトステネスのざる |
| コンテスト | |
| ユーザー |
aim_cpo
|
| 提出日時 | 2017-06-19 20:52:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 45 ms / 2,000 ms |
| コード長 | 1,331 bytes |
| 記録 | |
| コンパイル時間 | 703 ms |
| コンパイル使用メモリ | 91,952 KB |
| 実行使用メモリ | 7,680 KB |
| 最終ジャッジ日時 | 2024-10-02 07:51:39 |
| 合計ジャッジ時間 | 1,701 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
#define ll long long
#define fi first
#define se second
#define inf (999999999)
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
double p;
int a[1000001];
inline void prime() {
for (int i = 0; i <= n; i++)a[i] = 0;
for (int i = 2; i <= n; i++) {
int b = i * 2;
while (b <= n) {
a[b]++;
b += i;
}
}
}
inline double power(int a) {
double now = 1-p;
double res = 1;
while (a > 0) {
if (a & 1) {
res *= now;
}
a >>= 1;
now *= now;
}
return res;
}
inline double solve() {
double res = 0;
for (int i = 2; i <= n; i++) {
if (a[i]==0) {
res += 1;
}
else {
//cout << cont << endl;
res += power(a[i]);
}
//printf("%.9f\n", res);
}
return res;
}
int main() {
cin >> n >> p;
prime();
double ans = solve();
printf("%.9f", ans);
return 0;
}
aim_cpo