Problem


Logic

분석

  • 문제 유형 (알고리즘…)
  • 제약 조건 (인풋 크기, 예외 값, 시공간 복잡도…)

설계

  1. 알고리즘 선택
  2. 자료구조 선택
  3. 수도 코드 작성
  4. 정합판단
  • 1 ~ 3과정으로 도출된 로직이 문제를 해결하는가
    • 그렇다 구현
    • 잘 모르겠다 구현
    • 아니다 1번부터 다시 점검

구현

  • 로직 검증

테스트

  • 예외 케이스 고려

My Code

cpp

boj/4948.cpp
// https://www.acmicpc.net/problem/4948
#include <iostream>
using namespace std;
 
#ifdef LOCAL
#    define LOG clog
#else
struct nullstream : ostream {
    nullstream()
        : ostream(nullptr) {}
};
nullstream LOG;
#endif
 
//--------------------------------------------------------------------------------------------------
 
#define MAX (1234567891)
#define MIN (-1234567891)
 
#include <cmath>
#include <iostream>
#include <vector>
 
int main() {
    //   logic
    int          max_bound = 123456 * 2;
    vector<bool> t(max_bound + 1, true);
    t[1] = false;
 
    for (int i = 2; i <= sqrt(max_bound); ++i) {
        if (t[i] == false) {
            continue;
        }
 
        for (int j = i * i; j <= max_bound; j += i) {
            t[j] = false;
        }
    }
 
    int n;
    cin >> n;
    while (n != 0) {
        int count = 0;
 
        for (int i = n + 1; i <= n * 2; ++i) {
            if (t[i]) {
                count++;
            }
        }
        cout << count << "\n";
 
        cin >> n;
    }
}