## 11428 - Cubes

Moderator: Board moderators

New poster
Posts: 25
Joined: Thu Nov 24, 2011 6:32 am

### Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

1657=24 23
Check input and AC output for thousands of problems on uDebug!

New poster
Posts: 25
Joined: Thu Nov 24, 2011 6:32 am

### Re: 11428 - Cubes (about 7 times TLE and 3 times WA)

Thanks a lot,got AC now

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Contact:

### Re: 11428 - Cubes

Here is my code...

#include<stdio.h>
int main()
{
int n,x,y,i,j,flag,m;
while(scanf("%d",&n)==1)
{
if(n==0) break;
x=0;
y=0;
flag=0;
for(j=0;j<=22;j++)
{
for(i=1;i<=28;i++)
{
if(i<j) continue;
m=(i*i*i)-(j*j*j);
if(m==n)
{
x=i;
y=j;
flag=1;
break;
}
}
if(flag==1) break;
}
if(x==0&&y==0)
printf("No solution\n");
else
printf("%d %d\n",x,y);
}
return 0;
}
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11428 - Cubes

40*40*40-39*39*39=4681
Check input and AC output for thousands of problems on uDebug!

alimbubt
New poster
Posts: 39
Joined: Tue Aug 07, 2012 10:40 pm
Contact:

### Re: 11428 - Cubes

brianfry713 wrote:40*40*40-39*39*39=4681
Thanks
Give me six hours to chop down a tree and I will spend the first four sharpening the axe...(BUBT ILLUSION)
http://uhunt.felix-halim.net/id/155497
http://onlyprogramming.wordpress.com/

mahbub2012
New poster
Posts: 5
Joined: Fri Nov 09, 2012 11:33 pm

### Re: 11428 - Cubes

why wrong ans

Code: Select all

``````

#include<stdio.h>
#include<math.h>

int main()
{
double f,t;
int i,c,n;
int flag=0;

while(scanf("%d", &n)==1) {
if(n==0)
break;

for(i=1; ; i++) {
zz:

if(flag == 1)
{i=i+1;
flag=0; }

f = n + (i*i*i);
t = cbrt(f);
c = t;

if(i>=t)
break;

if(c == t)
{flag = 1;
break;}  }

if(n!=((c*c*c)-(i*i*i)) && flag == 1)
goto zz;

if(flag == 1)
{ printf("%d %d\n", c,i);
flag = 0; }

else
printf("No solution\n");

}

return 0;
}

``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11428 - Cubes

That doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

shuvrothpol1
New poster
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

### Re: 11428 - Cubes

i've got wa many times.but i check the sample test cases here .can anyone help?
#include <stdio.h>

int main ()
{
scanf ("%lld",&n);
while (n!=0){
j=1;
flag=0;
while (1){
for (i=0;i<j;i++){
x2=j*j;
y2=i*i;
x2y2=x2+y2;
if (x2y2>n){
break;
}
x2y2+=(i*j);
x2y2*=(j-i);
if (x2y2==n){
printf ("%lld %lld\n",j,i);
flag=1;
}
}
break;
j++;
}
if (flag==0)
printf ("No solution\n");

scanf ("%lld",&n);
}
return 0;
}
Last edited by shuvrothpol1 on Thu Jan 24, 2013 8:25 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11428 - Cubes

Try input:

Code: Select all

``````721
0``````
AC output:

Code: Select all

``9 2``
Check input and AC output for thousands of problems on uDebug!

shuvrothpol1
New poster
Posts: 17
Joined: Wed Aug 15, 2012 12:37 pm

### Re: 11428 - Cubes

tnx acceptep..

X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

### 11428-I am tired getting WA again& again

plz...Help me

i am just a beginner

#include<cstdio>
#include<cmath>
int main()
{
long int t,i,a,N,x=0;
int c;
double p,b;
while(scanf("%ld",&N)==1)
{
if(N==0)
break;
p=sqrt((double)N);
for(i=1;i<=(int)p;i++)
{
a=N+(i*i*i);
b=cbrt((double)a);
c=(int)b;
t=(c*c*c)-(i*i*i);
if(t==N)
{
x=1;
printf("%d %ld\n",c,i);
break;
}
}
if(x==0)
printf("No solution\n");
x=0;
}
return 0;
}
Many of life’s failures are people who did not realize how close they were to success when they gave up.

X123
New poster
Posts: 11
Joined: Fri Oct 04, 2013 1:28 am

### Re: 11428 -Why WA?

plz...Help me

i am just a beginner

[removed]
Last edited by X123 on Fri Nov 15, 2013 7:54 pm, edited 1 time in total.
Many of life’s failures are people who did not realize how close they were to success when they gave up.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11428-I am tired getting WA again& again

Don't double post
Check input and AC output for thousands of problems on uDebug!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11428 - Cubes

Input: 631
Output should be 15 14
Check input and AC output for thousands of problems on uDebug!