When I'm trying to use sieve, it gives me "runtime error: signed integer overflow: 46349 * 46349 cannot be represented in type 'int'" for long long int j = i*i; line.. but the variable j is already long long int, not int, why is it still gives me error?
#include<bits/stdc++.h>
using namespace std;
bool Eliminated[1000001];
int N;
void Sieve(){
Eliminated[1]=true;
for(int i = 2;i<=1000000;i++){
if(Eliminated[i]==false){
long long int j = i*i;
while(j<=1000000){
Eliminated[j]=true;
j=j+i;
}
}
}
}
int main(){
Sieve();
cin>>N;
long long int arr[N];
for(int i = 0;i<N;i++){
cin>>arr[i];
long long int temp = sqrt(arr[i]);
if(temp*temp==arr[i]){
if(Eliminated[temp]==false){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}else{
cout<<"NO"<<endl;
}
}
}