Bob*_*y S 7 java math bounding numerical-analysis numerical-methods
让甲分别表示该组正整数,其十进制表示不包含的元件的倒数之和的第0位甲已知为23.10345.
防爆.1,2,3,4,5,6,7,8,9,11-19,21-29,31-39,41-49,51-59,61-69,71-79,81-89, 91-99,111-119,......
然后取每个数的倒数,并总和.
如何通过数字验证?
编写一个计算机程序来验证这个号码.
以下是我迄今为止写的,我需要帮助的边界这个问题,因为目前这需要很长时间才能完成:
Java中的代码
import java.util.*;
public class recip
{
public static void main(String[] args)
{
int current = 0; double total = 0;
while(total < 23.10245)
{
if(Integer.toString(current).contains("0"))
{
current++;
}
else
{
total = total + (1/(double)current);
current++;
}
System.out.println("Total: " + total);
}
}
}
Run Code Online (Sandbox Code Playgroud)
当正确接近时,这并不难.
例如,假设您要查找以123开始并以k非零数字结尾的所有整数的倒数之和(即最左边的数字).显然,存在9k个这样的整数,并且这些整数中的每一个的倒数在1 /(124*10k)... 1 /(123*10k)的范围内.因此,所有这些整数的倒数之和受(9/10)k/124和(9/10)k/123的限制.
为了找到以123开始的所有倒数之和的界限,必须将每个k> = 0的上限加起来.这是几何系列,因此可以推导出以123开始的整数倒数之和由10*(9/10)k/124和10*(9/10)k/123 限定.
当然,相同的方法可以应用于最左边数字的任何组合.我们在左侧检查的位数越多,结果就越准确.这是python中这种方法的实现:
def approx(t,k):
"""Returns a lower bound and an upper bound on the sum of reciprocals of
positive integers starting with t not containing 0 in its decimal
representation.
k is the recursion depth of the search, i.e. we append k more digits
to t, before approximating the sum. A larger k gives more accurate
results, but takes longer."""
if k == 0:
return 10.0/(t+1), 10.0/t
else:
if t > 0:
low, up = 1.0/t, 1.0/t
else:
low, up = 0, 0
for i in range(10*t+1, 10*t+10):
l,u = approx(i, k-1)
low += l
up += u
return low, up
Run Code Online (Sandbox Code Playgroud)
例如,调用约(0,8)给出下限和上限:23.103447707 ......和23.103448107 ....这与OP给出的索赔23.10345很接近.
有些方法可以更快收敛到所讨论的总和,但它们需要更多的数学运算.可以在这里找到更好的近似值.问题的一般化是肯普纳系列.
| 归档时间: |
|
| 查看次数: |
3107 次 |
| 最近记录: |