public class Solution

{

public int CountPrimes(int n)

{

bool isP=false;

int count=0;

if (n >3)

{

count = 3;

for (int i = 3; i < n; i=i+2)

{

isP = isPri(i);

if (isP == true)

count++;

}

```
}
else if(n<=3&&n>0)
{
count=n;
}
return count;
}
public bool isPri(int i)
{
if (i <= 3)
{
return true;
}
else
{
for (int j = 2; j < Math.Sqrt(i); j++)
{
if (i % j == 0)
{
return false;
}
}
return true;
}
}
}
```