Atenţie! Aceasta este o versiune veche a paginii, scrisă la 2016-01-25 06:42:03.
Revizia anterioară Revizia următoare
Revizia anterioară Revizia următoare
Problem: prime number generator
A while back Ovidiu Gheorghioiu told me this neat problem:
How would you build an efficient prime number generator?
Let the generator be an object G with the method nextPrime(). When we call it G.getNextPrime() the first time it returns 2. Every time we call it again it returns the next prime number.
So if we do:
G = PrimeGenerator()
print G.nextPrime()
print G.nextPrime()
print G.nextPrime()
We'll get
2
3
5
Categorii: