算法笔记5.4
前n个素数的求法:埃氏筛
leetcode204:https://leetcode-cn.com/problems/count-primes/
算法笔记5.4
素数也叫做质数
#include <iostream>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
int arr[10000]={0};
int numberofprime(int num){
int cnt=0;
if(num<2)return 0;
for(int i=2;i<=num;i++){
if(arr[i]==0){
cnt++;
printf("%d ",i);
for(int j=i+i;j<=num;j+=i){
arr[j]=1;
}
}
}
return cnt;
}
int main()
{
int n=100;
scanf("%d",&n);
n=numberofprime(n);
printf("The Number of the Prime are:%d",n);
return 0;
}