简单算法-完美立方

// wanmeilifang.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

采用的是枚举法,四重循环
int main()
{
int N;
cout << "请输入一个小于365的数:";
if (cin >> N)
cout << endl;
for (int a = 2; a <= N; ++a)
for (int b = 2; b < a; ++b)
for (int c = b; c < a; ++c)
for (int d = c; d < a; ++d)
if (a*a*a == b*b*b + c*c*c + d*d*d)
{
cout << "cube=" << a << "," << "(" << b << "," << c << "," << d << ")" << endl;
}

system("pause");

return 0;
}

 

posted @ 2017-11-27 00:33  boht  阅读(590)  评论(0)    收藏  举报