Deepak and Prime

test case 0 and 1 are showing wrong,
my code is https://ide.codingblocks.com/s/208017

hi @AlphaX, since here n is the number of primes which can be as large as 5000000 thus you need a larger array range aprrox 10^7 and declare it as global. so just change the size of your array and check

i had globaly declared prime array and increased size of prime array to 10^8 but still both above test cases are showing wrong
my new code is https://ide.codingblocks.com/s/208133

Hi @AlphaX, there are some small problem in your code like : -

  1. instead of initializing your prime array with 0 , you have to initialize you prime as 1 because what seive of erastothenes does , is to find non prime numbers and we conclude that remaining will be prime i.e. “seive” out non prime number now u know where this name comes
  2. you don’t need to store all n elements in a array , as why use extra memory when we only have to print the nth prime number
  3. i did;nt understand why u used count , also u are not initializing it with any value
  4. at line 8 . for(long long i=3;i<=100000000;i+=2) it should start with 4 as you are marking all even values as non prime except 2

you can refer to this code : https://ide.codingblocks.com/s/185987
in case of any doubt feel free to ask :slight_smile: