1부터 n까지의 prime number 갯수 찾는것이다.
가장 기본적인 형태로 구현하였음.
#include <string>
#include <vector>
using namespace std;
bool IS_PRIME(int n)
{
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
int solution(int n) {
int answer = 0;
for (int i = 2; i <= n; i++)
if (IS_PRIME(i))
answer++;
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV1 문자열을 정수로 바꾸기 (0) | 2022.04.26 |
|---|---|
| [프로그래머스] (C++) LV1 수박수박수박수박수박수? (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 서울에서 김서방 찾기 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 문자열 다루기 기본 (0) | 2022.04.26 |
| [프로그래머스] (C++) LV1 문자열 내림차순으로 배치하기 (0) | 2022.04.26 |