Page **1** of **4**

### 386 so simple BUT...

Posted: **Sat Feb 22, 2003 10:01 am**

by **deddy one**

my program gives me 216 lines of output and

it gives me WA

how many output lines it should be ?????

the sorting method is based ascending value of

"b" right??

Posted: **Sat Feb 22, 2003 8:30 pm**

by **Jalal**

Cheak ur inner loops!

yes the sorting method is based ascending value of

"b"

Posted: **Sun Feb 23, 2003 7:59 am**

by **deddy one**

so, how many lines of output are there in this problem??

I try to use double data type to guard against miscalculation

and it gives me 216 lines.

thanks.

Posted: **Sun Feb 23, 2003 12:40 pm**

by **angga888**

My output gives 223 lines.

I just use long, not double.

Try to check your loop again. You should get AC.

Good Luck

Posted: **Sun Feb 23, 2003 6:26 pm**

by **deddy one**

thx guys

got AC now

I made stupid mistake in my loop

using long data type making the calculation faster too.

### 386 - keep getting wrong answer

Posted: **Wed May 07, 2003 11:38 am**

by **the900**

My program has 223 lines of output, and the first ones are exactly the same as in the problem set, but I keep getting wrong answer. Does anyone know what could be wrong?

### Re: 386 so simple BUT...

Posted: **Sun May 11, 2003 11:07 pm**

by **szymcio2001**

Rong wrote:Why does give 222 lines in my output ?

I compiled it and it printed 223 line on my computer.

Rong wrote:
[cpp]

for(d=c;d<a;d++)

{

if(i==(pow(b,3)+pow(c,3)+pow(d,3)))

{

printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);

break;

}

}

}[/cpp]

This isn't verry efficient. You should check using math functions if exists a such integer d that a^3-b^3-c^3=d^3

Posted: **Tue May 13, 2003 10:14 am**

by **the900**

I get 223 lines of output but the judge tells me WA. Here's the code, could you help me

Posted: **Tue May 13, 2003 11:39 am**

by **szymcio2001**

[quote="the900"]I get 223 lines of output but the judge tells me WA. Here's the code, could you help me

### 386 - Perfect Cubes

Posted: **Mon Dec 15, 2003 1:31 pm**

by **aakash_mandhar**

What is wrong with this code plz help.. i thought this was a cool logic but got wa....

It seems to work and gives me 223 answers.. Plz help...

Plzz help

[cpp]

# include<iostream.h>

long a;

long init,temp;

int i,j1,j2,j3;

long cube[201];

long sol[300][3];

long sc;

int find(int x,int y,int z)

{

for(int i=0;i<sc;i++)

if((sol*[0]==x && sol**[1]==y && sol**[2]==z) || (sol**[0]==x && sol**[2]==y && sol**[1]==z)|| (sol**[2]==x && sol**[1]==y && sol**[0]==z) || (sol**[2]==x && sol[i][0]==y && sol[i][1]==z)|| (sol[i][1]==x && sol[i][2]==y && sol[i][0]==z) || (sol[i][1]==x && sol[i][0]==y && sol[i][2]==z)) return 1;*

return 0;

}

int main()

{

sc=0;

a=1;

init=7;

temp=6;

for(i=1;i<=200;i++)

{

cube[i]=a;

//cout<<a<<",\n";

a+=init;

temp+=6;

init+=temp;

}

for(i=6;i<=200;i++)

{

//cout<<cube[i]<<"\n";

for(j1=2;j1<=i-3;j1++)

{

for(j2=j1+1;j2<=i-2;j2++)

{

for(j3=j2+1;j3<=i-1;j3++)

{

if(cube[i]==cube[j1]+cube[j2]+cube[j3])

{

if(find(j1,j2,j3)==0)

{

sol[sc][0]=j1;sol[sc][1]=j2;sol[sc][2]=j3;sc++;

cout<<"Cube = "<<i<<", Triple = ("<<j1<<","<<j2<<","<<j3<<")\n";

}

}

}

}

}

}

return 1;

}

//@end_of_source_code

[/cpp]

### Nothing is wrong.

Posted: **Sat Dec 27, 2003 7:49 am**

by **sohel**

I have gone through your code and found no mistakes in it. So I decided to submit it and was not surprised to see 'accepted' as the reply. It means yours was a cool logic.

### AC

Posted: **Mon Jan 05, 2004 12:50 am**

by **aakash_mandhar**

Thx for the help..

I have removed my id from the post..

Thx again

Glad you liked the logic.

### WA 386

Posted: **Mon Feb 02, 2004 10:48 am**

by **WR**

Hi,

using brute force (or ''complete enumeration'' as I prefer to call it)

I get 223 lines of output - but a WA.

Summarizing the rules:

1) sort by non-descending a

2) b <= c <= d

3) if there's more than one triple for a specific a,

sort by the value of b (ascending)

Example:

Cube = 150, Triple = (24,102,132)

Cube = 150, Triple = (71,73,138)

Cube = 150, Triple = (75,100,125)

Cube = 150, Triple = (76,86,132)

So what's my mistake?!

Any hints?

Posted: **Mon Feb 02, 2004 6:06 pm**

by **pavelph**

First outputs for this problem:

[pascal]program acm386; {a^3=b^3+c^3+d^3}

begin

writeln('Cube = 6, Triple = (3,4,5)');

writeln('Cube = 12, Triple = (6,8,10)');

writeln('Cube = 18, Triple = (2,12,16)');

writeln('Cube = 18, Triple = (9,12,15)');

writeln('Cube = 19, Triple = (3,10,18)');

writeln('Cube = 20, Triple = (7,14,17)');

writeln('Cube = 24, Triple = (12,16,20)');

writeln('Cube = 25, Triple = (4,17,22)');

writeln('Cube = 27, Triple = (3,18,24)');

writeln('Cube = 28, Triple = (18,19,21)');

writeln('Cube = 29, Triple = (11,15,27)');

writeln('Cube = 30, Triple = (15,20,25)');

writeln('Cube = 36, Triple = (4,24,32)');

writeln('Cube = 36, Triple = (18,24,30)');

[/pascal]

I hope it helps you.

Posted: **Tue Feb 03, 2004 8:49 am**

by **WR**

Thanks for the post pavelph,

but it doesn't help because my output is exactly the same.

Code: Select all

```
#include <stdio.h> /* printf */
/*****************************
* ACM Contest - Problem 386 *
*****************************/
int main(void)
{
const int max = 200;
long a, b, c, d;
long a3, b3, c3, d3;
for (a=2;a<=max;a++){
a3 = a*a*a;
for (b=2;b<=a;b++){
b3 = b*b*b;
for (c=b;c<=a;c++){
c3 = c*c*c;
for (d=c;d<=a;d++){
d3 = d*d*d;
if (b3+c3+d3 == a3)
printf("Cube = %ld, Triple = (%ld,%ld,%ld)\n",a,b,c,d);
}
}
}
}
return 0;
}
```