方法一:
#include <cstdio>
int main(){
int a, b, c;
for(int i = 100; i < 1000; ++i){
a = i / 100;
b = i % 100 / 10;
c = i % 10;
if(a * a * a + b * b * b + c * c * c == i){
printf("%d\n", i);
}
}
return 0;
}
方法二:
#include <cstdio>
int cube(int k){
return k * k * k;
}
int main(){
int a, b, temp;
for(int i = 1; i < 10; ++i){
a = cube(i);
for(int j = 0; j < 10; ++j){
b = cube(j);
for(int k = 0; k < 10; ++k){
temp = a + b + cube(k);
if(temp == i * 100 + j * 10 + k){
printf("%d\n", temp);
}
}
}
}
return 0;
}