Euler 27, question about solution from guide

Challenge

Guide page

I understand general logic in this solution, tho my approach was a bit different.

My question is about the first block of code: building list of primes
I also used sieve to get some primes in my solution, but in different context.

Here they are building sieve of primes in range 50000, and my question: why 50000?

If there is some maths behind using this value, there are no comments about it in the code. and I am very curious about such choice of size for list of primes

If it’s just hardcoded - I am not sure that I am big fan of that.

50000 is the size of the array, the number of items. It’s pointless going past a certain point because it will become incredibly slow. So just exiting at a given point is sensible rather than having no upper limit & eventually eating all available memory on the system. The number looks arbitrary (for example someone ran it with one number, then kept increasing the number until there was a speed issue & then settled a number a bit smaller than that)

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.