July 2021

C - Doctor Differentiation

Solution

\[\]

Example

\[\]

Implementation

#include <stdio.h>
#include <math.h>

int main() {
    int t, n, m, k, i, j, ans;
    scanf("%d", &t);
    
    int a[10]; // This array is used to store
    int p[10]; // This array is used to store the powers
    
    while (t--) {
        scanf("%d%d%d", &n, &m, &k);
        
        for (i = 0; i < n; i++)
            scanf("%d", &a[i]);
        
        for (i = 0; i < n; i++)
            p[i] = n-i-1;
        
        //Multiply the power and the coefficient and decrement power
        for (i = 0; i < m; i++)
            for (j = 0; j < n; j++) {
                a[j] *= p[j];
                p[j]--;
            }
        
        ans = 0;
        
        for (i = 0; i < n; i++)
            if (p[i] >= 0)
                ans += a[i]*pow(k, p[i]);
        
        printf("%d\n", ans);
    }
    
    return 0;
}
\[\]

Contest Material