完美立方2810

完美立方

 OpenJ_Bailian - 2810 

Time limit1000 ms     Memory limit65536 kB  OS Linux  Source1543

形如a3= b3 + c3 + d3的等式被称为完美立方等式。例如123= 63 + 83 + 103 。编写一个程序,对任给的正整数N (N≤100),寻找所有的四元组(a, b, c, d),使得a3 = b3 + c3 + d3,其中a,b,c,d 大于 1, 小于等于N,且b<=c<=d。

Input一个正整数N (N≤100)。Output每行输出一个完美立方。输出格式为: 
Cube = a, Triple = (b,c,d) 
其中a,b,c,d所在位置分别用实际求出四元组值代入。 

请按照a的值,从小到大依次输出。当两个完美立方等式中a的值相同,则b值小的优先输出、仍相同则c值小的优先输出、再相同则d值小的先输出。

Sample Input

24

Sample Output

Cube = 6, Triple = (3,4,5)
Cube = 12, Triple = (6,8,10)
Cube = 18, Triple = (2,12,16)
Cube = 18, Triple = (9,12,15)
Cube = 19, Triple = (3,10,18)
Cube = 20, Triple = (7,14,17)
Cube = 24, Triple = (12,16,20)

 

 1 #include <iostream>
 2 using namespace std;
 3 
 4 //#define cube(a) a * a * a
 5 
 6 
 7 int main()
 8 {
 9     int a, b, c, d, N;
10     cin >> N;
11     int cube[101];
12     for (int i = 2; i < 101; i++)
13         cube[i] = i * i * i;
14 
15     for (a = 2; a <= N; a++)
16     for (b = 2; b < a; b++)
17     for (c = b; c < a; c++)
18     for (d = c; d < a; d++)
19     if (cube[b] + cube[c] + cube[d] == cube[a])
20         cout << "Cube = " << a << ", Triple = (" << b << "," << c << "," << d << ")" << endl;
21 
22     return 0;
23 }

 

上一篇:Unity笔记:DOTS入门示例


下一篇:数据分析工具FastCube.Core如何组装.NET 5.0教程