Did you know that the number 5 is the first safe prime? A safe prime is a prime number that can be expressed as 2p+1, where p is also a prime.
To celebrate Cody's Five-Year Anniversary, write a function to determine if a positive integer n is a safe prime in which the prime p (such that n=2p+1) is also a safe prime.
Examples
isextrasafe(5) = false % because 5=2*2+1 and 2 is not a safe prime isextrasafe(23) = true % because 23=2*11+1 and 11 is also a safe prime (11=2*5+1)
15 = 2*7+1 and 7 = 2*3+1 so 15 should be a safe prime. Am I missing something?
An (extra) safe prime number itself must be a prime number. Here, 15 is not a prime, so it is not (extra) safe prime
For case 8, x = 719;
which will lead to 44, not prime, the result should be false, but it's true now.
Am I right?
danteliujie, x = 719 does not lead to 44.
Why can't 71 be true?
Ups, 'maybe' 15 is not prime at all...
Oh sorry. I mean for Test #7
Test #5 x = 15;
15 = 2*7 + 1
7 = 2*3 + 1
3 is a prime number. therefore 7 is a safe prime. AND 15 is an extra safe prime. Or is there anything wrong with the equations above?
Lol. Forgot that 15 is not even a prime number.
isprime already exists!
This code would incorrectly identify x = 59 as an extra-safe prime (which it's not).
When x = 5 and x = 7, return false, is it right?
Yes, x = 5 and x = 7 are safe primes, but not "extra" safe primes because their corresponding values for p (2 and 3, respectively) are not safe primes.
This solution would incorrectly identify x = 71 as an extra-safe prime (which it's not).
Good catch, yurenchu. I'm adding 71 to the test suite.
Swap the first and last columns
10166 Solvers
992 Solvers
1911 Solvers
Given a window, how many subsets of a vector sum positive
685 Solvers
Solving Quadratic Equations (Version 1)
369 Solvers