386 - Perfect Cubes
Moderator: Board moderators
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
I am getting worng answer. where is the problem??
please help me.........
[cpp]
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 100
long DEC;
char Other[MAX];
char Insert_Char(long base,long mod)
{
long i;
char C = 'A';
for(i = 0; i < base - 10; i++)
if(mod == 10+i) return (char) (C+i);
return '0';
}
void To_Desimal(char *NUM, long base)
{
long i,ins,l,len;
l = len = strlen(NUM) - 1;
DEC = 0;
for(i = 0; i <= len ; i++)
{
if(NUM == 'A') ins = 10;
else if( NUM == 'B') ins = 11;
else if( NUM == 'C') ins = 12;
else if( NUM == 'D') ins = 13;
else if( NUM == 'E') ins = 14;
else if( NUM == 'F') ins = 15;
else ins = NUM - '0';
DEC = DEC + ins * pow(base,l);
l--;
}
}
void From_Desimal(long base)
{
long i,mod,len,j;
char temp[MAX];
long dec;
dec = DEC;
for(i = 0; dec!=0;i++ )
{
mod = dec % base;
if(mod >= 10)
temp = Insert_Char(base,mod);
else temp = mod + '0';
dec = dec / base;
}
temp = NULL;
len = strlen(temp)-1;
j = 0;
for(i = len; i >= 0; i-- )
Other[j++]=temp[i];
Other[j] = NULL;
}
int main()
{
int i,minus;
long b1,b2,flag;
char NUM[MAX];
//freopen("c:\\out.txt","w",stdout);
while( scanf("%s %ld%ld",NUM,&b1,&b2)==3)
{
flag = 0;
minus = 0;
for(i = 0; NUM[i]!=NULL; i++)
if(NUM[i] != '0'){ flag=1;break;}
if(flag == 0) {printf(" 0\n");continue;}
else if(b2 == 10 )
{
To_Desimal(NUM,b1);
if(DEC > 9999999){printf(" ERROR\n");continue;}
printf("%7lld\n",DEC);
}
else if(b1 == 10)
{
sscanf(NUM,"%lld",&DEC);
From_Desimal(b2);
if(strlen(Other) > 7){ printf(" ERROR\n");continue;}
printf("%7s\n",Other);
}
else
{
To_Desimal(NUM,b1);
From_Desimal(b2);
if(strlen(Other) > 7){printf(" ERROR\n");continue;}
printf("%7s\n",Other);
}
}
return 0;
}
[/cpp]
please help me.........
[cpp]
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX 100
long DEC;
char Other[MAX];
char Insert_Char(long base,long mod)
{
long i;
char C = 'A';
for(i = 0; i < base - 10; i++)
if(mod == 10+i) return (char) (C+i);
return '0';
}
void To_Desimal(char *NUM, long base)
{
long i,ins,l,len;
l = len = strlen(NUM) - 1;
DEC = 0;
for(i = 0; i <= len ; i++)
{
if(NUM == 'A') ins = 10;
else if( NUM == 'B') ins = 11;
else if( NUM == 'C') ins = 12;
else if( NUM == 'D') ins = 13;
else if( NUM == 'E') ins = 14;
else if( NUM == 'F') ins = 15;
else ins = NUM - '0';
DEC = DEC + ins * pow(base,l);
l--;
}
}
void From_Desimal(long base)
{
long i,mod,len,j;
char temp[MAX];
long dec;
dec = DEC;
for(i = 0; dec!=0;i++ )
{
mod = dec % base;
if(mod >= 10)
temp = Insert_Char(base,mod);
else temp = mod + '0';
dec = dec / base;
}
temp = NULL;
len = strlen(temp)-1;
j = 0;
for(i = len; i >= 0; i-- )
Other[j++]=temp[i];
Other[j] = NULL;
}
int main()
{
int i,minus;
long b1,b2,flag;
char NUM[MAX];
//freopen("c:\\out.txt","w",stdout);
while( scanf("%s %ld%ld",NUM,&b1,&b2)==3)
{
flag = 0;
minus = 0;
for(i = 0; NUM[i]!=NULL; i++)
if(NUM[i] != '0'){ flag=1;break;}
if(flag == 0) {printf(" 0\n");continue;}
else if(b2 == 10 )
{
To_Desimal(NUM,b1);
if(DEC > 9999999){printf(" ERROR\n");continue;}
printf("%7lld\n",DEC);
}
else if(b1 == 10)
{
sscanf(NUM,"%lld",&DEC);
From_Desimal(b2);
if(strlen(Other) > 7){ printf(" ERROR\n");continue;}
printf("%7s\n",Other);
}
else
{
To_Desimal(NUM,b1);
From_Desimal(b2);
if(strlen(Other) > 7){printf(" ERROR\n");continue;}
printf("%7s\n",Other);
}
}
return 0;
}
[/cpp]
-
- New poster
- Posts: 32
- Joined: Fri Oct 01, 2004 10:53 pm
386 what is wrong
[java]for(int i=6;i<=200;i++)
{
for(int j=2;j<i;j++)
{
for(int k=2;k<=j;k++)
{
for(int l=2;l<=k;l++)
{
if(i*i*i==(k*k*k+j*j*j+l*l*l))
{
System.out.println("Cube = "+i+", Triple = ("+l+","+k+","+j+")");
}
}
}
}
}[/java]
{
for(int j=2;j<i;j++)
{
for(int k=2;k<=j;k++)
{
for(int l=2;l<=k;l++)
{
if(i*i*i==(k*k*k+j*j*j+l*l*l))
{
System.out.println("Cube = "+i+", Triple = ("+l+","+k+","+j+")");
}
}
}
}
}[/java]
Getting 0:00 time for problem 386
I would like to know how get 00:00 time for problem 386.I used the following code and
got time of 0:01:614.Though it got AC i would like to optimize more
#include <stdio.h>
int main()
{
int a,b,c,d;
for(a=6;a<=200;a++)
for(b=2;b<a;b++)
for(c=b;c<a;c++)
for(d=c;d<a;d++)
if(a*a*a==(b*b*b+c*c*c+d*d*d))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
return 0;
}
got time of 0:01:614.Though it got AC i would like to optimize more
#include <stdio.h>
int main()
{
int a,b,c,d;
for(a=6;a<=200;a++)
for(b=2;b<a;b++)
for(c=b;c<a;c++)
for(d=c;d<a;d++)
if(a*a*a==(b*b*b+c*c*c+d*d*d))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
return 0;
}
-
- New poster
- Posts: 19
- Joined: Sat Mar 12, 2005 5:56 pm
- Location: Halifax, Nova Scotia, Canada
- Contact:
Hi,
I think most of those 0:00 for this problem are done using pre calculation.
Maybe even all of them!
Anyway, I think you can optimize your code a good amount in the following way. I could get it accepted in 0:00.980 which is not really good, but is still better.
I think most of those 0:00 for this problem are done using pre calculation.
Maybe even all of them!
Anyway, I think you can optimize your code a good amount in the following way. I could get it accepted in 0:00.980 which is not really good, but is still better.
Code: Select all
#include <stdio.h>
int main()
{
int a,b,c,d;
int acube,bcube,ccube,bplusc;
for(a=6;a<=200;a++)
{
acube=a*a*a;
for(b=2;b<a;b++)
{
bcube=b*b*b;
for(c=b;c<a;c++)
{
ccube=c*c*c;
bplusc=bcube+ccube;
for(d=c;d<a;d++)
{
if(acube==(bplusc+d*d*d))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
}
}
}
}
return 0;
}
-
- New poster
- Posts: 3
- Joined: Sun Jun 26, 2005 2:24 pm
The judgieing machine seems wrong
Dear Sir,
I am a new commer I solved the question no 386 and submitted only to get wrong answer.
But my solution is right and running within the time limit. Further more the output given in the question is itself wrong. it is not showing the line
Cube = 9, Triple = (1,6,8 )
but 9*9*9=1*1*1 +6*6*6+ 8*8*8
So the question must be corrected.
I also submitted question no 834 but your judging system says it as wrong.
Also I took part in the online programming contest on 25/6/2005 I solved the question B only but your online judge says it as wrong answer .
There must be some thing wrong in the judgeing system
Md. Aftabuddin
I am a new commer I solved the question no 386 and submitted only to get wrong answer.
But my solution is right and running within the time limit. Further more the output given in the question is itself wrong. it is not showing the line
Cube = 9, Triple = (1,6,8 )
but 9*9*9=1*1*1 +6*6*6+ 8*8*8
So the question must be corrected.
I also submitted question no 834 but your judging system says it as wrong.
Also I took part in the online programming contest on 25/6/2005 I solved the question B only but your online judge says it as wrong answer .
There must be some thing wrong in the judgeing system
Md. Aftabuddin
Last edited by Md. Aftabuddin on Tue Jun 28, 2005 4:57 pm, edited 1 time in total.
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
Please make sure that you understand the problem. I believe you that you think you solved the problems right, however you will always get WA if you solved another problem than was posed.
For problem 386, please consider that you have to find values a,b,c > 1 !!!
I suggest you read the problem descriptions of that other problems again, maybe you also overlooked something.
For problem 386, please consider that you have to find values a,b,c > 1 !!!
I suggest you read the problem descriptions of that other problems again, maybe you also overlooked something.
-
- Learning poster
- Posts: 60
- Joined: Sun Apr 16, 2006 7:59 pm
386 wa, it seems ok but......
please show me the mistake...
thanks.........
thanks.........
Code: Select all
the code is removed.
Last edited by ayeshapakhi on Wed May 31, 2006 7:00 am, edited 1 time in total.