10326 - The Polynomial Equation

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

I have no idea what I am doing wrong. Can someone check this I/O:

Code: Select all

0
1 
0
4
1 -1 2 -2
5
1 2 -3 4 -5
3
1 1 1
3
0 0 1
3
1 1 0
10
1 -1 1 -1 1 -1 1 -1 1 -1
18
47 4 -4 6 5 -3 3 5 -7 11 -13 17 -19 -23 1 -1 2 -2
30
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2

Code: Select all

+ 0 = 0
x + 0 = 0
x^4 - 5x^2 + 4 = 0
x^5 + x^4 - 27x^3 - x^2 + 146x - 120 = 0
x^3 - 3x^2 + 3x - 1 = 0
x^3 - x^2 + 0 = 0
x^3 - 2x^2 + x + 0 = 0
x^10 - 5x^8 + 10x^6 - 10x^4 + 5x^2 - 1 = 0
x^18 - 29x^17 - 1516x^16 + 22438x^15 + 594647x^14 - 6733631x^13 - 76940474x^12 + 887000088x^11 + 2659293351x^10 - 44751912491x^9 + 14380900456x^8 + 859136425550x^7 - 1330305327287x^6 - 6613277622169x^5 + 13698383778334x^4 + 18535038211924x^3 - 42582893180712x^2 - 12737025391680x + 30197850883200 = 0
x^30 - 60x^29 + 1740x^28 - 32480x^27 + 438480x^26 - 4560192x^25 + 38001600x^24 - 260582400x^23 + 1498348800x^22 - 7325260800x^21 + 30766095360x^20 - 111876710400x^19 + 354276249600x^18 - 981072691200x^17 + 2382605107200x^16 - 5082890895360x^15 + 9530420428800x^14 - 15697163059200x^13 + 22673679974400x^12 - 28640437862400x^11 + 31504481648640x^10 - 30004268236800x^9 + 24548946739200x^8 - 17077528166400x^7 + 9961891430400x^6 - 4781707886592x^5 + 1839118417920x^4 - 544923975680x^3 + 116769423360x^2 - 16106127360x + 1073741824 = 0
Germano
New poster
Posts: 2
Joined: Sat Oct 16, 2004 9:15 am

WA too

Post by Germano »

Hello,

i use your input and get the same output.. i dont know what is wrog..
someone has some others inputs?

my code:

#include <stdio.h>
#define ABS(a) ((a>0)?(a):-(a))
#define MAX 51

long long c1[MAX];
long long c2[MAX];

int main()
{
long long r;
int i, j, n;

while ( scanf("%d", &n) == 1 ){
if ( !n ){
puts("+ 0 = 0");
continue;
}
for ( i=0; i<n; i++ )
c1 = 0;
scanf("%lld", &c1[0]);
if ( n == 1 ){
if ( c1[0] < 0 )
printf("x - %lld = 0\n", ABS(c1[0]));
else
printf("x + %lld = 0\n", c1[0]);
continue;
}
c1[0] *= -1;
c1[1] = 1;
for ( i=1; i<n; i++ ){
for ( j=0; j<n; j++ )
c2[j] = 0;
scanf("%lld", &r);
/* multiplication */
for ( j=0; j<=i; j++ )
c2[j] = -(c1[j]*r);

/* multiplication */
for ( j=1; j<=i+1; j++ )
c2[j] += c1[j-1];
/*put the result in c1 */
for ( j=0; j<=i+1; j++ )
c1[j] = c2[j];
}

/* print the output */
printf("x^%d", n);
for (i=n-1; i>1; i--){
if ( c1 == 0 )
continue;
if ( c1 < 0 ){
if ( c1 == -1 )
printf(" - x^%d", i);
else
printf(" - %lldx^%d", ABS(c1), i);
}else {
if ( c1 == 1 )
printf(" + x^%d", i);
else
printf(" + %lldx^%d", c1, i);
}
}

if ( c1[1] != 0 ){
if ( c1[1] < 0 ){
if ( c1[1] == -1 )
printf(" - x");
else
printf(" - %lldx", ABS(c1[1]));
}else {
if ( c1[1] == 1 )
printf(" + x");
else
printf(" + %lldx", c1[1]);
}
}

if ( c1[0] < 0 )
printf(" - %lld = 0\n", ABS(c1[0]));
else
printf(" + %lld = 0\n", c1[0]);
}
return 0;
}
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

The first case given by Darko is wrong. Because the problem states...

Code: Select all

The input will start with a positive integer N indicating the number of roots of the polynomial equation
And 0 is not a positive number.

Try the following cases...

Input:

Code: Select all

1
2
1
1
Output:

Code: Select all

x - 2 = 0
x - 1 = 0
Hope these help.
Ami ekhono shopno dekhi...
HomePage
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

It sure helped me :)

Thanks, Jan.
Post Reply

Return to “Volume 103 (10300-10399)”