1 solutions

  • 0
    @ 2023-10-21 12:48:49
    #include <stdio.h>
    int main()
    {
        int n,m,k,j,f,a,b,d;
        int i = 1;
        int sum = 0;
        scanf("%d", &n);
        scanf("%d", &m);
        k = n / m;
        int num[1000];
        int sum1[1000] = { 0 };
        int sum2[1000] = { 0 };
        for (i = 0; i < n; i++)
        {
            scanf("%d", &num[i]);
        }
        for (i = 0; i < m; i++)
        {
            for (j = i * k; j < k * (i + 1); j++)
                sum1[i] += num[j];
        }
        for (i = 0; i < m; i++)
        {
            printf("%d ", sum1[i]);
        }
        printf("\n");
        for (i = 2;( m / i) != 1; i=i*2)
        {
            for (j = 0; j < m / i; j++)
            {
                for (a = 0; a < i * (j + 1); a++)
                    sum2[j] += sum1[a];
            }
            for (f = (m / i) - 1; f > 0; f--)
                sum2[f] = sum2[f] - sum2[f - 1];
            for (d = 0; d < m / i; d++)
                printf("%d ", sum2[d]);
            printf("\n");
            for (b = 0; b < m; b++)
            {
                sum2[b] = 0;
            }
        }
        for (i = 0; i < m; i++)
            sum += sum1[i];
        printf("%d",sum);
        return 0;
    }
    
    • 1

    Information

    ID
    6660
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    7
    Tags
    (None)
    # Submissions
    63
    Accepted
    17
    Uploaded By