首页 > 其他 > 详细

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

时间:2015-07-18 02:05:10      阅读:239      评论:0      收藏:0      [点我收藏+]

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)

版权声明:本文为博主原创文章,未经博主允许不得转载。

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

原文:http://blog.csdn.net/zhangzhengyi03539/article/details/46935413

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!