/home/toolbox/public_html/solutions/107/10784/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 /*
17 * Author: Isaac Traxler
18 * Date: 2021-11-05
19 * Purpose: fun
20 * Problem: 10784 - Diagonal
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 /*
28 * 4 5 6 7 8 9 10 11 12 13 14 15 16
29 * 2 5 9 14 20 27 35 44 54 65 77 90 104
30 * diagonals = ((n - 3) * n) / 2
31 * 2 * diagonals = n(n - 3)
32 * 2 * diagonals < n^2
33 * sqrt(2 * sides) < n
34 */
35
36 int cnt;
37 long long num;
38
39 void init()
40 {
41 /* FUNCTION init */
42 cnt = 1;
43 } /* FUNCTION init */
44
45 void dump()
46 {
47 /* FUNCTION dump */
48 } /* FUNCTION dump */
49
50 int getInput()
51 {
52 /* FUNCTION getInput */
53 int dataReadFlag;
54
55 scanf(" %lld ", &num);
56 dataReadFlag = (0 != num);
57 return (dataReadFlag);
58 } /* FUNCTION getInput */
59
60 void process()
61 {
62 /* FUNCTION process */
63 long long tmp;
64
65 num = 2 * num;
66 tmp = sqrt((double) num) + 2;
67 while ((tmp * (tmp - 3)) < num)
68 {
69 tmp++;
70 }
71
72 printf("Case %d: %d\n", cnt, tmp);
73 cnt++;
74 } /* FUNCTION process */
75
76 int main()
77 {
78 /* main */
79 int moreToDo;
80
81 init();
82 moreToDo = getInput();
83 while (moreToDo)
84 {
85 /* while */
86 process();
87 moreToDo = getInput();
88 } /* while */
89
90 return EXIT_SUCCESS;
91 } /* main */
92