题目描述
Count the number of prime numbers less than a non-negative number,
n
.
输入
一个整数n(n<=1000000)
输出
小于等于n的素数的数量
样例输入
10
样例输出
4
提示
Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int n,i,j;
cin>>n;
int s=0;
for(i=2;i<=n;i++)
{
int b=sqrt(i);
for(j=2;j<=b;j++)
if(i%j==0)
break;
if(j>b)
s++;
}
cout<<s;
return 0;
}