| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
水题纪念,不过还是用一位老兄说的算法过的把2-100的立方都放到一个数组里面去遍历,这样做不会超时.
#include<iostream>
using namespace std;
int main()
{ int n,i,j,p,q,a[101];
cin>>n;
for(i=2;i<=100;i++)
{a[i]=i*i*i;
}//得到2-100的三次放数
for(i=2;i<=n;i++)
for(j=2;j<=n;j++)
for(p=2;p<=n;p++)
for(q=2;q<=n;q++)
{ if(a[i]==a[j]+a[p]+a[q] &&a[j]<a[p] &&a[p]<a[q] &&a[q]<a[i])
cout<<"Cube = "<<i<<", Triple = ("<<j<<","<<p<<","<<q<<")"<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator