solution
∑
i
=
1
n
i
∗
C
2
n
−
i
n
−
i
∗
(
p
n
+
1
q
n
−
i
+
q
n
+
1
p
n
−
i
)
\sum\limits_{i=1}^{n}i*C_{2n-i}^{n-i}*(p^{n+1}q^{n-i}+q^{n+1}p^{n-i})
i=1∑ni∗C2n−in−i∗(pn+1qn−i+qn+1pn−i)
因
为
n
<
2
e
5
,
p
n
+
1
,
q
n
+
1
过
小
,
因
此
中
间
运
算
取
对
数
,
变
为
因为n<2e5,p^{n+1},q^{n+1}过小,因此中间运算取对数,变为
因为n<2e5,pn+1,qn+1过小,因此中间运算取对数,变为
∑
i
=
1
n
i
∗
e
I
n
C
2
n
−
i
n
−
i
∗
(
e
I
n
(
p
n
+
1
q
n
−
i
)
+
e
I
n
(
q
n
+
1
p
n
−
i
)
)
\sum\limits_{i=1}^{n}i*e^{InC_{2n-i}^{n-i}}*(e^{In(p^{n+1}q^{n-i})}+e^{In(q^{n+1}p^{n-i})})
i=1∑ni∗eInC2n−in−i∗(eIn(pn+1qn−i)+eIn(qn+1pn−i))
question
为
什
么
会
每
个
答
案
前
面
有
个
0
。
。
。
为什么会每个答案前面有个0。。。
为什么会每个答案前面有个0。。。
code
/*Siberian Squirrel*/
/*Cute KiloFish*/
#include<bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ACM_LOCAL
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const double eps = 1e-4;
const int INF = 0x3f3f3f3f;
/*const int MOD = 998244353, r = 119, k = 23, g = 3;
const int MOD = 1004535809, r = 479, k = 21, g = 3;*/
const int MOD = 1e9 + 7;
const int M = 1e7 + 10;
const int N = 1e6 + 10;
const int UP = 50;
//inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
int n;
double In_fac[N];
double p, q;
double C(int n, int m) {
if(m == 0) cout << 0;
return In_fac[n] - In_fac[m] - In_fac[n - m];
}
void solve(double res = 0) {
double _p = log(p), _q = log(q), pq;
for(int i = 1; i <= n; ++ i) {
double c = C(2 * n - i, n - i);
pq = (n + 1) * _p + (n - i) * _q;
res += i * exp(pq + c);
pq = (n + 1) * _q + (n - i) * _p;
res += i * exp(pq + c);
}
cout << fixed << setprecision(10) << res;
}
int main() {
IO;
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
#endif
int o = 1, cases = 0;
// cin >> o;
In_fac[0] = 0;
for(int i = 1; i < N; ++ i) {
In_fac[i] = In_fac[i - 1] + log(i);
}
while(o --) {
while(cin >> n >> p) {
q = 1 - p;
cout << "Case " << ++ cases << ": ";
solve();
cout << endl;
}
}
return 0;
}