#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++)
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 |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Incorrect |
2 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |