結果
問題 |
No.144 エラトステネスのざる
|
ユーザー |
![]() |
提出日時 | 2020-05-27 22:25:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,074 bytes |
コンパイル時間 | 1,497 ms |
コンパイル使用メモリ | 172,380 KB |
実行使用メモリ | 10,912 KB |
最終ジャッジ日時 | 2024-10-13 03:50:20 |
合計ジャッジ時間 | 5,196 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 1 -- * 6 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; typedef unsigned long long ull; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } // pow double pow(double a, ll b){ if(b == 0) return 1.0; if(b & 1) { return a * pow(a, b - 1); } else { double d = pow(a, b / 2); return d * d; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; double p; cin >> n >> p; vector<bool> isprime(n+1, true); isprime[0] = isprime[1] = false; vector<int> primes; for(int i = 2; i <= n; i++){ if(isprime[i]) primes.push_back(i); for(int j = 2 * i; j <= n; j += i) isprime[j] = false; } double ans = 0.0; for(int i = 2; i <= n; i++){ ll cnt = 1; int y = i; for(int x : primes){ ll t = 1; while(y % x == 0){ y /= x; t++; } cnt *= t; } cnt -= 2; ans += pow(1.0 - p, cnt); } cout << fixed << setprecision(10); cout << ans << endl; }