it is working for 10 testcases but not for 100 testcases
Cant find error
no it is not accepted in leetcode you can see the error in the photo
@manasrustagi16
first change int to long long int and i<=n to i<n if still error u can send the code
class Solution {
public:
int countPrimes(int n) {
long long int count=0;
bool* p = new bool[n];
for(int i=3;i<n;i+=2)
{
p[i]=1;
}
for(int i=3;i<n;i+=2)
{
if(p[i]==1)
{
for(int j=i*i;j<=n;j+=i)
{
p[j]=0;
}
}
}
p[2]=1;
p[1]=p[0]=0;
for(int i=2;i<n;i++)
{
if(p[i]==1)
{
count++;
}
}
return count;
}
};
still not working showing this Line 28: Char 15: runtime error: load of value 190, which is not a valid value for type ‘bool’ (solution.cpp)
@manasrustagi16 check the updated code https://ide.codingblocks.com/s/658923
commented as well
hope the doubt is clear
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.