log2对数表:
https://zh.arslanbar.net/post.php?t=24047【代码】
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define log2(x) (log10((double)x) / log10(2.0))
int main(void)
{
int m, n;
int i, j;
int *nums;
int *L, *R;
int sum;
scanf("%d%d", &n, &m);
nums = (int *)malloc(n * sizeof(int));
L = (int *)malloc(m * sizeof(int));
R = (int *)malloc(m * sizeof(int));
for (i = 0; i < n; i++)
scanf("%d", nums + i);
for (i = 0; i < m; i++)
scanf("%d%d", L + i, R + i);
for (i = 0; i < m; i++)
{
for (j = L[i]; j <= R[i]; j++)
nums[j - 1] = (int)floor(log2((double)nums[j - 1]) + 1.0);
sum = 0;
for (j = 0; j < n; j++)
sum += nums[j];
printf("%d\n", sum);
}
free(nums);
free(L);
free(R);
return 0;
}