绑定此程序以确定不包含零的倒数整数之和 [英] Bounding this program to determine the sum of reciprocal integers not containing zero

查看:163
本文介绍了绑定此程序以确定不包含零的倒数整数之和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A 表示正整数的集合,其十进制表示不包含数字0. 中元素的倒数之和已知 为23.10345。

Let A denote the set of positive integers whose decimal representation does not contain the digit 0. The sum of the reciprocals of the elements in A is known to be 23.10345.

Ex。 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,...

Ex. 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, ...

然后取每个数字的倒数,并计算总数。

Then take the reciprocal of each number, and sum the total.

如何通过数字验证?

编写一个计算机程序来验证这个数字。

Write a computer program to verify this number.

这是到目前为止我写的内容,我需要帮助限制这个问题,因为这需要很长时间才能完成:

Here is what I have written so far, I need help bounding this problem as this currently takes too long to complete:

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);
        }
    }
}


推荐答案

正确接近时并不难。

假设您想要找到所有整数开始的倒数之和(即最左侧)数字)123,以k非零数字结尾。显然有9个 k 这样的整数,这些整数的倒数在1 /(124 * 10 k )范围内.1 /(123 * 10 < SUP>ķ)。因此,所有这些整数的倒数之和受(9/10) k / 124和(9/10) k / 123的限制。

Assume for example that you want to find the sum of reciprocals of all integers starting (i.e. the left-most digits) with 123 and ending with k non-zero digits. Obviously there are 9k such integers and the reciprocal of each of these integers is in the range 1/(124*10k) .. 1/(123*10k). Hence the sum of reciprocals of all these integers is bounded by (9/10)k/124 and (9/10)k/123.

要找到以123开头的所有倒数之和的边界,必须将每个k> = 0的上限加起来。这是一个几何系列,因此可以推导出以123开头的整数倒数之和受10 *(9/10) k / 124和10 *(9/10)<的限制sup> k / 123。

To find bounds for sum of all reciprocals starting with 123 one has to add up the bounds above for every k>=0. This is a geometric serie, hence it can be derived that the sum of reciprocals of integers starting with 123 is bounded by 10*(9/10)k/124 and 10*(9/10)k/123.

同样的方法当然可以应用于最左边数字的任何组合。
我们在左侧检查的位数越多,结果就越准确。
这是python中这种方法的实现:

The same method can of course be applied for any combination of left-most digits. The more digits we examine on the left, the more accurate the result becomes. Here is an implementation of this approach in 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

例如,调用约(0,8)给出下限和上限:
23.103447707 ......和23.103448107 ....
接近OP给出的索赔23.10345。

Calling approx(0, 8) for example gives the lower and upper bound: 23.103447707... and 23.103448107.... which is close to the claim 23.10345 given by the OP.

有些方法会更快收敛到有问题的总和,但它们需要更多的数学。
可以在此处找到更好的近似值。问题的一般化是肯普纳系列

There are methods that converge faster to the sum in question, but they require more math. A much better approximation of the sum can be found here. A generalization of the problem are the Kempner series.

这篇关于绑定此程序以确定不包含零的倒数整数之和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