EularProject 40: 计算正整数连接构成无理数的确定位

Champernowne’s constant
Problem 40
An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021…

It can be seen that the 12th digit of the fractional part is 1.

If dn represents the nth digit of the fractional part, find the value of the following expression.

d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000

Answer:
210
Completed on Fri, 17 Jul 2015, 18:25
Go to the thread for problem 40 in the forum.

python code:

__author__ = 'zhengyi'

def funcNum(x):
    k=0
    while x>0:
        k+=1
        x=x//10
    return k

def func(d,c,k):
    temp=funcNum(c)
    for i in range(0,d-k):
        c=c//10
    return c%10

c=1
d=1
r=1
index=[pow(10,i) for i in range(1,7)]
while len(index)>0:
    c+=1
    d+=funcNum(c)
    if d==index[0]:
        r*=c%10
        del index[0]
        continue
    else:
        if d>index[0]:
            r=r*func(d,c,index[0])
            del index[0]
print(r)

你可能感兴趣的:(欧拉计划)