This is the code:

Code: Select all

```
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_DEGREE 20000
#define MAX_LEN 200000
char input[MAX_LEN];
int main()
{
int i;
long a[MAX_DEGREE];
int k;
int degree;
long r;
int j;
long q[MAX_DEGREE];
long t;
char* p;
int n;
char word[100];
int first = 1;
// freopen("in5.txt", "r", stdin);
while (scanf("%d", &k) != EOF)
{
scanf(" %[^\n]", input);
i = 0;
p = strtok(input, " ");
while (p != NULL)
{
a[i] = atoi(p);
p = strtok(NULL, " ");
i++;
}
degree = i;
if (first)
{
first = 0;
}
else
{
printf("\n");
}
/* if (degree < 2)
{
printf("q(x): 0\nr = %ld\n", a[0]);
continue;
}*/
r = 0;
j = 0;
for (i = 0;i < degree-1;i++)
{
t = a[i]-r;
q[j] = t;
r = -t*k;
j++;
}
r = a[i]-r;
printf("q(x): ");
for (i = 0;i < degree-1;i++)
{
printf("%ld ", q[i]);
}
printf("\n");
printf("r = %ld\n", r);
}
return 0;
}
```

This is the test input:

3

1 -7 15 -8

3

1 -7 15 -9

1

1 0 0 -3

1

1 -1

1

5 -5

3

1 -3

3

3 -9

4

1 -3

4

1 -1

1

5

1

1 -2 1

1

1 -3 3 -1

3

1 -7 12

1

1 -4 6 -4 1

4

1 0 -16

1

1 -4 5 -2

2

1 -4 5 -2

1

1 0 0 0 -1 1

1

1 0 0 0 -1 0

3

-7 2 2

3

1

3

1 -7 15 -8

3

1 -7 15 -9

3

1

3

0 0 0 0 5

-2

1 1 -2

This is the test output:

[quoteq(x): 1 -4 3

r = 1

q(x): 1 -4 3

r = 0

q(x): 1 1 1

r = -2

q(x): 1

r = 0

q(x): 5

r = 0

q(x): 1

r = 0

q(x): 3

r = 0

q(x): 1

r = 1

q(x): 1

r = 3

q(x):

r = 5

q(x): 1 -1

r = 0

q(x): 1 -2 1

r = 0

q(x): 1 -4

r = 0

q(x): 1 -3 3 -1

r = 0

q(x): 1 4

r = 0

q(x): 1 -3 2

r = 0

q(x): 1 -2 1

r = 0

q(x): 1 1 1 1 0

r = 1

q(x): 1 1 1 1 0

r = 0

q(x): -7 -19

r = -55

q(x):

r = 1

q(x): 1 -4 3

r = 1

q(x): 1 -4 3

r = 0

q(x):

r = 1

q(x): 0 0 0 0

r = 5

q(x): 1 -1

r = 0

][/quote]

cases considered:

1) x-k

2) q (x-k)

3) 1/0

4) x-a, a < k

5) (x-k)^2

6) (x-k)^3

7) (x-k)^4

(x-k)(x-a)

9) x^2-k^2

10) x^2-a, a<k

11) x^5-x+1

12) (x-k)^2 ( x-a)

13) (x-k)(x-a)^2

14) k can be negative number

15) also included the test cases in previous posts.

16) k = 0

Moreover, made everything long so that no overflow. Size of the holding array is 2x ~ 10x. Kept the array in the heap. Included blank lines between cases.

Still the judge seems to be unfairly giving WA.

Got any ideas?