UVa 386 - Perfect Cubes

Contents

  1. 1. Problem
  2. 2. Solution
  3. 3. Code

Problem

中文網址

Solution

直接三個 for ,暴力建表。

Code

UVa 386
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<cstdio>

int main()
{
for (int a = 6; a <= 200; a++)
{
int aaa = a*a*a;
for (int b = 2; b <= 200; b++)
{
int bbb = b*b*b;
if (bbb > aaa)
break;
for (int c = b; c <= 200; c++)
{
int ccc = c*c*c;
if (ccc + bbb > aaa)
break;

for (int d = c; d <= 200; d++)
if (aaa == bbb + ccc + d*d*d)
printf("Cube = %d, Triple = (%d,%d,%d)\n", a, b, c, d);
else if (aaa < bbb + ccc + d*d*d)
break;
}
}
}

return 0;
}