Perfect Cubes
Time limit1sMemory limit128 MB
Find all quadruples a, b, c, d with 2 <= a <= N, b < c < d, and a^3 = b^3 + c^3 + d^3, printed in sorted order.
- Level
Medium4 of 10
- Topics
- Brute force, Math, Sorting, Implementation
- Solved
- No attempts yet
Problem
Fermat's Last Theorem states that when , , are non-zero integers and is a natural number greater than 2, there are no natural numbers , , satisfying .
However, it is not hard to find natural numbers greater than 1 that satisfy the perfect-cube equation . For example, .
Given an integer , write a program that finds every quadruple satisfying this perfect-cube equation with . Here , , and are all greater than 1 and satisfy .
Input
The first line contains an integer ().
Output
Print each solution on its own line in increasing order of ; for the same , order by increasing , then , then . Each line has the form:
Cube = a, Triple = (b,c,d)
If no quadruple satisfies the conditions, print nothing.
Hint
Fermat's Last Theorem was proved by Andrew Wiles in 1995.