← Back to challenges

Cuban Prime

JavaScriptHardmathlanguage_fundamentals

Instructions

Create a function to check whether a given number is Cuban Prime. A cuban prime is a prime number that is a solution to one of two different specific equations involving third powers of x and y. For this challenge we are only concerned with the cuban numbers from the first equation. We ignore the cuban numbers from the second equation.

Equation Form

p = (x^3 - y^3)/(x - y), x  = y + 1, y > 0

... and the first few cuban primes from this equation are 7, 19, 37, 61, 127, 271.

Examples

cubanPrime(7) ➞ "7 is cuban prime"

cubanPrime(9) ➞ "9 is not cuban prime"

cubanPrime(331) ➞ "331 is cuban prime"

cubanPrime(40) ➞ "40 is not cuban prime"

Notes

  • The inputs are positive integers only.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.