#include <string> #include <vector> using namespace std; int find_decimal(int n) { int cnt = 0; int a[1000000] = {0}; // 에라토스테네스의 체 for(int i = 2; i <= n; i++) { if(a[i] == 1) { continue; } for(int j = i+i; j <= n; j+=i) { a[j] = 1; } } for(int i = 2; i <= n; i++) { if(a[i] == 0) { cnt++; } } return cnt; } int solution(int n) { int answer = find_decimal(n); return answer; } | cs |
'Programmers > Level 1' 카테고리의 다른 글
[프로그래머스 1] 문자열을 정수로 바꾸기 (C/C++) (0) | 2019.10.17 |
---|---|
[프로그래머스 1] 수박수박수박수박수박수? (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 서울에서 김서방 찾기 (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 문자열 다루기 기본 (C/C++) (0) | 2019.10.17 |
[프로그래머스 1] 문자열 내림차순으로 배치하기 (C/C++) (0) | 2019.10.17 |