this que would be solve using segmented seive in cpp
but here can it be solved using sieve only ?? as we can make list of size 10^9 in python
Prime generator
Hey @Ashu1318, the space complexity of your code would be very high. In case of simple sieve the complexity is O(n) whereas in segmented sieve the space complexity is O(n^1/2)
. I would therefore advise you to use segmented sieve itself. But you can always try and experiment using simple sieve in python but then make sure you follow the constraints given in the question.
I hope this clears your doubt !
Happy Learning !
The code has some errors. Kindly fix them first so that I can check if the code works for prime generator.
Thanks !
yeah that’s what i want to know remove these error,i tried many times
could u plz tell me how to fix it ???
Hey @Ashu1318, the error that your code is giving is shown below :
/bin/run.sh: line 3: 12 Killed python3 script.py
Usually, you get killed
message when the program runs out of RAM (as opposed to hard disk which you have in plenty). You should keep a watch on main memory. Run top and have a look at the memory being taken by your program, or alternatively use a tool like guppy (https://pypi.python.org/pypi/guppy/) to track memory utilization programmatically.
I would hazard a guess that you are creating some big in memory data structure while processing files, perhaps not de-allocating them as you iterate through the files.
So as I had said the space complexity is too high. Kindly try to use other methods to solve this Prime generator
problem.
I hope this clears your doubt !
Happy Coding !
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.