結果
問題 | No.144 エラトステネスのざる |
ユーザー |
|
提出日時 | 2020-04-18 02:54:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 1,074 bytes |
コンパイル時間 | 2,813 ms |
コンパイル使用メモリ | 197,816 KB |
最終ジャッジ日時 | 2025-01-09 21:05:52 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:53:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | double p; scanf("%d%lf",&n,&p); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; class linear_sieve{ vector<int> lpf,p; public: linear_sieve(int n):lpf(n+1){ for(int i=2;i<=n;i++){ if(lpf[i]==0){ lpf[i]=i; p.emplace_back(i); } for(int j=0;j<p.size()&&p[j]<=lpf[i]&&i*p[j]<=n;j++) lpf[i*p[j]]=p[j]; } } const vector<int>& primes()const{ return p; } bool is_prime(int a)const{ assert(a<=(int)lpf.size()-1); return a>0 && lpf[a]==a; } map<int,int> prime_factorize(int a)const{ assert(a<=(int)lpf.size()-1); map<int,int> pf; for(;a>1;a/=lpf[a]) ++pf[lpf[a]]; return pf; } int number_of_divisors(int a)const{ assert(a<=(int)lpf.size()-1); int res=1,cnt=0,pre=-1; for(;a>1;a/=lpf[a]){ if(pre==-1 || pre==lpf[a]){ cnt++; } else{ res*=cnt+1; cnt=1; } pre=lpf[a]; } return res*(cnt+1); } }; int main(){ int n; double p; scanf("%d%lf",&n,&p); linear_sieve LS(n); double ans=0; for(int i=2;i<=n;i++){ ans+=pow(1-p,LS.number_of_divisors(i)-2); } printf("%.9f\n",ans); return 0; }