回答編集履歴
5
return させる
test
CHANGED
@@ -148,7 +148,9 @@
|
|
148
148
|
|
149
149
|
if(n<=0){
|
150
150
|
|
151
|
-
printf("n must be positive.");
|
151
|
+
printf("n must be positive.\n");
|
152
|
+
|
153
|
+
return 0;
|
152
154
|
|
153
155
|
}
|
154
156
|
|
4
n>18にも対応
test
CHANGED
@@ -126,6 +126,90 @@
|
|
126
126
|
|
127
127
|
}
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
```
|
129
|
+
```
|
130
|
+
|
131
|
+
GNU MPで組んでみました
|
132
|
+
|
133
|
+
```C
|
134
|
+
|
135
|
+
#include <gmp.h>
|
136
|
+
|
137
|
+
#include <stdio.h>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
int main(void)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
long long n;
|
146
|
+
|
147
|
+
scanf("%lld", &n);
|
148
|
+
|
149
|
+
if(n<=0){
|
150
|
+
|
151
|
+
printf("n must be positive.");
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
// 10**nを計算しておく
|
156
|
+
|
157
|
+
mpz_t end_ndigit;
|
158
|
+
|
159
|
+
mpz_init(end_ndigit);
|
160
|
+
|
161
|
+
mpz_set_ui(end_ndigit, 1);
|
162
|
+
|
163
|
+
for (long long i = 0; i < n; i++) {
|
164
|
+
|
165
|
+
mpz_mul_ui(end_ndigit, end_ndigit, 10);
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
// 3をかけ続け, 桁数がnを超えたら抜ける
|
172
|
+
|
173
|
+
mpz_t x;
|
174
|
+
|
175
|
+
mpz_init(x);
|
176
|
+
|
177
|
+
mpz_set_ui(x, 1);
|
178
|
+
|
179
|
+
while (mpz_cmp(x, end_ndigit) < 0) {
|
180
|
+
|
181
|
+
mpz_mul_ui(x, x, 3);
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
// 答え
|
188
|
+
|
189
|
+
mpz_cdiv_q_ui(x, x, 3);
|
190
|
+
|
191
|
+
gmp_printf("%Zd\n", x);
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
// 解放
|
196
|
+
|
197
|
+
mpz_clear(x);
|
198
|
+
|
199
|
+
mpz_clear(end_ndigit);
|
200
|
+
|
201
|
+
return 0;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
```text
|
208
|
+
|
209
|
+
80
|
210
|
+
|
211
|
+
47780373265559358009192445772039644256794138579444188363337645975725833060824587
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
![イメージ説明](4249f88b2fe2b8181b654cb11e69c7fa.png)
|
3
整形
test
CHANGED
@@ -72,6 +72,8 @@
|
|
72
72
|
|
73
73
|
```
|
74
74
|
|
75
|
+
#include <assert.h>
|
76
|
+
|
75
77
|
#include <stdio.h>
|
76
78
|
|
77
79
|
|
@@ -86,9 +88,9 @@
|
|
86
88
|
|
87
89
|
|
88
90
|
|
89
|
-
if(n<=0 || n >= 18){
|
91
|
+
if (n <= 0 || n >= 18) {
|
90
92
|
|
91
|
-
printf("範囲外です
|
93
|
+
printf("範囲外です");
|
92
94
|
|
93
95
|
return 0;
|
94
96
|
|
@@ -110,7 +112,7 @@
|
|
110
112
|
|
111
113
|
long long x = 1LL;
|
112
114
|
|
113
|
-
while(x < end_ndigit) {
|
115
|
+
while (x < end_ndigit) {
|
114
116
|
|
115
117
|
x *= 3LL;
|
116
118
|
|
@@ -124,4 +126,6 @@
|
|
124
126
|
|
125
127
|
}
|
126
128
|
|
129
|
+
|
130
|
+
|
127
131
|
```
|
2
自分の実装例
test
CHANGED
@@ -65,3 +65,63 @@
|
|
65
65
|
}
|
66
66
|
|
67
67
|
```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
私の実装例
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
#include <stdio.h>
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
int main(void)
|
80
|
+
|
81
|
+
{
|
82
|
+
|
83
|
+
long long n;
|
84
|
+
|
85
|
+
scanf("%lld", &n);
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
if(n<=0 || n >= 18){
|
90
|
+
|
91
|
+
printf("範囲外です\n");
|
92
|
+
|
93
|
+
return 0;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
long long end_ndigit = 1;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
for (long long i = 0; i < n; i++) {
|
104
|
+
|
105
|
+
end_ndigit *= 10LL;
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
long long x = 1LL;
|
112
|
+
|
113
|
+
while(x < end_ndigit) {
|
114
|
+
|
115
|
+
x *= 3LL;
|
116
|
+
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
printf("%lld\n", x / 3LL); //最後nよりも1桁多い最小のxだから割る3
|
122
|
+
|
123
|
+
return 0;
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
```
|
1
コード修正
test
CHANGED
@@ -32,8 +32,6 @@
|
|
32
32
|
|
33
33
|
x = x * 3LL;
|
34
34
|
|
35
|
-
printf("%lld\n", x);
|
36
|
-
|
37
35
|
|
38
36
|
|
39
37
|
long long xtemp = x;
|