BOJ : https://www.acmicpc.net/problem/1978

GitHub : https://github.com/junho0956/Algorithm/blob/master/1978/1978/%EC%86%8C%EC%8A%A4.cpp

 

소수를 찾기위한 정확한 개념을 기억해두자.

** 소수는 소수로 나누어떨어지지 않는다.

 

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//에라토스테네스의 체
#include <iostream>
using namespace std;
 
#define MAX 1001
 
bool sosu[MAX];
 
int main() {
    for (int i = 2; i < MAX; i++) sosu[i] = true;
 
    for (int i = 2; i * i < MAX; i++) {
        if (!sosu[i]) continue;
        for (int k = i * i; k < MAX; k += i) sosu[k] = false;
    }
 
    int N,n, cnt=0cin >> N;
 
    while (N--) {
        cin >> n;
        cnt += sosu[n];
    }
 
    cout << cnt;
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 6588번 골드바흐의 추측  (0) 2020.01.13
BOJ 1929번 소수 구하기  (0) 2020.01.13
BOJ 2089번 -2진수  (0) 2020.01.13
BOJ 1212번 8진수 2진수  (0) 2020.01.13
BOJ 1373번 2진수 8진수  (0) 2020.01.13

+ Recent posts