Prateek loves candy i am getting some error

@lukharshiv,
you are exceeding the limit of int at i*i in prime method.

Instead do something like:

		int n = 1000005;
		for (int i = 3; i < n; i = i + 2) {
			p[i] = 1;
		}
		for (int i = 2; i < n; i = i + 2) {
			if (p[i] == 1) {
				for (int j = 2; i * j < n; j = j + 1) {
					p[i * j] = 0;
				}
			}
		}
		p[2] = 1;
		p[1] = p[0] = 0;

Also, call the prime method before the count. Because right now you are computing sieve for every input. The entire point of sieve is to calculate prime numbers in a range before hand.

Can you please tell me how can I write the output of 5th place prime number

What logic should I use for output?

@lukharshiv,
you can keep a temp variable. Initially temp=0, increment temp if p[i] =1, and use the condition that if temp==count, print i

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.