13,589,560 members
alternative version

#### Stats

21.3K views
9 bookmarked
Posted 20 Apr 2009
Licenced CPOL

# Perfect Cube

A Classic C++ Problem

## Introduction

About three days ago, I had a talk with a student about Math and Pierre de Fermat. It was an interesting discussion. His problem was how to solve the problem named Perfect Cube. So I had to take a small break with him and we resolved this simple-medium problem. I also found it interesting to write my conclusions.

For many years, Fermat Theorem, said that it was not possible for three integers number a,b,c > 1 and one natural number n > 2 to exist, in this way to have an + bn = cn, it has not been demonstrated. Many attempts have been made to demonstrate this thing and none of them worked. But it is possible to find integers greater then 1 that satisfy the perfect cube equation: a3 = b3 + c3 + d3 (for example 123 = 63 + 83 + 103 is true).

## Background

This problem aims to write a small program that will display in file "cubes.out" all multitudes of numbers {a,b,c,d} from multitude {1,2,...,100} that satisfy this equation like:

```Cube = 6,   Triple = (3,4,5)
Cube = 12, Triple = (6,8,10)
Cube = 18, Triple = (2,12,16)
........
Cube = 99,   Triple = (11,66,88)
Cube = 100, Triple = (16,68,88)
Cube = 100, Triple = (35,70,85)```

## Using the Code

For all pairs of natural numbers a and b, with properties: a > b and a, b being between 2 and 100, we are looking for c and d numbers with the property:

`a3 - b3 = c3 + d3`

We will use an array named cube to keep all cubes of natural numbers from [0,100]. For a and b fixed we note with rest the difference  a3 - b3. Later, for c fixed we look for d. In this way the `cube[d] = rest - rest[c]`.

```#include <stdio.h>

long cube[101];
FILE* fout;
void main()
{
int i,a,b,c,d, rest, rest2;
fout = fopen("cubes.out", "w");
for(i=0; i<=100;i++)
cube[i] = i*i*i;
for(a=6; a<100; a++)
for(b=2; b<a; b++)
{
rest = cube[a] - cube[b];
for(d=c; cube[d]<=rest2; d++)
if(cube[d]==rest2)
fprintf(fout, "Cube=%d, Triple = (%d,%d,%d)\n",a,b,c,d);
}
fclose(fout);
}```

Happy coding!

## History

• 20th April, 2009: Initial post

## Share

 Instructor / Trainer Lumina - The University of South-East Europe Romania
No Biography provided

## You may also be interested in...

 Pro

 First Prev Next
 Fermat's Last Theorem drandand27-Apr-09 18:26 drandand 27-Apr-09 18:26
 Re: Fermat's Last Theorem Marius Iulian Mihailescu9-May-09 10:23 Marius Iulian Mihailescu 9-May-09 10:23
 Last Visit: 31-Dec-99 18:00     Last Update: 18-Jun-18 8:20 Refresh 1