题目链接:http://poj.org/problem?id=1543
题意不难,求小于n的数的立方能否写成三个的立方和,水题,暴力枚举!
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std;
int main() { int n,i,j,k,l; cin>>n; for(i=3;i<=n;i++) { for(j=2;j<n;j++) for(k=j+1;k<n;k++) for(l=k+1;l<n;l++) if(i*i*i==j*j*j+k*k*k+l*l*l) { cout<<"Cube = "<<i<<", Triple = ("<<j<<","<<k<<","<<l<<")"<<endl; break; } } }
|