Why am I getting segmentation fault in the following code?

#include
#include
using namespace std;

vector primes;
bool b[1000005];

void sieve(){

b[0]=b[1]=false;
b[2]=true;

for(int i=3;i<=1000000;i+=2){
	b[i]=true;
}

for(int i=3;i<=1000000;i+=2){
	if(b[i]){
		for(int j=i*i;j<=1000000;j+=(2*i)){
			b[j]=false;
		}
	}
}

for(int i=0;i<=1000000;i++){
	if(b[i]){
		primes.push_back(i);
	}
}

}

int main(){

int t;
cin>>t;

sieve();

while(t--){

	int n;
	cin>>n;

	cout<<primes[n-1]<<endl;

}

return 0;

}

Please share your code using ide.codingblocks.com , will let you know mistake.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.