#include <stdio.h>
#include <string.h>
#define N 111
#define D 10
int main() {
static char cc[N + 1];
static int aa[N * 2], bb[N * 2], tt[N * 2];
int n, h, i, j, r, k;
scanf("%s", cc), n = strlen(cc);
for (i = 0; i < n; i++)
aa[i] = cc[n - 1 - i] - '0';
for (h = N - 1; h >= 0; h--) {
for (bb[h] = 1; bb[h] < D; bb[h]++) {
memset(tt, 0, N * 2 * sizeof *tt);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
tt[i + j] += bb[i] * bb[j];
for (i = 0; i < N; i++)
tt[i] += bb[i];
for (i = 0; i < N * 2; i++)
if (tt[i] >= D)
tt[i + 1] += tt[i] / D, tt[i] %= D;
r = 0;
for (i = N * 2 - 1; i >= 0; i--) {
r = r * D + tt[i];
tt[i] = r / 2, r %= 2;
}
for (i = N * 2 - 1; i >= 0; i--)
if (tt[i] != aa[i]) {
if (tt[i] > aa[i])
goto out;
break;
}
if (i < 0)
goto out;
}
out:
bb[h]--;
}
for (i = 0; i < N; i++)
aa[i] *= 2;
for (i = 0; i < N; i++)
if (aa[i] >= D)
aa[i] -= D, aa[i + 1]++;
for (i = 0; i < N; i++)
aa[i] -= bb[i];
aa[0]--;
for (i = 0; i < N; i++)
if (aa[i] < 0) {
k = (-aa[i] + 9) / D;
aa[i] += k * D, aa[i + 1] -= k;
}
i = N - 1;
while (aa[i] == 0)
i--;
while (i >= 0)
printf("%d", aa[i--]);
printf("\n");
return 0;
}
Compilation message
oddeven.c: In function 'main':
oddeven.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%s", cc), n = strlen(cc);
| ^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
2 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
2 ms |
212 KB |
Output is correct |
15 |
Correct |
3 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
6 ms |
288 KB |
Output is correct |
18 |
Correct |
5 ms |
292 KB |
Output is correct |
19 |
Correct |
5 ms |
212 KB |
Output is correct |
20 |
Correct |
5 ms |
292 KB |
Output is correct |
21 |
Correct |
5 ms |
212 KB |
Output is correct |
22 |
Correct |
5 ms |
288 KB |
Output is correct |