Re: 11428 - Cubes
Posted: Tue Jan 06, 2009 11:29 am
I don't know what's going on with me. Some one please help me to get ACC.
I got so many WA.
I got so many WA.
Code: Select all
removed
Code: Select all
removed
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
long int i,j,y,N;
int digits[10005][2];
for(i=1;i<100;i++)
{
for(j=1;j<i;j++)
{
y=i*i*i-j*j*j;
if(y<=10000 && digits[y][0]<0)
{
digits[y][0]=i;
digits[y][1]=j;
}
}
}
while(scanf("%ld",&N))
{
if(N==0)break;
if(digits[N][0]>0)
printf("%d %d\n",digits[N][0],digits[N][1]);
else
printf("No solution\n");
}
return 0;
}
Code: Select all
Code: Select all
// id 11428
#include <stdio.h>
int main()
{
long int x[50],y[50],n,temp_i,temp_x,temp_1;
int i,j,flag;
for(i=0; i<50; i++)
{
x[i]=i*i*i;
y[i]=i*i*i;
}
while(1)
{
scanf("%ld",&n);
flag=0;
if(n==0)
{
break;
}
i=0;
while(x[i]<=n)
{
i++;
}
temp_i=i;
temp_x=x[i];
for(j=0; j<temp_i; j++)
{
//temp_1=n+y[j];
if(n+y[j]==temp_x)
{
flag=1;
break;
}
}
if(flag)
{
printf("%ld %d\n",temp_i,j);
}
else
{
printf("No solution\n");
}
}
return 0;
}
Code: Select all
#include <cstdio>
#include <cmath>
int main()
{
int n;
//freopen("in_11428.txt","r",stdin);
//freopen("out_11428.txt","w",stdout);
while(scanf("%d",&n)==1)
{
int i,j,flag=0,m,k;
int num,x3,y3;
if (n==0) break;
for(i=1;i<=(sqrt(n)/2)+1;i++)
{
x3=i*i*i;
if(x3<n) continue;
for(j=1;j<=(sqrt(n)/2)+1;j++)
{
y3=j*j*j;
if(y3>x3) continue;
num=x3-y3;
if(num==n)
{
m=i;
k=j;
flag=1;
break;
}
else if(num>n)
{
continue;
}
}
}
if(flag==1)
printf("%d %d\n",m,k);
else
printf("No solution\n");
}
return 0;
}
Code: Select all
#include <cstdio>
#include <cmath>
int main()
{
long n;
//freopen("in_11428.txt","r",stdin);
//freopen("out_11428.txt","w",stdout);
while(scanf("%ld",&n)==1)
{
long i,j,flag=0,m,k;
long num,x3,y3;
if (n==0) break;
for(i=1 ; i<=(int)sqrt(n)+10 ; i++)
{
x3=i*i*i;
for(j=1 ; j<=i ; j++)
{
y3=j*j*j;
// printf("%ld %ld\n",x3,y3);
if(y3>x3) continue;
num=x3-y3;
if(num==n)
{
m=i;
k=j;
flag=1;
break;
}
else if(num>n)
{
continue;
}
}
}
if(flag==1)
printf("%ld %ld\n",m,k);
else
printf("No solution\n");
}
return 0;
}
Code: Select all
#include<stdio.h>
typedef struct{
int x;
int y;
}s;
s cube[20005];
int main()
{
int i,j,k,p;
for(i=0; i<=22; i++)
{
for(j=i+1; j<=22; j++)
{
p=(j*j*j)-(i*i*i);
if(cube[p].x==0 && cube[p].y==0)
{
cube[p].x=j;
cube[p].y=i;
}
else
{
if(cube[p].y>i)
{
cube[p].x=j;
cube[p].y=i;
}
}
}
}
int n;
while(scanf("%d",&n)==1 && n!=0)
{
if(cube[n].x==0 && cube[n].y==0) printf("No solution\n");
else printf("%d %d\n",cube[n].x,cube[n].y);
}
return 0;
}