Python Forum

Full Version: how to find a next prime number?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a question that makes me so confused ...
I have to complete 「nextPrime()」 function so that it will return the smallest prime number that is greater than the input n. For example, if input is 6.4, the function should return 7. n can be any decimal number.

THANK YOU SO MUCH Cry Cry Cry
(Oct-01-2017, 08:15 AM)iamyourfather Wrote: [ -> ]THANK YOU SO MUCH
you are welcome :)\
ops, what for..?

seriously - what is your question? We are glad to help, but we are not here to do your homework for you.
Ok, so you need to:

a) come up with an algorithm to determine if a value is a prime number
.. there's an obvious way to do this (divide by all lower numbers starting from 2 to find no remainder)
.. and a more efficient mathematical approach, which you can easily look up

b) come up with an algorithm to choose the next highest integer incrementally, testing each one to see if it is prime

How far have you got?