Ian Dorian Macleod
Problem 40
Problem Statement

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 $\times$ d10 $\times$ d100 $\times$ d1000 $\times$ d10000 $\times$ d100000 $\times$ d1000000

Approach

C++ implementation

#include <stdc++.h>

using namespace std;

int champernownes() {
vectornums;
int ans = 1;
nums.push_back(0);
int count = 1;
int i = 1;
while(count <= 1000000) {
string tmp = to_string(i);
while(tmp.length() != 0) {
if (count == 1 || count == 10 || count == 100 || count == 1000
|| count == 10000 || count == 100000 || count == 1000000) {
ans *= ((int)tmp[0]-48);
}
tmp = tmp.substr(1, tmp.length()-1);
count++;
}
i++;
}
return ans;
}

int main() {
cout << champernownes() << endl;
return 0;
}


You can also download the source code for this problem here and compile it on your local machine.
Further Analysis