Prateek bhaiya loves candy

So instead of calculating sieve array again and again for each test case , i calculated sieve array one at the start of main
but i am getting segmentation fault and it doesnt show up when i replace j+=2 with j++

@nischay1111 i have seen your code , you have used int data type for ‘i’& ‘j’
and you are performing j*j operation which will overflow for int data type,
so try using long or long long
for refernce see this code

hey aman i tried to run your code
but getting this

Also when i tried to run the original code i sent tou with replacing int by long long
i failed 1 test case


here is the link

Actually it is long long try that. I just saw that long has a range similar to int.

I tried
also made all variable including count long long

Let me try again. Ill tell you as soon as i do

@nischay1111 https://ide.codingblocks.com/s/227071
try this
in question x-th prime number is asked where 1<=x<=10^6,so size of array wiil be upto the 10^6th prime number

Thanks a lot for help !!
so i guess that the issue was of optimization
instead of running loop for each test case , we calculated array of prime numbers once and used it for all cases

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.