问题 J: Floating-Point Hazard 求导

题目链接:http://icpc.upc.edu.cn/problem.php?cid=1740&pid=9

题意:

题解:因为10^-15这个很小,所以就可以看做对(x)^1/3求导,得到1 / 3  * (x) ^ (- 2 / 3 )

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l,r;
	while(~scanf("%d%d",&l,&r))
	{
		if(l==0&&r==0)break;
		double ans=0;
		for(int i=l;i<=r;i++)
			ans+=pow(i,-1.0*2/3);
		ans /= 3;
		int p = 15;
		while(ans >= 10)
		{
			ans /= 10;
			p--;
		}
		while(ans < 1)
		{
			ans *= 10;
			p++;
		}
		printf("%.5fE-%03d\n",ans,p);
	}
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/mmk27_word/article/details/89684678