312

## Description

a³ = b³ + c³ + d³为完美立方等式。例如 12³ = 6³ + 8³ + 10³。对任意给出的正整数N(N≤100),寻找所有的四元组（a, b, c, d）,使得 a³ = b³ + c³ + d³, 其中 1 < a, b, c, d ≤ N。

24

## Sample Output

Cube = 6, Triple = (3,4,5)
Cube = 9, Triple = (1,6,8)
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)

4 重 for 循环

# 代码

/*
By:OhYee
Github:OhYee
Blog:http://www.oyohyee.com/
Email:oyohyee@oyohyee.com

かしこいかわいい？
エリーチカ！

*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
using namespace std;

const int maxn = 1000;

bool Do() {
int N;
if(scanf("%d",&N) == EOF)
return false;
int a,b,c,d;
for(a = 1;a <= N;a++) {
int a3 = a*a*a;
for(b = 1;b <= N;b++) {
int b3 = b*b*b;
if(a3 < b3)
break;
for(c = b;c <= N;c++) {
int c3 = c*c*c;
if(a3 < b3 + c3)
break;
for(d = c;d <= N;d++) {
int d3 = d*d*d;
if(a3 < b3 + c3 + d3)
break;
if(a3 == b3 + c3 + d3)
printf("Cube = %d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
}
}
}
return true;
}

int main() {
while(Do());
return 0;
}

• 点击查看/关闭被识别为广告的评论