回答編集履歴
5
return させる
answer
CHANGED
@@ -73,7 +73,8 @@
|
|
73
73
|
long long n;
|
74
74
|
scanf("%lld", &n);
|
75
75
|
if(n<=0){
|
76
|
-
printf("n must be positive.");
|
76
|
+
printf("n must be positive.\n");
|
77
|
+
return 0;
|
77
78
|
}
|
78
79
|
// 10**nを計算しておく
|
79
80
|
mpz_t end_ndigit;
|
4
n>18にも対応
answer
CHANGED
@@ -62,5 +62,47 @@
|
|
62
62
|
printf("%lld\n", x / 3LL); //最後nよりも1桁多い最小のxだから割る3
|
63
63
|
return 0;
|
64
64
|
}
|
65
|
+
```
|
66
|
+
GNU MPで組んでみました
|
67
|
+
```C
|
68
|
+
#include <gmp.h>
|
69
|
+
#include <stdio.h>
|
65
70
|
|
71
|
+
int main(void)
|
72
|
+
{
|
73
|
+
long long n;
|
74
|
+
scanf("%lld", &n);
|
75
|
+
if(n<=0){
|
76
|
+
printf("n must be positive.");
|
77
|
+
}
|
78
|
+
// 10**nを計算しておく
|
79
|
+
mpz_t end_ndigit;
|
80
|
+
mpz_init(end_ndigit);
|
81
|
+
mpz_set_ui(end_ndigit, 1);
|
82
|
+
for (long long i = 0; i < n; i++) {
|
83
|
+
mpz_mul_ui(end_ndigit, end_ndigit, 10);
|
84
|
+
}
|
85
|
+
|
86
|
+
// 3をかけ続け, 桁数がnを超えたら抜ける
|
87
|
+
mpz_t x;
|
88
|
+
mpz_init(x);
|
89
|
+
mpz_set_ui(x, 1);
|
90
|
+
while (mpz_cmp(x, end_ndigit) < 0) {
|
91
|
+
mpz_mul_ui(x, x, 3);
|
92
|
+
}
|
93
|
+
|
94
|
+
// 答え
|
95
|
+
mpz_cdiv_q_ui(x, x, 3);
|
96
|
+
gmp_printf("%Zd\n", x);
|
97
|
+
|
98
|
+
// 解放
|
99
|
+
mpz_clear(x);
|
100
|
+
mpz_clear(end_ndigit);
|
101
|
+
return 0;
|
102
|
+
}
|
66
|
-
```
|
103
|
+
```
|
104
|
+
```text
|
105
|
+
80
|
106
|
+
47780373265559358009192445772039644256794138579444188363337645975725833060824587
|
107
|
+
```
|
108
|
+

|
3
整形
answer
CHANGED
@@ -35,6 +35,7 @@
|
|
35
35
|
|
36
36
|
私の実装例
|
37
37
|
```
|
38
|
+
#include <assert.h>
|
38
39
|
#include <stdio.h>
|
39
40
|
|
40
41
|
int main(void)
|
@@ -42,8 +43,8 @@
|
|
42
43
|
long long n;
|
43
44
|
scanf("%lld", &n);
|
44
45
|
|
45
|
-
if(n<=0 || n >= 18){
|
46
|
+
if (n <= 0 || n >= 18) {
|
46
|
-
printf("範囲外です
|
47
|
+
printf("範囲外です");
|
47
48
|
return 0;
|
48
49
|
}
|
49
50
|
|
@@ -54,11 +55,12 @@
|
|
54
55
|
}
|
55
56
|
|
56
57
|
long long x = 1LL;
|
57
|
-
while(x < end_ndigit) {
|
58
|
+
while (x < end_ndigit) {
|
58
59
|
x *= 3LL;
|
59
60
|
}
|
60
61
|
|
61
62
|
printf("%lld\n", x / 3LL); //最後nよりも1桁多い最小のxだから割る3
|
62
63
|
return 0;
|
63
64
|
}
|
65
|
+
|
64
66
|
```
|
2
自分の実装例
answer
CHANGED
@@ -31,4 +31,34 @@
|
|
31
31
|
printf("%lld\n", x/3LL); //最後nよりも1桁多い最小のxだから割る3
|
32
32
|
return 0;
|
33
33
|
}
|
34
|
+
```
|
35
|
+
|
36
|
+
私の実装例
|
37
|
+
```
|
38
|
+
#include <stdio.h>
|
39
|
+
|
40
|
+
int main(void)
|
41
|
+
{
|
42
|
+
long long n;
|
43
|
+
scanf("%lld", &n);
|
44
|
+
|
45
|
+
if(n<=0 || n >= 18){
|
46
|
+
printf("範囲外です\n");
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
|
50
|
+
long long end_ndigit = 1;
|
51
|
+
|
52
|
+
for (long long i = 0; i < n; i++) {
|
53
|
+
end_ndigit *= 10LL;
|
54
|
+
}
|
55
|
+
|
56
|
+
long long x = 1LL;
|
57
|
+
while(x < end_ndigit) {
|
58
|
+
x *= 3LL;
|
59
|
+
}
|
60
|
+
|
61
|
+
printf("%lld\n", x / 3LL); //最後nよりも1桁多い最小のxだから割る3
|
62
|
+
return 0;
|
63
|
+
}
|
34
64
|
```
|
1
コード修正
answer
CHANGED
@@ -15,7 +15,6 @@
|
|
15
15
|
|
16
16
|
for (long long i = 0; i < 1000; i++) {
|
17
17
|
x = x * 3LL;
|
18
|
-
printf("%lld\n", x);
|
19
18
|
|
20
19
|
long long xtemp = x;
|
21
20
|
long long digit = 0;
|