1109-Fermat's Last Theorem
http://rose.u-aizu.ac.jp/onlinejudge/ProblemSet/description.jsp?id=1109
問題概要
2以上1110以下の整数zが与えられる。
x^3+y^3
全ての考えられるx,yを試す。
#include <iostream> #include <algorithm> using namespace std; typedef long long int lli; int main() { lli ans,z; for(;cin>>z,z;){ ans=z*z*z; for(lli x=1;x<z;x++){ for(lli y=1;y<z;y++){ if(z*z*z-x*x*x-y*y*y<0)break; ans=min(ans,z*z*z-x*x*x-y*y*y); } } cout<<ans<<endl; } return 0; }