How fast do you need a program? And how often do you calculate this problem?
If you need fast achievement and don't care about memory. You can generate an increasing prime table by the sieve method, and then hold it for the program life cycle, and then when you need to find βthe largest prime number smaller than x,β just find the table and time O (log N) when you may find the exact answer.
source share