-
Notifications
You must be signed in to change notification settings - Fork 0
/
day06b.c
58 lines (43 loc) · 1003 Bytes
/
day06b.c
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Licensed under the MIT License.
// Wait For It Part 2
#include <math.h>
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#define BUFFER_SIZE 64
static bool read(FILE* stream, long long* result)
{
char buffer[BUFFER_SIZE];
if (!fgets(buffer, sizeof buffer, stream))
{
return false;
}
long long number = 0;
for (char* p = buffer; *p; p++)
{
if (!isdigit(*p))
{
continue;
}
number = (number * 10) + (*p - '0');
}
*result = number;
return true;
}
int main(void)
{
long long t;
long long dx;
clock_t start = clock();
if (!read(stdin, &t) || !read(stdin, &dx))
{
fprintf(stderr, "Error: Format.\n");
return 1;
}
long long result = ceil((t + sqrt(t * t - 4 * dx)) / 2)
- floor((t - sqrt(t * t - 4 * dx)) / 2)
- 1;
printf("06b %lld %lf\n", result, (double)(clock() - start) / CLOCKS_PER_SEC);
return 0;
}