The problem is this http://www.spoj.com/problems/CMPLS/
I thought of implementing newtons divided difference and find out the polynomial. But I am not able to get the correct answer. Some basic test cases are passing but some are not.
# include <stdio.h>
int main()
{
int i, j, k, t, m, x[100][100], s, c, n;
long ans, mul;
scanf ("%d", &t);
while (t--) {
scanf ("%d%d", &s, &c);
n = s;
for (i = 0; i < n; i++)
scanf ("%d", &x[i][0]);
for (j = 1; j < n; j++)
for (i = 0; i < n; i++) {
x[i][j] = x[i+1][j-1] - x[i][j-1];
}
k = n;
printf("\n");
for (i = 0; i < n; i++) {
for(j = 0; j < k; j++)
printf ("%d ", x[i][j]);
printf ("\n");
k--;
}
printf ("\n\n");
for (m = 1; m <= c; m++) {
ans = x[0][0];
for ( i = 1; i < n - 1; i++) {
mul = x[0][i];
for (j = 1; j <= i; j++)
mul = mul * (s + m - j);
ans = ans + mul;
}
printf ("%ld ", ans);
}
printf ("\n");
}
return 0;
}