in this question according to the code i have written i am able to get correct answer for n upto 90000.The answer that i am getting is of the order 10^7. So if n equals to 5000000 the prime number will be greater than 10^9 .Even long long int won’t help so what to do?
Deepak and primes
Long long int can support numbers upto 10^18, so that will do fine in place of int. Also, this question requires the knowledge of the concept Sieve of Eratosthenes
. That topic is covered under the topic Number Theory. So if you have not gone through that video, I’d request you to first cover that topic then attempt this question.
Hope this helps.
I have used the sieve approach as discussed in the video.But my algo does give any answe for 5000000 prime number it gives 0.
The algo works fine for smaller numbers upto 90000.
So please tell me where is the problem?
Chances are you might have declared the loop variable as int. You have to declare even the loop variables as long long int data type.
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.