(Problem 40)Champernowne's constant
2014-01-07 23:30
281 查看
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
![](http://projecteuler.net/images/symbol_times.gif)
d10
![](http://projecteuler.net/images/symbol_times.gif)
d100
![](http://projecteuler.net/images/symbol_times.gif)
d1000
![](http://projecteuler.net/images/symbol_times.gif)
d10000
![](http://projecteuler.net/images/symbol_times.gif)
d100000
![](http://projecteuler.net/images/symbol_times.gif)
d1000000
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
![](http://projecteuler.net/images/symbol_times.gif)
d10
![](http://projecteuler.net/images/symbol_times.gif)
d100
![](http://projecteuler.net/images/symbol_times.gif)
d1000
![](http://projecteuler.net/images/symbol_times.gif)
d10000
![](http://projecteuler.net/images/symbol_times.gif)
d100000
![](http://projecteuler.net/images/symbol_times.gif)
d1000000
#include <stdio.h> int solve() { int i, k, result, n, t, temp; int s[8], a[101]; i = k = 0; n = result = 1; t = 0; while(1) { temp = n; i = 0; while(temp) { s[i++] = temp % 10; temp /= 10; } i--; while(i >= 0) { a[k] = s[i]; t++; if(t == 1 || t == 10 || t == 100 || t == 1000 || t == 10000 || t == 100000 || t == 1000000) { result *= a[k]; if(t == 1000000) return result; } if(k == 100) { k = 1; } else { k++; } i--; } n++; } } int main(void) { printf("%d\n",solve()); return 0; }
Answer: | 210 |
相关文章推荐
- 2014第2周二
- 一个艰难的决定
- 常用linux命令
- mean shift tracking
- LinearLayout布局
- Oracle连接查询小结
- Javascript闭包(Closure)
- 20140107
- 记录我喜欢的书及作者
- 【Ogre编程入门与进阶】第三章 Ogre框架配置及概要分析
- 金字塔结构的好处
- ASP.NET反射
- 详解Android应用如何匹配不同的手机分辨率
- 利用Httphandler、UserControl 输出HTML片段
- 超实用的JavaScript技巧及最佳实践(上)
- 在win7—64位上使用DEBUG调试汇编程序
- -_-#【模式】声明依赖关系
- 超实用的JavaScript技巧及最佳实践(下)
- C#调用VC dll输出参数
- 一个有意思的shell――批量添加用户