#include <string>
#include <vector>
using namespace std;
int a[1000001]={0, };
int solution(int n) {
int answer = 0;
for(int i=2; i<=n; i++)
a[i]=1;
for(int k=2; k<=n/2; k++){
for(int j=2; j*k<=n; j++){
a[k*j]=0;
}
}
for(int z=2; z<=n; z++){
if(a[z]==1){
answer++;
}
}
return answer;
}
'Programming > Algorithm (C++)' 카테고리의 다른 글
c06 (0) | 2021.03.04 |
---|---|
[프로그래머스 1단계] c++: : 문자열을 정수로 바꾸기 (0) | 2021.03.01 |
[프로그래머스 1단계] c++:: string 클래스의 substr() (0) | 2021.03.01 |
[프로그래머스 레벨1] c++ :: 두개 뽑아서 더하기 (2) | 2021.02.28 |
[백준 2579] c++ :: 계단 오르기 (0) | 2021.02.07 |