The code is running fine for smaller no.s, but for bigger no.s it is giving run error in hacker blocks.
Code https://ide.codingblocks.com/s/115467
Question https://hack.codingblocks.com/contests/c/925/700
Problem in Deepak and Prime
@ratulhans
As the problem says , you are required to print nth prime number where n can be as large as 50000. 50000th prime number is a little over 86 million while you are only computing primes till 50000. Increase your sieve array size to 87 million to be safe to that it covers all cases.
Also change the data type of loop counter variable j to long long int or it will give you a runtime error.
Also your code gives wrong answers to even small inputs due to invalid initialisation of variable cnt. While passing the argument , give it value 1 rather than 0.
cout<<prime(m,1);
or otherwise it shows 5 as the 2nd prime number instead of 3 as its counter is always one ahead always.
Thanks now it’s working.
@ratulhans
I request you to mark your doubt as Resolved in your Doubts Section. If you have any further issues regarding your doubt , let me know so I can help you out.
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.