1
0
Fork 0

Problem 40

This commit is contained in:
Jonathan Chan 2016-12-06 10:42:28 -08:00
parent 47cda7eff3
commit e8a4a63635
2 changed files with 26 additions and 0 deletions

BIN
40 Executable file

Binary file not shown.

26
40.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int champernowneDigit (int n) {
int d = 1;
int next = 9;
while (n > next) {
n -= next;
next = 9 * ++d * (int) pow (10, d - 1);
}
for (int k = 1; k <= d; k++) {
if ((n - k) % d == 0) {
return (((n - k) / (d * (int) pow (10, d - k))) % 10) + (k == 1 ? 1 : 0);
}
}
}
int main () {
int product = 1;
for (int i = 1; i <= 1000000; i *= 10) {
product *= champernowneDigit (i);
}
printf ("%d\n", product);
}