#include<cstdio>
int main(){
int n,a,b,c,d;
while(~scanf("%d",&n)){
for(a=6;a<=n;a++){//样例中a最小为6
for(b=2;b<a;b++){
for(c=b+1;c<a;c++){
for(d=c+1;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;
}
原文:http://blog.51cto.com/13688928/2119217