找回密码
 注册
Simdroid-非首页
查看: 95|回复: 2

[欧拉习题] ProjEuler[40]:把数字列为一排……

[复制链接]
发表于 2009-12-15 18:11:00 | 显示全部楼层 |阅读模式 来自 甘肃兰州
An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021...

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

If d_(n) represents the n^(th) digit of the fractional part, find the value of the following expression.

d_(1) × d_(10) × d_(100) × d_(1000) × d_(10000) × d_(100000) × d_(1000000

把数字从1开始按从小到大的顺序排成一列,求出其中第1,10,100,1000,10000,100000,1000000位(从左算起)之积。
 楼主| 发表于 2009-12-15 18:13:23 | 显示全部楼层 来自 甘肃兰州
Simdroid开发平台
本帖最后由 jimogsh 于 2009-12-15 18:17 编辑
  1. Times @@ (Flatten[IntegerDigits /@ Range[10^6]][[10^
  2.      Range[0, 6]]]) // Timing
复制代码
本来想写一个规则的,结果觉得太复杂了,就用这个笨办法了。
在网上找到这个代码,看起来思路和我的是一样的,然而运行却报错了,不过却也得出了正确的答案。
  1. In[4]:= Product[t[[10^i]], {i, 0, 6}] /.
  2.   t -> Flatten@Table[IntegerDigits[m], {m, 1000000}] // Timing

  3. During evaluation of In[4]:= Part::partd: Part specification t[[1]] is longer than depth of object. >>

  4. During evaluation of In[4]:= Part::partd: Part specification t[[10]] is longer than depth of object. >>

  5. During evaluation of In[4]:= Part::partd: Part specification t[[100]] is longer than depth of object. >>

  6. During evaluation of In[4]:= General::stop: Further output of Part::partd will be suppressed during this calculation. >>

  7. Out[4]= {3.947, 210}
复制代码
回复 不支持

使用道具 举报

发表于 2009-12-15 19:02:02 | 显示全部楼层 来自 上海宝山区
40 should be not difficult, tuning your code.

  1. list = Flatten[IntegerDigits /@ Table[n, {n, 2*10^5}], 1];
  2. Times @@ Flatten[Take[list, {#}] & /@ Table[10^i, {i, 0, 6}]]
复制代码
回复 不支持

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|小黑屋|联系我们|仿真互动网 ( 京ICP备15048925号-7 )

GMT+8, 2024-3-29 13:03 , Processed in 0.032721 second(s), 14 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表