If prime[prime.size()-1] = 31607 then prime[prime.size()] = 0. This is the cause of your runtime error. This is because prime[j] = 0 then prime[j] <= temp is true, the next if statement (i % prime[j]==0) causes runtime error because i / 0 is divide by zero.
How to solve this? Make sure that the largest number in prime is greater than 312622 or that j is also within the range of the size of the list of primes.