結果

問題 No.144 エラトステネスのざる
ユーザー aim_cpoaim_cpo
提出日時 2017-06-19 20:42:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,512 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 92,844 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-10 06:12:26
合計ジャッジ時間 4,570 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,880 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,944 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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<now) {
				if (now%nowp == 0) {
					cont++;
					nowp++;
				}
				else {
					nowp++;
				}
			}
			//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;
}
0