/home/toolbox/public_html/solutions/9/913/a.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 #define MAX_LINE 257
17
18 /*
19 * Author: Isaac Traxler
20 * Date: 2021-11-16
21 * Purpose: fun
22 * Problem: 913 - Joana and the Odd Numbers
23 */
24
25 /*
26 * This template reads lines of data at a time until end of file.
27 */
28
29 /* line num last Values
30 * 1 1 1 1
31 * 2 3 7 3 5 7
32 * 3 5 17 9 11 13 15 17
33 * 4 7 31 19 21 23 25 27 29 31
34 * (line * 2) - 1 == num (number of values per line)
35 * line == (num + 1) / 2
36 *
37 * last = (2 * n * n) - 1
38 *
39 * sum of last 3 == last + (last - 2) + (last - 4)
40 * == 3 * last - 6
41 * == 3 * (last - 2)
42 */
43
44 long long int num;
45
46 void init()
47 {
48 /* FUNCTION init */
49 } /* FUNCTION init */
50
51 void dump()
52 {
53 /* FUNCTION dump */
54 } /* FUNCTION dump */
55
56 int getInput()
57 {
58 /* FUNCTION getInput */
59 int dataReadFlag;
60
61 dataReadFlag = (1 == scanf(" %lld ", &num));
62 return (dataReadFlag);
63 } /* FUNCTION getInput */
64
65 void process()
66 {
67 /* FUNCTION process */
68 long long int n;
69 long long int last;
70 long long int sum3;
71
72 if (1 != (1 & num))
73 {
74 /* even number */
75 sum3 = 0;
76 } /* even number */
77 else
78 {
79 /* odd number */
80 n = (num + 1) / 2;
81 last = (2 * n * n) - 1;
82 sum3 = 3 * (last - 2);
83 } /* odd number */
84 printf("%lld\n", sum3);
85 } /* FUNCTION process */
86
87 int main()
88 {
89 /* main */
90 int moreToDo;
91
92 init();
93 moreToDo = getInput();
94 while (moreToDo)
95 {
96 /* while */
97 process();
98 moreToDo = getInput();
99 } /* while */
100
101 return EXIT_SUCCESS;
102 } /* main */
103