diff options
Diffstat (limited to '2023/06/6a.c')
| -rw-r--r-- | 2023/06/6a.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/2023/06/6a.c b/2023/06/6a.c new file mode 100644 index 0000000..4ce8fd1 --- /dev/null +++ b/2023/06/6a.c | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | #include <inttypes.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdbool.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | |||
| 8 | #define N 100000 | ||
| 9 | |||
| 10 | #define MIN(a, b) ((a)<(b)?(a):(b)) | ||
| 11 | #define MAX(a, b) ((a)>(b)?(a):(b)) | ||
| 12 | |||
| 13 | bool isnum(char c) { return c >= '0' && c <= '9'; } | ||
| 14 | |||
| 15 | int64_t readl(int64_t nums[], char *buf) { | ||
| 16 | int64_t i; | ||
| 17 | for (i = 0; *buf; buf++) { | ||
| 18 | if (!isnum(*buf)) continue; | ||
| 19 | nums[i++] = atoll(buf); | ||
| 20 | while (isnum(*buf)) buf++; | ||
| 21 | } | ||
| 22 | return i; | ||
| 23 | } | ||
| 24 | |||
| 25 | int main() { | ||
| 26 | char line[N], clean[N]; | ||
| 27 | int64_t i, n, p, D, x1, x2, t[N], d[N]; | ||
| 28 | |||
| 29 | n = readl(t, fgets(line, N, stdin)); | ||
| 30 | readl(d, fgets(line, N, stdin)); | ||
| 31 | |||
| 32 | p = 1; | ||
| 33 | for (i = 0; i < n; i++) { | ||
| 34 | D = t[i]*t[i] - 4*d[i]; | ||
| 35 | if (D < 0) p = 1; | ||
| 36 | double sq = sqrt(D); | ||
| 37 | x1 = (int64_t)floor((t[i] - sq)/2) + 1; | ||
| 38 | x2 = (int64_t)ceil((t[i] + sq)/2) - 1; | ||
| 39 | p *= x2 - x1 + 1; | ||
| 40 | } | ||
| 41 | |||
| 42 | printf("%" PRId64 "\n", p); | ||
| 43 | return 0; | ||
| 44 | } | ||
