POJ 1543 Perfect Cubes

题意:输入一个数n, 求a <= n 满足方程式a^3 = b^3 + c^3 + d^3  的所有解。

 

11000672 NY_lv10 1543 Accepted 216K 32MS C++ 452B 2012-11-09 18:33:09

 

View Code
 1 #include <iostream>

 2 //#include <fstream>

 3 using namespace std;

 4 

 5 //ofstream out("1.txt");

 6 int main()

 7 {

 8     int a, b, c, d;

 9     int n;

10     while (cin>>n)

11     {

12     for (a=2; a<=n; a++)

13         for (b=2; b<a; b++)

14             for (c=b; c<a; c++)

15                 for (d=c; d<a; d++)

16                 {

17                     if (a*a*a == b*b*b + c*c*c + d*d*d)

18                         cout<<"Cube = "<<a<<", Triple = ("<<b<<","<<c<<","<<d<<")"<<endl;

19                         //out<<"{"<<a<<", "<<b<<", "<<c<<", "<<d<<"},";

20                 }

21     }

22     return 0;

23 }

 

你可能感兴趣的:(cube)