您的位置:首页 > 其它

(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

d10

d100

d1000

d10000

d100000

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: