#include <stdio.h>
#include <string.h>
#define L 256
void mult2(int *aa) {
int h;
for (h = 0; h < L; h++)
if ((aa[h] *= 2) >= 10)
aa[h] -= 10, aa[h + 1]++;
}
void add1(int *aa) {
int h;
aa[0] += 1;
for (h = 0; h < L; h++)
if (aa[h] >= 10)
aa[h] -= 10, aa[h + 1]++;
}
int main() {
static int aa[L];
static char cc[L + 1];
int n, m, l, i, cnt;
scanf("%d%*d", &n);
cnt = 0;
for (m = 1; m < n; m <<= 1)
cnt++;
printf("%d\n", cnt);
for (m = 1; m < n; m <<= 1) {
memset(aa, 0, L * sizeof *aa);
for (i = n - 1; i >= 0; i--) {
mult2(aa);
if (i % (m * 2) < m)
add1(aa);
}
l = L;
while (l > 1 && aa[l - 1] == 0)
l--;
for (i = l - 1; i >= 0; i--)
cc[l - 1 - i] = aa[i] + '0';
cc[l] = 0;
printf("A=((A&%s)+((A>>%d)&%s))\n", cc, m, cc);
}
return 0;
}
Compilation message
popcount.c: In function 'main':
popcount.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d%*d", &n);
| ^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Accepted. |
2 |
Correct |
0 ms |
204 KB |
Accepted. |
3 |
Correct |
0 ms |
204 KB |
Accepted. |
4 |
Incorrect |
0 ms |
204 KB |
Wrong command format. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
268 KB |
Wrong command format. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Accepted. |
2 |
Incorrect |
1 ms |
208 KB |
Wrong command format. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Wrong command format. |
2 |
Halted |
0 ms |
0 KB |
- |