## 11428 - Cubes

Moderator: Board moderators

mysword
New poster
Posts: 26
Joined: Sun Mar 06, 2005 8:52 am

### 11428 - Cubes

why my program get accepted in the 11436 Cubes - EXTREME, but get WA in 11428 Cubes using the same program??why why why???

It's so funny.....

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Contact:
then probably your program is wrong, and the testcases for 11436 didn't catch it.

tobby
Learning poster
Posts: 98
Joined: Fri Dec 30, 2005 3:31 pm
Does your code work for N = 721?

mukeshtiwari
Learning poster
Posts: 63
Joined: Tue Mar 07, 2006 6:51 pm
Location: india
Could someone please tell me why this code is giving WA for problem cubes.

Code: Select all

``````#include<cstdio>
#include<cmath>

int main()
{

long long int  n=1;
long long int k1,k2,x,y,w,flag;
while(scanf("%lld",&n) && n)
{
flag=1;
for(long long int  i=1;i*i*i<=n;i++)
{
if(!(n%i))
{
k1=i,k2=n/i;
w=((-3*k1)+(long long int)sqrt((double)(12*k2-3*k1*k1)))/6;
x=w+k1;
y=w;
if((x*x*x-y*y*y)==n)
{
printf("%lld %lld\n",x,y);
flag=0;
break;
}
}
}
if(flag)
printf("No solution\n");
}
}

``````

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Contact:
mukeshtiwari wrote:Could someone please tell me why this code is giving WA for problem cubes.
try the testcase n=1
the output should be No solution

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
I GOT ac
thanks sclo
i have a problem with that.
''I want to be most laziest person in the world''

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

### Re: 11428 - Cubes

Im getting WR PLZ Help me...

Code: Select all

``````// Removed...
``````
Thanks
Keep posting
Sapnil
Last edited by sapnil on Sat Apr 05, 2008 3:26 pm, edited 1 time in total.
"Dream Is The Key To Success"

@@@ Jony @@@

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:

### Re: 11428 - Cubes

Generate the output for 8 and read the description again.
Ami ekhono shopno dekhi...
HomePage

t_sergiu
New poster
Posts: 12
Joined: Sun Mar 02, 2008 6:18 am

### Re: 11428 - Cubes

Hmm I can't seem to figure out why I'm getting WA. Can someone help?

Code: Select all

``````#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
vector< int > cubes;
cubes.reserve( 100 );

for( int i = 1; i < 100; ++i )
{
cubes.push_back( i * i * i );
}

int n;

while( true )
{
cin >> n;
if( n == 0 )
break;

bool a = true;
for( unsigned int i = 1; i < 100; ++i )
{
int tot = n + cubes[ i ];
if( binary_search( ++( cubes.begin() ), cubes.end(), tot ) )
{
int j;
for( j = 1; cubes[ j ] != tot; ++j );
cout << j << " " << i << endl;
a = false;
break;
}
}

if( a )
cout << "No solution" << endl;
}

return 0;
}``````

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

### Re: 11428 - Cubes

Check your answer for 8, 64.. It founds some solutions but my AC code, doesn't.
I've got all your answers for all values of N from 1 to 10000 and all my answers of the same range.
I used fc to compare them, here is only part of its output:
My file is ac_outs.txt, your file - wa_out.txt. Line numbers (6:, 9:, etc.) are values of N for which I tested our solutions.
I hope it may help.

Code: Select all

``````????????? ?????? ac_outs.txt ? WA_OUTS.TXT
***** ac_outs.txt
6:  No solution
7:  2 1
8:  No solution
***** WA_OUTS.TXT
6:  No solution
7:  No solution
8:  1 99
9:  No solution
*****

***** ac_outs.txt
17:  No solution
18:  No solution
19:  3 2
20:  No solution
***** WA_OUTS.TXT
18:  No solution
19:  2 1
20:  No solution
*****

***** ac_outs.txt
25:  No solution
26:  3 1
27:  No solution
***** WA_OUTS.TXT
25:  No solution
26:  No solution
27:  2 99
28:  No solution
*****

***** ac_outs.txt
35:  No solution
36:  No solution
37:  4 3
38:  No solution
***** WA_OUTS.TXT
36:  No solution
37:  3 2
38:  No solution
*****

***** ac_outs.txt
55:  No solution
56:  4 2
57:  No solution
***** WA_OUTS.TXT
55:  No solution
56:  3 1
57:  No solution
*****

***** ac_outs.txt
60:  No solution
61:  5 4
62:  No solution
63:  4 1
64:  No solution
***** WA_OUTS.TXT
60:  No solution
61:  4 3
62:  No solution
*****

***** ac_outs.txt
65:  No solution
66:  No solution
***** WA_OUTS.TXT
63:  No solution
64:  3 99
65:  No solution
*****

***** ac_outs.txt
90:  No solution
91:  6 5
92:  No solution
***** WA_OUTS.TXT
89:  No solution
90:  No solution
91:  5 4
92:  No solution
*****

***** ac_outs.txt
97:  No solution
98:  5 3
99:  No solution
***** WA_OUTS.TXT
97:  No solution
98:  4 2
99:  No solution
*****

***** ac_outs.txt
116:  No solution
117:  5 2
118:  No solution
***** WA_OUTS.TXT
116:  No solution
117:  4 1
118:  No solution
*****

