Code runs on my machine but not on online compiler

https://ide.codingblocks.com/s/292222 . Also can you please check the logic too?

@girishgargcool remve this part to run it in cb IDE
image

I tried submitting it on SPOJ without these lines. Still it shows Segmented sieve error

@girishgargcool you are not considering the edges, areas can be formed with the edges also. see this

https://ide.codingblocks.com/s/292232 . This is the initial code that I wrote considering both left and right edge cases. But still it gives me Segmentation Fault on SPOJ. Also in the video bhaiya considered only right edge case, why not left?

@girishgargcool he considered 0 case also. I’ll look at this code, wait

hi @girishgargcool The code where you have considered both edges seems correct to me, can you try first reserving some space in the vector and taking input for v[i] insted of doing a push_back operation? You can see the code that I have shared above uses the same logic exactly and it passed all the test cases.

https://ide.codingblocks.com/s/292246 Shows WA this time

@girishgargcool why are you reserving so much space? reserve only that much what is needed. now what will happen is that v.back() will give the element at index 10004.

https://ide.codingblocks.com/s/292254 . Reduced space. Still WA

https://ide.codingblocks.com/s/292260 . Used alternative for back() . still WA

@girishgargcool keep the space as N, you will get it as input in each case.

https://ide.codingblocks.com/s/292267 . Done. Shows SEGMENTATION FAULT now

@girishgargcool i think you totally missed the point here, whats the point of reserving space if you are doing push pack operation anyway? Take input as simply cin >> v1[i] >> v2[i];
image
I also changed the way to handle the corner cases in a single for loop only, this code is getting AC. (without making this change it kept giving segmentation fault, so you can try dry running for different cases to see why is that)

Thank you. Understood now

1 Like

@girishgargcool dont forget to mark the doubt as resolved!