/* 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. * * What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?*/ #define _POSIX_C_SOURCE 199309L #include #include #include #include "projecteuler.h" int main(int argc, char **argv) { long int res, n[20] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; double elapsed; struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); /* Function define in projecteuler.c to find the least common multiple of multiple numbers.*/ res = lcmm(n, 20); clock_gettime(CLOCK_MONOTONIC, &end); elapsed = (end.tv_sec - start.tv_sec) + (double)(end.tv_nsec - start.tv_nsec) / 1000000000; printf("Project Euler, Problem 5\n"); printf("Answer: %ld\n", res); printf("Elapsed time: %.9lf seconds\n", elapsed); return 0; }