Https://ide.codingblocks.com/s/246400 Please tell error in this one


Please tell error in this one

define array globally and make bool arrray instead of int
as you have to store only 0 and 1 so integer array is not required

Modified Code

i hope this help
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course

Sir What was error in my code, And Please tell Why you declared the array as global?


And this code is not passing 2 test cases, Please tell about that.

actually when you have declared that array in function(main()) it was created in stack memory and when you were printing something compiler got some time and releases some memory which helped in processing and printing the output.
Its resolved by creating the array globally because the global arrays are created in heap memory.

look at constraints
1<n<2*10^9

so you can’t make array of that much size
you have to use segmented Seive logic
which will be cover in your course later

Segmented Sieve in which topic Sir, And Is this one the Prime Sieve. Please tell the difference between the both

i don’t know where it is but it should be in your course
if not then see on Youtube

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.