結果
| 問題 | No.144 エラトステネスのざる |
| コンテスト | |
| ユーザー |
misora192
|
| 提出日時 | 2020-05-27 22:31:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,077 bytes |
| 記録 | |
| コンパイル時間 | 1,592 ms |
| コンパイル使用メモリ | 171,860 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-10-13 03:52:50 |
| 合計ジャッジ時間 | 5,204 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / 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, int 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++){
int cnt = 1;
int y = i;
for(int x : primes){
int 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;
}
misora192