/home/toolbox/public_html/solutions/114/11417/b.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9 #include <ctype.h>
10
11 #define TRUE (1 == 1)
12 #define FALSE (1 != 1)
13
14 #define DEBUG if (FALSE)
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2022-10-04
19 * Purpose: fun
20 * Problem: 11417
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 #define TOP 501
28
29 int ans[TOP+1];
30 int n;
31
32 int gcd(int a, int b)
33 {
34 /* FUNCTION gcd */
35 /* this uses Euclid's method */
36 int toReturn;
37
38 if (0 == b)
39 toReturn = a;
40 else
41 toReturn = gcd(b, (a % b));
42 return toReturn;
43 } /* FUNCTION gcd */
44
45 void init()
46 {
47 /* FUNCTION init */
48 int i;
49 int j;
50 int tmp;
51
52 ans[0] = 0;
53 ans[1] = 0;
54 ans[2] = 1;
55 for (i=3; TOP>i; i++)
56 {
57 /* for i */
58 tmp = ans[i-1];
59 for (j=i+1; TOP>=j; j++)
60 {
61 /* for j */
62 printf("(i %d) (j %d) (tmp %d)\n", i, j, tmp);
63 tmp = tmp + gcd(j, i);
64 } /* for j */
65 ans[i] = tmp;
66 } /* for i */
67 } /* FUNCTION init */
68
69 void dump()
70 {
71 /* FUNCTION dump */
72 } /* FUNCTION dump */
73
74 int getInput()
75 {
76 /* FUNCTION getInput */
77 int dataReadFlag;
78
79 scanf(" %d ", &n);
80 dataReadFlag = 0 != n;
81 return (dataReadFlag);
82 } /* FUNCTION getInput */
83
84 void process()
85 {
86 /* FUNCTION process */
87 printf("%d\n", ans[n]);
88 } /* FUNCTION process */
89
90 int main()
91 {
92 /* main */
93 int moreToDo;
94
95 init();
96 moreToDo = getInput();
97 while (moreToDo)
98 {
99 /* while */
100 process();
101 moreToDo = getInput();
102 } /* while */
103
104 return EXIT_SUCCESS;
105 } /* main */
106