Would be interesting to see, how Python and Rust would benefit from an efficient algorithm. To check whether a number k is prime, one only needs to check all primes up to floor(sqrt(k)). So, if you track primes found while looking for the nth prime number using a list, you always will have all divisors in that list you need to check for the next number to test, which you would add to the list if it turns out to be prime. Once you have n primes in that list, you're done.

And there is somewhere a generator based on the sieve of Erasthotenes that produces a sequence of primes, that I guess is even more efficient than the algorithm I described. But it will require more memory.

That being said, thank you for teaching me how to combine Python and Rust.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Olaf Schlüter
Olaf Schlüter

Written by Olaf Schlüter

IT security specialist, Physicist by education, believing in God as for the exceptional harmony of the laws of nature to create and support life.

No responses yet

Write a response