Please check code for Prime visit problem


Not able to pass all test cases.
I have one doubt also :In the function abc(), if I make i and j as int in the nested loop, I am getting segmentation fault but the loop just above it works fine with int data type. Why?

Hello @sahilkhan2312000131 https://ide.codingblocks.com/s/445587
corrected code and commented the mistake:

@sahilkhan2312000131 as here we are starting from i*i and i can be in the range 1000000 and when we take the sqaure of this then it will not be handle by only int thats we have to take long long here.
in the above loop there number is not big.

I have a doubt: Why is that the max limit of sieve is 10^7?? As limit of int is 10^9 shouldn’t it be 10^9??

@sahilkhan2312000131 if you are using the integer array then as int takes more space and we have to store only 1 and 0 for every index and we can optimise it using bool or bitset which will not be that consuming.
but i think for normal sieve questions 1e7 se zyada ki zarurat nahi hogi.

Actually I am asking this because if we are given a 10^10 number to check if its prime or not, then we make sieve and divide that number by sieve elements to check if its prime or not. Can we directly make bitset of size 10^10 instead?

@sahilkhan2312000131 have not you seen the editorail for sieve upto that range.
there must be editorial for that as well. if you will find it further.
There is some modification in that.

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.