The triangle below is special.
It has integer sides and a prime perimeter.
Given an integer "n" we want to know how many triangles can be formed such that the sides are integers and the perimeters are primes less than or equal to the nearest prime to "n".
The nearest prime number is defined as:
- "n" if "n" itself is prime;
- either the previous prime before or the next prime after "n", whichever has lesser distance to "n"; or
- the previous prime before "n" if the previous and next primes are equidistant to "n".
As an example, lets consider "n = 9". The nearest prime is 7 because 9 is equidistant between 7 and 11. The primes less than equal to 7 are [2 3 5 7]. There are no integral triangles that can be formed with perimeter 2. For 3 there is one, namely [1 1 1]. For 5 there is one, [1 2 2]. And for 7 there are 2, [1 3 3] and [2 2 3] . So, the total number of prime perimetered integral triangles that can be formed when n = 9 is 4.
NOTE: Rotations and reflections are irrelevant and counted only once.
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers10
Suggested Problems
-
Check to see if a Sudoku Puzzle is Solved
337 Solvers
-
Calculate the Hamming distance between two strings
341 Solvers
-
Decimation - Optimized for speed
217 Solvers
-
77 Solvers
-
Mersenne Primes vs. All Primes
841 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!