Floating-Point Hazard (数学)

https://vj.z180.cn/c7965da2b8fbd28dfbce93c000a232e5?v=1578704227

Floating-Point Hazard (数学)

题意:

高精度求和

思路:

用求导定义得出所求式子可化为对i^(1/3)求导的和*1e5,即求1/3*i^(-2/3)的和*1e15

#include <stdio.h>
#include <string.h>
#include <math.h>

int main()
{
    int i, low, high, num;
    double sum;
    while(~scanf("%d %d", &low, &high)&&low&&high)
    {
        sum = 0.0;
        for(i=low; i<=high; i++)
        {
            sum = sum + pow(i, -2.0 / 3.0) / 3.0;
        }
        num = 15;
        while(sum < 1)
        {
            sum *= 10;
            num++;
        }
        while(sum > 10)
        {
            sum /= 10;
            sum--;
        }
        printf("%.5lfE-%03d\n", sum, num);
    }
    return 0;
}

相关推荐