回答編集履歴
2
test
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
```c
|
4
4
|
#include <stdio.h>
|
5
5
|
#include <stdlib.h>
|
6
|
-
#include <stdbool.h>
|
7
6
|
#include <float.h>
|
8
7
|
#include <gmp.h>
|
9
8
|
|
@@ -18,7 +17,7 @@
|
|
18
17
|
{
|
19
18
|
save_result_to_file(&permutation, "output1.csv");
|
20
19
|
save_result_to_file(&combination, "output2.csv");
|
21
|
-
}
|
20
|
+
}
|
22
21
|
|
23
22
|
void save_result_to_file(void (*func)(uint, uint, mpz_t*), char *file_name) {
|
24
23
|
FILE *fp = fopen(file_name, "w");
|
@@ -30,7 +29,6 @@
|
|
30
29
|
uint j, k;
|
31
30
|
mpz_t result, overflow;
|
32
31
|
mpf_t tmp_float;
|
33
|
-
bool is_overflow;
|
34
32
|
char result_type = (func == &permutation) ? 'P' : 'C';
|
35
33
|
char *result_str;
|
36
34
|
|
@@ -40,9 +38,8 @@
|
|
40
38
|
for (j = 0; j <= 100; j++)
|
41
39
|
for (k = 0; k <= j; k++) {
|
42
40
|
(*func)(j, k, &result);
|
43
|
-
is_overflow = false;
|
44
41
|
if (mpz_cmp(result, overflow) > 0) {
|
45
|
-
|
42
|
+
result_str = NULL;
|
46
43
|
} else if (mpz_cmp_ui(result, LIMIT) > 0) {
|
47
44
|
mpf_set_z(tmp_float, result);
|
48
45
|
gmp_asprintf(&result_str, "%.4FE", tmp_float);
|
@@ -50,14 +47,14 @@
|
|
50
47
|
result_str = mpz_get_str(NULL, 10, result);
|
51
48
|
}
|
52
49
|
fprintf(fp, "%d%c%d,%s\n", j, result_type, k,
|
53
|
-
|
50
|
+
result_str ? result_str : "#NUM!");
|
54
51
|
free(result_str);
|
55
52
|
}
|
56
53
|
fclose(fp);
|
57
54
|
mpz_clear(result);
|
58
55
|
mpz_clear(overflow);
|
59
56
|
mpf_clear(tmp_float);
|
60
|
-
}
|
57
|
+
}
|
61
58
|
|
62
59
|
void permutation(uint m, uint n, mpz_t *r) {
|
63
60
|
if (m == 0 || n == 0) {
|
@@ -83,4 +80,3 @@
|
|
83
80
|
return;
|
84
81
|
}
|
85
82
|
```
|
86
|
-
|
1
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
uint j, k;
|
31
31
|
mpz_t result, overflow;
|
32
32
|
mpf_t tmp_float;
|
33
|
-
bool is_overflow
|
33
|
+
bool is_overflow;
|
34
34
|
char result_type = (func == &permutation) ? 'P' : 'C';
|
35
35
|
char *result_str;
|
36
36
|
|
@@ -40,6 +40,7 @@
|
|
40
40
|
for (j = 0; j <= 100; j++)
|
41
41
|
for (k = 0; k <= j; k++) {
|
42
42
|
(*func)(j, k, &result);
|
43
|
+
is_overflow = false;
|
43
44
|
if (mpz_cmp(result, overflow) > 0) {
|
44
45
|
is_overflow = true;
|
45
46
|
} else if (mpz_cmp_ui(result, LIMIT) > 0) {
|