summaryrefslogtreecommitdiff
path: root/p5/main.c
blob: 47759c4d08ef39732a53468d6ad278aeaa734bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}