AOJ - Problem 1109 : Fermat's Last Theorem
1
#include <iostream> #include <algorithm> using namespace std; int main(){ int z; while( cin >> z , z ){ long long int ans = -1; for(long long int x = 1 ; x*x*x < z*z*z ; x++ ){ for(long long int y=1 ; x*x*x + y*y*y < z*z*z ; y++ ){ long long int s = z*z*z - x*x*x - y*y*y; ans = ( ans == -1 )? s : min( ans , s ); } } cout << ans << endl; } }