+ 2
I need help. how can I choose, for a prime number, the prime number that is before and the one that goes after this
4 Respostas
+ 7
You mean given 17, we need to get 13 and 19?🤔
I couldn't thought of any method except for to find all prime numbers🤔
+ 7
read this maybe https://en.m.wikipedia.org/wiki/Bertrand%27s_postulate, it can help you to find the prime number succeeding the given number
+ 4
Using a loop, you'll just have to test all the numbers before (or after) it one by one for primality, starting with the closest one. Whenever you find a prime, you can stop the loop. Also, make sure that your code is not trying to find primes before 2, because there won't be any.
It actually doesn't matter whether the number we started with is a prime or not.
This is all I can suggest. If you get stuck, please share your attempt, and we'd be happy to help you out.