Getting heap space

Hi,

When I was calculating prime for 2 to 1000000000 the i am getting heal space. how to decide up to what number we need to calculate prime number?

  • Take input of the number.
  • put a loop from 2 to that number.
  • If the number gets divided by any number in the loop, that means the number is not Prime.
  • Othewise, Prime.