結果

問題 No.144 エラトステネスのざる
ユーザー snteasntea
提出日時 2015-10-29 11:46:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,474 bytes
コンパイル時間 574 ms
コンパイル使用メモリ 75,380 KB
実行使用メモリ 11,704 KB
最終ジャッジ日時 2023-10-11 05:07:04
合計ジャッジ時間 3,078 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,476 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 233 ms
11,420 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 235 ms
11,460 KB
testcase_19 AC 55 ms
11,392 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){
			for(int j=2;j*i<=N;j++){
				yakusu[i*j][0]=i;
				yakusu[i*j][1]=j;
			}
		}
	}
	long double ans=0;
	FOR(i,2,N+1){
		//DEBUG(i);
		if(yakusu[i][0]||yakusu[i][1]){
			int d=1;
			int po=i;
			int pre=yakusu[po][0];
			int co=1;
			po=yakusu[po][1];
			do{
				/*DEBUG(p);
				DEBUG(pre);
				DEBUG(co);*/
				//cout<<endl;
				if(pre==po){
					co++;
				}else{
					d*=co+1;
					co=1;
				}
				po=yakusu[po][1];
				pre=yakusu[po][0];
			}while(yakusu[po][0]||yakusu[po][1]);
			//DEBUG(co);
			d*=co+1;
			ans+=pow(1-p,d-2);
			//cout<<d-2<<endl;
		}else{
			ans+=1;
			//cout<<0<<endl;
		}
		//cout<<endl;
	}
	cout.precision(10);
	cout<<ans<<endl;
	return 0;
}
0