UVA Solution : 386 Perfect Cubes
Solve in C:
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,k,m,n,a,b,c,flag,s,count;
for(s=1; s<=200; s++)
{
m=s*s*s;
for(i=2; i<=200; i++)
{
a=i*i*i;
for(j=i+1; j<=200; j++)
{
b=j*j*j;
for(k=j+1;k<=200;k++)
{
c=k*k*k;
if(m==(a+b+c))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",s,i,j,k);
}
}
}
}
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main()
{
int i,j,k,m,n,a,b,c,flag,s,count;
for(s=1; s<=200; s++)
{
m=s*s*s;
for(i=2; i<=200; i++)
{
a=i*i*i;
for(j=i+1; j<=200; j++)
{
b=j*j*j;
for(k=j+1;k<=200;k++)
{
c=k*k*k;
if(m==(a+b+c))
{
printf("Cube = %d, Triple = (%d,%d,%d)\n",s,i,j,k);
}
}
}
}
}
return 0;
}
No comments