/home/toolbox/public_html/solutions/116/11614/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 <stdlib.h>
7 #include <math.h>
8 #include <stdint.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 /* fprintf(stderr, "functionName: message", varslist); */
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2018-10-23
20 * Purpose: fun
21 * Problem: 11614
22 */
23
24 /*
25 * number of warriors on row n = (n * (n+1)) / 2
26 * x = (n^2 + n) / 2
27 * 2x = n^2 + n
28 * 0 = n^2 + n - 2x
29 * for quadratic equation, a=1, b=1, c=-2x
30 * (-b+-sqrt(b^2-4ac)) / 2a becomes
31 * (-1 + sqrt(1 - 4*1*(-2x)) ) / 2*1
32 * (-1 + sqrt(1 + 8x))/2
33 * (sqrt(1+8x) - 1) / 2
34 *
35 * floor(sqrt( 2.0 * n + 0.25 ) + 0.5) - 1
36 */
37
38 /*
39 * This template reads data a specified number of times.
40 */
41
42 int numberOfTimes;
43 long long num;
44
45 void init()
46 {
47 /* FUNCTION init */
48 scanf("%d ", &numberOfTimes);
49 } /* FUNCTION init */
50
51 void dump()
52 {
53 /* FUNCTION dump */
54 } /* FUNCTION dump */
55
56 void getInput()
57 {
58 /* FUNCTION getInput */
59 scanf(" %lld ", &num);
60 } /* FUNCTION getInput */
61
62 void process()
63 {
64 /* FUNCTION process */
65 double tmp;
66 long long ans;
67
68 tmp = num;
69 /* sqrt(1+8x) - 1) / 2 */
70 ans = (sqrt(1 + 8*tmp) - 1)/2;
71 printf("%lld\n", ans);
72
73 } /* FUNCTION process */
74
75 int main()
76 {
77 /* main */
78 int i;
79
80 init();
81 for (i=0; i<numberOfTimes; i++)
82 {
83 /* while */
84 getInput();
85 process();
86 } /* while */
87
88 return EXIT_SUCCESS;
89 } /* main */
90
91