Sorry, but i won’t be of much help in C++
The error is because of array bounds.
The maximum size of vector primes is the total number of primes less than
5000001. But here you are required to find the 5000000th prime which is surely not possible.
Look at my code : https://ideone.com/ktN2u7
Re-read the constraints (and the problem)