Please check code for PRIME1 - Prime Generator problem on SPOJ


Getting compilation error.

Hello @sahilkhan2312000131 could you please share the question link as well.

SPOJ.com - Problem PRIME1
Its same code as discussed in the video still getting error.

@sahilkhan2312000131 check now:

I have some doubts:

  1. Why have you written: int32_t main()
  2. If I am taking N=100000 i am getting error in ide but code gets accepted but if I take n=100005, code runs fine in ide. Why??

Please reply to my doubt

@sahilkhan2312000131 sorry for the late reply i was trapped because of network issue:

i have used int32_t because i have declared int as long long int but int in int main cant be fo the type long long int thats why we have to write int32_t ther.

@sahilkhan2312000131 N=100000 if they are asking for this prime numbers upto this range then you have to take some array size more then N=100000 this because otherwise after this point the array size will be insufficient to calculate further and eventually endup giving error.

Coding Blocks IDE
Just check this code one, if I take N=1000005 it runs fine but if I take n=1000000, I get segmentation fault. Why??

@sahilkhan2312000131 do you know about the array is always 0 based in the array:
so lets suppose i write const int N=10 for the size.
and then i run the loop till less than equal to n only then i have more number of places which i am looking for in the array but the array is smaller in size then that.
like as i said before:
N=5;
but we are looking for N+1 places in the array that is why it is giving segmentation fault.

so when you are declaring the array of size 100005 then you are already taking the array size as bit extra.

ohh… I got it, thank you so much

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.