Playing wtih cards

getting faults in this problem

Hey @guptashubham210a, I believe you’re trying to access the index of the vector which you have not even initialized, (use zero-based indexing everywhere) and resize the vectors before using them.
If you still feel stuck, you can refer to this solution.
Hope this helps.

@Yashwardhan_Gautam](http://discuss.codingblocks.com/u/Yashwardhan_Gautam)

but I am pushing prime no only na and by v[1] I will get 1st prime no so whats the problem for ith prime?
and what do you mean by use zero-based indexing everywhere and resize the vectors before using them?

Try accessing the vector v, it’ll throw an error, because there was some issue with the sieve function written, I have made the changes to fix that, check it here. But still check once the logic, you’re running inside the for loop from 1 to q, since the final output is different. you can refer to the solution in pervious post.

@Yashwardhan_Gautam](http://discuss.codingblocks.com/u/Yashwardhan_Gautam)
got it it should be from 0 to q-1 for prime or instead of this v[i-1].

1 Like

@Yashwardhan_Gautam](http://discuss.codingblocks.com/u/Yashwardhan_Gautam)
what was the problem in seive function pls tell my mistake?

1 Like

@Yashwardhan_Gautam](Playing wtih cards)
getting only one test case pass other are getting wrong why? I have made changes also then?

Try dry running what you’re doing in the code, the logic is not correct, you can take reference from the code in first comment.

The problem with the sieve code is in line number 17
for (ll j = i * i; i < n; j += i),
it should be for(ll j=i*i;j<n;j+=i)

@Yashwardhan_Gautam
I got the logic but what we are doing on line no 50 s1=s3 will this store in same order or first pop from s3 then store in s1?

Yes.
Moreover, you can always put different debugging statements in the code to check, how it should.
If it’s clear, you can mark it resolved and also rate if you’d like :slight_smile:

@Yashwardhan_Gautam](http://discuss.codingblocks.com/u/Yashwardhan_Gautam)
I didn’t get it same order or reversed order of s3?

s3=s1 simply makes a copy of s1 and paste it into s3, the order.
if the order of the elements in s1 is 1,2,3 it’ll remain the same in s3 as well.