42 lines
932 B
C
42 lines
932 B
C
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#define LOOP_COUNT 1000000
|
|
#define EXPECTED_CHECKSUM 3875011
|
|
|
|
struct array_record {
|
|
int32_t digits[8];
|
|
};
|
|
|
|
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 struct array_record make_record(void) {
|
|
return (struct array_record){.digits = {3, 1, 4, 1, 5, 9, 2, 6}};
|
|
}
|
|
|
|
static int32_t array_struct_field_loop(int32_t limit) {
|
|
struct array_record record = make_record();
|
|
int32_t i = 0;
|
|
int32_t acc = 11;
|
|
|
|
while (i < limit) {
|
|
acc = acc + record.digits[i % 8];
|
|
acc = acc > 1000000000 ? acc - 1000000000 : acc;
|
|
i = i + 1;
|
|
}
|
|
|
|
return acc;
|
|
}
|
|
|
|
int main(void) {
|
|
int32_t result = array_struct_field_loop(configured_loop_count());
|
|
printf("%d\n", result);
|
|
return result == EXPECTED_CHECKSUM ? 0 : 1;
|
|
}
|