Floating-Point Hazard (数学定义QAQ)

本文探讨了一种特殊的数学计算问题,即如何在给定的上下限范围内,利用科学计数法精确计算一个特定表达式的值。通过引入求导的概念,文章提供了一种创新的解决方案,避免了直接计算可能带来的精度误差。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目描述
Given the value of low, high you will have to find the value of the following expression:


If you try to find the value of the above expression in a straightforward way, the answer may be incorrect due to precision error.

输入
The input file contains at most 2000 lines of inputs. Each line contains two integers which denote the value of low, high (1 ≤ low ≤ high ≤ 2000000000 and high-low ≤ 10000). Input is terminated by a line containing two zeroes. This line should not be processed.

输出
For each line of input produce one line of output. This line should contain the value of the expression above in exponential format. The mantissa part should have one digit before the decimal point and be rounded to five digits after the decimal point. To be more specific the output should be of the form d.dddddE-ddd, here d means a decimal digit and E means power of 10. Look at the output for sample input for details. Your output should follow the same pattern as shown below.

input
1 100
10000 20000
0 0
output
3.83346E-015
5.60041E-015
题意:
简单的来说就是根据那个公式去计算这个值,给你的是一个上、下限,然后根据这个求这个答案,然后最后的答案就要根据科学计数法来保四舍五入留最后5位
分析:
这样来看,好像没有什么思路(大佬看到这就可以走了d=====( ̄▽ ̄*)b),但是,小伙伴们对求导的定义式是否有什么印象呢????
下面我就将求导的定义式及其求导的过程给各位搬过来了( ̄▽ ̄):
考察下面(二元函数导数)的定义:
lim⁡△t→ 0△f△t=lim⁡△t→ 0f(x+△t)−f(x)△t=f(x)′\begin{matrix} \lim_{\triangle t \to \ 0} \frac{\triangle f}{\triangle t}=\end{matrix} \begin{matrix} \lim_{\triangle t \to \ 0} \frac{f(x+\triangle t)-f(x)}{\triangle t}=\end{matrix}f(x)\primelimt 0tf=limt 0tf(x+t)f(x)=f(x)
如果我们上述的题目所给的式子看成f(x)=(x3)f(x)=(\sqrt[3]{x})f(x)=(3x)△t=10−15\triangle t = 10^{-15}t=1015
这一题是不是就可以看成从题目给的下限到上限的求导的和了呢(最后的答案应该需要乘上△t \triangle t t

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int N = 1e6+10;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int MOD=1e9+7;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Abs(x) ((x)>=0?(x):-(x))
double low,up;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE
    while(scanf("%lf%lf",&low,&up)!=EOF,low+up){
        double t=1e-15;
        double ans=0;
        for(double i=low;i<=up;i++){
            ans+=pow(i,-0.66666666666);
        }
        ans*=0.333333333;
        printf("%.5fE-015\n",ans);
    }
    return 0;
 }

emmmmm,排版没有排好,下次改进ε=ε=ε=( ̄▽ ̄)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值