結果

問題 No.144 エラトステネスのざる
ユーザー snteasntea
提出日時 2015-10-29 14:09:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 360 ms / 2,000 ms
コード長 1,404 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 75,184 KB
実行使用メモリ 11,556 KB
最終ジャッジ日時 2023-10-11 05:12:40
合計ジャッジ時間 3,819 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 353 ms
11,408 KB
testcase_14 AC 360 ms
11,556 KB
testcase_15 AC 341 ms
11,404 KB
testcase_16 AC 339 ms
11,392 KB
testcase_17 AC 336 ms
11,472 KB
testcase_18 AC 355 ms
11,524 KB
testcase_19 AC 77 ms
11,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <utility>
#include <cstdio>

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

typedef pair<int,int> P;
typedef long long int LL;
typedef pair<LL,LL> LP;

int yakusu[1000000+1][2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N;
	long double p;
	cin>>N>>p;
	FOR(i,2,N+1){
		if(yakusu[i][0]==0){
			yakusu[i][0]=i;
			yakusu[i][1]=1;
			for(int j=2;j*i<=N;j++){
				if(yakusu[i*j][0]==0){
					yakusu[i*j][0]=i;
					yakusu[i*j][1]=j;
				}
			}
		}
	}
	long double ans=0;
	FOR(i,2,N+1){
		//DEBUG(i);
		int d=1;
		int po=i;
		int pre=yakusu[po][0];
		int co=1;
		po=yakusu[po][1];
		while(po!=1){
			/*DEBUG(po);
			DEBUG(pre);
			DEBUG(co);*/
			if(pre==yakusu[po][0]){
				co++;
			}else{
				d*=(co+1);
				co=1;
				pre=yakusu[po][0];
			}
			po=yakusu[po][1];
		}
		//DEBUG(co);
		d*=(co+1);
		ans+=pow(1-p,d-2);
		//cout<<d-2<<endl;
	}
	cout.precision(10);
	cout<<ans<<endl;
	return 0;
}
0