Testcase timelimit

Whats the problem

why timelimit is being reached.

Hi @vivek21,
Your method to calculate prime number takes a lot of time.Instead try this method know as sieve of eratosthenes. In this method take a boolean array of size n+1 where n is the number till which you want to take out primes and save the value of all the index as “true” . And then i=2 till ii<=n traverse the array and if at any place value of boolean array is true then go into another inner loop from p=ii up till p<=n and in increments of p+=i and go all the array[p] = false;

not understood how to make boolean array. written code taking the words in mind -> https://ide.codingblocks.com/s/132614 but the code doesn’t work.

No you did not follow according to what i said . I know it is hard so i have made the code for you to make a array storing primes . If at a index i of array prime value stored is true that means it is a prime number.
Now you just have to count.
here is the code :- https://ide.codingblocks.com/s/132632

I was not aware about how arrays are made in java. I did it according to c++. Is there another method instead of using arrays as arrays have not came yet?

This method requires array and it reduces the time complexity so your code gets submitted …So you have have to use array and here it uses basic idea of array nothing much .

What’s wrong in this code -> https://ide.codingblocks.com/s/133984

See you should apply some common sense …You are trying to find 5 prime numbers in 0 to 4 … How is that even possible … There are lot of bugs … i have corrected your code to make it working but it will require a lot of understading so i have commented in the code … check that.