結果
| 問題 |
No.144 エラトステネスのざる
|
| コンテスト | |
| ユーザー |
sntea
|
| 提出日時 | 2015-10-29 14:09:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 324 ms / 2,000 ms |
| コード長 | 1,404 bytes |
| コンパイル時間 | 609 ms |
| コンパイル使用メモリ | 80,876 KB |
| 実行使用メモリ | 11,520 KB |
| 最終ジャッジ日時 | 2024-09-13 04:30:12 |
| 合計ジャッジ時間 | 3,359 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#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;
}
sntea