***** ac_outs.txt
123:  No solution
124:  5 1
125:  No solution
***** WA_OUTS.TXT
123:  No solution
124:  No solution
125:  4 99
126:  No solution
127:  6 5
128:  No solution
*****

***** ac_outs.txt
126:  No solution
127:  7 6
128:  No solution
***** WA_OUTS.TXT
129:  No solution
130:  No solution
*****

***** ac_outs.txt
149:  No solution
150:  No solution
***** WA_OUTS.TXT
151:  No solution
152:  5 3
153:  No solution
*****

***** ac_outs.txt
151:  No solution
152:  6 4
153:  No solution
***** WA_OUTS.TXT
154:  No solution
155:  No solution
*****

***** ac_outs.txt
166:  No solution
167:  No solution
***** WA_OUTS.TXT
168:  No solution
169:  7 6
170:  No solution
*****

***** ac_outs.txt
168:  No solution
169:  8 7
170:  No solution
***** WA_OUTS.TXT
171:  No solution
172:  No solution
*****

***** ac_outs.txt
186:  No solution
187:  No solution
***** WA_OUTS.TXT
188:  No solution
189:  5 2
190:  No solution
*****

***** ac_outs.txt
188:  No solution
189:  6 3
190:  No solution
***** WA_OUTS.TXT
191:  No solution
192:  No solution
*****

***** ac_outs.txt
205:  No solution
206:  No solution
***** WA_OUTS.TXT
207:  No solution
208:  5 1
209:  No solution
*****

***** ac_outs.txt
207:  No solution
208:  6 2
209:  No solution
***** WA_OUTS.TXT
210:  No solution
211:  No solution
*****

***** ac_outs.txt
213:  No solution
214:  No solution
215:  6 1
216:  No solution
217:  9 8
218:  7 5
219:  No solution
***** WA_OUTS.TXT
215:  No solution
216:  5 99
217:  8 7
218:  6 4
219:  No solution
*****

***** ac_outs.txt
270:  No solution
271:  10 9
272:  No solution
***** WA_OUTS.TXT
270:  No solution
271:  9 8
272:  No solution
*****
<VERY MUCH DIFFERENCE HERE, BUT I'VE CUT IT OUT>

***** ac_outs.txt
9575:  No solution
9576:  26 20
9577:  57 56
9578:  No solution
***** WA_OUTS.TXT
9575:  No solution
9576:  25 19
9577:  56 55
9578:  No solution
*****

***** ac_outs.txt
9601:  No solution
9602:  41 39
9603:  No solution
***** WA_OUTS.TXT
9601:  No solution
9602:  40 38
9603:  No solution
*****

***** ac_outs.txt
9647:  No solution
9648:  22 10
9649:  No solution
***** WA_OUTS.TXT
9647:  No solution
9648:  21 9
9649:  No solution
*****

***** ac_outs.txt
9727:  No solution
9728:  24 16
9729:  No solution
***** WA_OUTS.TXT
9727:  No solution
9728:  23 15
9729:  No solution
*****

***** ac_outs.txt
9784:  No solution
9785:  28 23
9786:  No solution
***** WA_OUTS.TXT
9784:  No solution
9785:  27 22
9786:  No solution
*****

***** ac_outs.txt
9792:  No solution
9793:  25 18
9794:  No solution
***** WA_OUTS.TXT
9792:  No solution
9793:  24 17
9794:  No solution
*****

***** ac_outs.txt
9918:  No solution
9919:  22 9
9920:  No solution
***** WA_OUTS.TXT
9918:  No solution
9919:  21 8
9920:  No solution
*****

***** ac_outs.txt
9969:  No solution
9970:  23 13
9971:  No solution
***** WA_OUTS.TXT
9969:  No solution
9970:  22 12
9971:  No solution
*****
``````
Now I lay me down to sleep...
my profile

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:

### Re: 11428 - Cubes

oh, and it is not very rational to check whether element is present in the vector using binary_search, but to find the index of this element - to use linear search. If you want to find an index of an element in the vector you may use upper_bound function, try to find documentation in the web.

I tried to fix your code.. What can I say, it's possible to get your method of solution to work correctly, but it is too slow anyway.
Hint: think of some other way of checking whether a number is a cube.
Now I lay me down to sleep...
my profile

joshi13
New poster
Posts: 9
Joined: Sun Jan 06, 2008 3:18 am

### Re: 11428 - Cubes

Hi.

I got AC in problem 11436 Cubes Extreme, the i tried to solve problem
11428 using the same code i used for 11436 but i got WA. Can anybody provide
some I/O sets ?

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

### Re: 11428 - Cubes

removed after ac..
thanks..
Last edited by pok on Fri Dec 12, 2008 12:05 am, edited 1 time in total.

MRH
Learning poster
Posts: 51
Joined: Mon Aug 11, 2008 9:09 pm

### Re: 11428 - Cubes

YOUR SOLUTION WA FOR DATA TYPE
BUT ACTUALLY YOUR ALGO IS TLE
REDUCE TIME .
THANK YOU

pok
New poster
Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

### Re: 11428 - Cubes

thanks..
i got ac..
but there was no problem in data type..
there was problem in for loop..