diff options
Diffstat (limited to 'p5')
| -rw-r--r-- | p5/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | p5/main.c | 42 |
2 files changed, 49 insertions, 0 deletions
diff --git a/p5/CMakeLists.txt b/p5/CMakeLists.txt new file mode 100644 index 0000000..5a700c8 --- /dev/null +++ b/p5/CMakeLists.txt @@ -0,0 +1,7 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +PROJECT(euler_problem5 C) +INCLUDE_DIRECTORIES(../common) +SET(SOURCES main.c ../common/utils.c) +ADD_EXECUTABLE(p5 ${SOURCES}) +TARGET_LINK_LIBRARIES(p5 m) +SET_SOURCE_FILES_PROPERTIES(${SOURCES} PROPERTIES COMPILE_FLAGS -g) diff --git a/p5/main.c b/p5/main.c new file mode 100644 index 0000000..47759c4 --- /dev/null +++ b/p5/main.c @@ -0,0 +1,42 @@ +#include <stdio.h> +#include <stdlib.h> + +void basic() +{ + long int i = 0; + long int j; + int done = 0; + + while (!done) + { + i += 20; + + done = 1; + + // 20 (2*2*5) 2, 4, 10, 20 + // 19 + // 18 (2*3*3) 2, 6, 9, 18 + // 17 + // 16 (2*2*2*2) 2, 4, 8, 16 + // 15 (3*5) 3, 5 + // 14 (2*7) 2, 7 + // 13 + // 12 (2*2*3) 2, 3 + // 11 + // no need to check for 1-9, because they are included in the + // numbers above + + for (j = 11; j <= 20 && done; ++j) + { + done = done && (i % j == 0); + } + } + + printf("%ld\n", i); +} + +int main(int argc, char **argv) +{ + basic(); + return 0; +}
\ No newline at end of file |
