結果
| 問題 |
No.144 エラトステネスのざる
|
| ユーザー |
aim_cpo
|
| 提出日時 | 2017-06-19 20:46:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,563 bytes |
| コンパイル時間 | 751 ms |
| コンパイル使用メモリ | 92,236 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-02 07:51:11 |
| 合計ジャッジ時間 | 15,668 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 7 |
ソースコード
#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;
bool a[1000001];
inline void prime() {
for (int i = 0; i <= 10; i++)a[i] = 1;
for (int i = 2; i <= n; i++) {
if (a[i]) {
int b = i * 2;
while (b <= n) {
a[b]=0;
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]) {
res += 1;
}
else {
int now = i;
int nowp = 2;
int cont = 0;
while (nowp*nowp<now) {
if (now%nowp == 0) {
cont++;
nowp++;
}
else {
nowp++;
}
}
cont *= 2;
if (nowp*nowp == now)cont++;
//cout << cont << endl;
res += power(cont);
}
//printf("%.9f\n", res);
}
return res;
}
int main() {
cin >> n >> p;
prime();
double ans = solve();
printf("%.9f", ans);
return 0;
}
aim_cpo