公式比较好推
精度好难搞啊@_@
下面记笔记@_@
****在CodeBlocks中,输出double型变量要使用%f (参见http://bbs.****.net/topics/391938535
**** long double用%LF输出
**** __float128 精度比 long double 高(可以在中间运算时使用,输出时把__float128强制转化为double然后printf
**** 注意n->∞时(这道题里是1e6),可以借助极限公式@_@(有人用cmath公式就ac了,好强啊orz)
贴两个代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __float128 LB; //亲测此处long double会wa掉一半数据 LB qpow(LB x,LL k)
{
LB ret=;
for(;k;k>>=)
{
if(k&) ret*=x;
x=x*x;
}
return ret;
} int main()
{
int T;scanf("%d",&T);
while(T--)
{
LL n,m;
scanf("%lld%lld",&n,&m);
// cin>>n>>m;
LB t=qpow((LB)(n-)/n,m)*n;
LB ans=n-t;
// cout<<ans<<endl;
printf("%.7lf\n",(double)ans);
}
}
#include<bits/stdc++.h>
int main()
{
int T;scanf("%d",&T);
while(T--)
{
double n,m;
scanf("%lf%lf",&n,&m);
if(n<1e6)
printf("%f\n",n*(-pow(1.0*(n-)/n,m)));
else printf("%f\n",n*(-exp(-1.0*m/n)));
}
}