34 lines
756 B
C
34 lines
756 B
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#define LOOP_COUNT 1000000
|
|
#define EXPECTED_CHECKSUM 3875007
|
|
|
|
static int32_t configured_loop_count(void) {
|
|
int32_t value = LOOP_COUNT;
|
|
if (scanf("%d", &value) != 1 || value <= 0) {
|
|
return LOOP_COUNT;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
static int32_t array_index_loop(int32_t limit) {
|
|
static const int32_t digits[8] = {3, 1, 4, 1, 5, 9, 2, 6};
|
|
int32_t i = 0;
|
|
int32_t acc = 7;
|
|
|
|
while (i < limit) {
|
|
acc = acc + digits[i % 8];
|
|
acc = acc > 1000000000 ? acc - 1000000000 : acc;
|
|
i = i + 1;
|
|
}
|
|
|
|
return acc;
|
|
}
|
|
|
|
int main(void) {
|
|
int32_t result = array_index_loop(configured_loop_count());
|
|
printf("%d\n", result);
|
|
return result == EXPECTED_CHECKSUM ? 0 : 1;
|
|
}
|