結果
問題 | No.144 エラトステネスのざる |
ユーザー |
![]() |
提出日時 | 2019-09-23 15:40:58 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 2,165 bytes |
コンパイル時間 | 1,112 ms |
コンパイル使用メモリ | 159,868 KB |
実行使用メモリ | 11,616 KB |
最終ジャッジ日時 | 2024-09-19 04:26:26 |
合計ジャッジ時間 | 3,659 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef pair<int,int> P;typedef long long ll;typedef vector<int> vi;typedef vector<ll> vll;#define pb push_back#define mp make_pair#define eps 1e-9#define INF 2000000000#define LLINF 1000000000000000ll#define sz(x) ((int)(x).size())#define fi first#define sec second#define all(x) (x).begin(),(x).end()#define sq(x) ((x)*(x))#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)#define EQ(a,b) (abs((a)-(b))<eps)#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}template<class T,class U>ostream& operator << (ostream& os,pair<T,U>& p){os << p.fi << ',' << p.sec; return os;}template<class T,class U>istream& operator >> (istream& is,pair<T,U>& p){is >> p.fi >> p.sec; return is;}template<class T>ostream& operator << (ostream &os,const vector<T> &vec){for(int i=0;i<vec.size();i++){os << vec[i];if(i+1<vec.size())os << ' ';}return os;}template<class T>istream& operator >> (istream &is,vector<T>& vec){for(int i=0;i<vec.size();i++)is >> vec[i];return is;}void fastio(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}int N;double p;int mindiv[1000100];int divnum[1000100];template<class T>T mypow(T a,int x){T res = 1.0;while(x){if(x&1)res *= a;a = a*a;x >>= 1;}return res;}int main(){fastio();cin >> N >> p;for(int i=0;i<=1000000;i++)mindiv[i]=i;for(int i=2;i*i<=1000000;i++){for(int j=i*2;j<=1000000;j+=i){chmin(mindiv[j],i);}}for(int i=2;i<=1000000;i++){divnum[i] = 1;int x = i;while(x>1){int d = mindiv[x];int cnt = 0;while(x%d==0){x /= d;cnt++;}divnum[i] *= (cnt+1);}}// for(int i=2;i<=39;i++){// cout << i << ' ' << divnum[i] << ' ' << mindiv[i] << endl;// }double ans = 0.0;for(int i=2;i<=N;i++){ans += mypow(1.0-p,divnum[i]-2);}cout << ans << endl;return 0;}