- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem040.cpp
More file actions
Latest commit
30 lines (28 loc) · 609 Bytes
/
Copy pathproblem040.cpp
File metadata and controls
30 lines (28 loc) · 609 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<cmath>
#include<iostream>
intchampernowneNthDigit(int n)
{
int digits = 0;
int upperVal = 1;
int upperIndex = 0;
do {
++digits;
upperIndex += 9 * upperVal * digits;
upperVal *= 10;
} while (n > upperIndex);
int dist = upperIndex - n;
int val = upperVal - dist / digits - 1;
int div = pow(10, dist % digits);
return val / div % 10;
}
intmain()
{
int ans = 1;
int n = 1;
for (int i = 0; i < 7; ++i) {
ans *= champernowneNthDigit(n);
n *= 10;
}
std::cout << "Answer: " << ans << '\n';
return0;
}