I was recently trying to solve problem [problem:230B] and I'm getting WA on test 8, I don't know why. Also the solution comes out correct in my local compiler.↵
I need help.↵
attaching the solution.↵
[submission:244541266]↵
~~~~~↵
#include<bits/stdc++.h>↵
using namespace std;↵
#define ll long long↵
#define vv vector<long long> ↵
#define map map<long long, long long>↵
#define mapllc map<long long, char>↵
#define mapcll map<char, long long>↵
#define set set<long long>↵
#define loop0 for(ll i=0; i<n ; i++)↵
#define loop1 for(ll i=1; i<n; i++)↵
int main(){↵
bool sieve[1000001];↵
sieve[0]=sieve[1]=false;↵
ll m = 1000000;↵
for(int i = 2; i<=m; i++){↵
sieve[i]= true;↵
}↵
for(int i = 2; i*i<=m; i++){↵
if(sieve[i]==true){↵
for(int j = i*i; j<=m; j+=i){↵
sieve[j]=false;↵
}↵
}↵
}↵
ll n; cin>>n;↵
vv arr(n);↵
loop0{↵
ll temp; cin>>temp;↵
if((temp)==(sqrt(temp)*sqrt(temp))) arr[i] = sqrt(temp);↵
else arr[i] = 0;↵
}↵
loop0{↵
if(sieve[arr[i]]==true) cout<<"YES"<<endl;↵
else cout<<"NO"<<endl;↵
}↵
}↵
~~~~~↵
↵
I need help.↵
attaching the solution.↵
[submission:244541266]↵
#include<bits/stdc++.h>↵
using namespace std;↵
#define ll long long↵
#define vv vector<long long> ↵
#define map map<long long, long long>↵
#define mapllc map<long long, char>↵
#define mapcll map<char, long long>↵
#define set set<long long>↵
#define loop0 for(ll i=0; i<n ; i++)↵
#define loop1 for(ll i=1; i<n; i++)↵
int main(){↵
bool sieve[1000001];↵
sieve[0]=sieve[1]=false;↵
ll m = 1000000;↵
for(int i = 2; i<=m; i++){↵
sieve[i]= true;↵
}↵
for(int i = 2; i*i<=m; i++){↵
if(sieve[i]==true){↵
for(int j = i*i; j<=m; j+=i){↵
sieve[j]=false;↵
}↵
}↵
}↵
ll n; cin>>n;↵
vv arr(n);↵
loop0{↵
ll temp; cin>>temp;↵
if((temp)==(sqrt(temp)*sqrt(temp))) arr[i] = sqrt(temp);↵
else arr[i] = 0;↵
}↵
loop0{↵
if(sieve[arr[i]]==true) cout<<"YES"<<endl;↵
else cout<<"NO"<<endl;↵
}↵
}↵
~~~~~
↵