2018 ICPC Asia Nakhon Pathom Regional Contest J Floating-Point Hazard

题面

题意

  • 求:
    ∑ i = l o w h i g h ( i + 1 0 − 15 3 − i 3 ) \sum_{i=low}^{high} (\sqrt[3]{i+10^{-15}}-\sqrt[3]i) i=lowhigh(3i+1015 3i )

  • T ≤ 2000 , 1 ≤ l o w , h i g h ≤ 2 × 1 0 9 , h i g h − l o w ≤ 1 0 4 T\le 2000,1\le low,high\le 2\times10^9,high-low\le 10^4 T2000,1low,high2×109,highlow104

思路

  1. 1 0 − 15 10^{-15} 1015 是一个很小的量,可以联想到 d x dx dx,写出求导公式:
    f ( x ) = x 3 f ′ ( x ) = x + d x 3 − x 3 d x = 1 3 x − 2 3 x + d x 3 − x 3 = 1 3 x − 2 3 d x \begin{aligned} f(x)&=\sqrt[3]{x}\\ f'(x)&=\dfrac{\sqrt[3]{x+dx}-\sqrt[3]x}{dx}=\frac{1}{3}x^{-\frac{2}{3}}\\ \sqrt[3]{x+dx}-\sqrt[3]x&=\frac{1}{3}x^{-\frac{2}{3}}dx \end{aligned} f(x)f(x)3x+dx 3x =3x =dx3x+dx 3x =31x32=31x32dx

  2. 带入 d x = 1 0 − 15 dx=10^{-15} dx=1015,注意转一下科学计数法

代码

int low, high;
void solve() {
    long double res = 0;
    rep(i, low, high) res += pow(i * 1.0, -2.0 / 3.0);
    res /= 3;
    int tot = 15;
    while(res < 1.0) res = res * 10.0, ++tot;
    while(res >= 10.0) res = res / 10.0, --tot;
    if(tot < 10) printf("%.5LfE-00%d\n", res, tot);
    else if(tot >= 100) printf("%.5LfE-%d\n", res, tot);
    else printf("%.5LfE-0%d\n", res, tot);
}

int main() {
    while(scanf("%d%d", &low, &high) && (low || high)) solve();
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值