Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
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 27
28 29 30
Archives
Today
Total
관리 메뉴

dh-winternagi 님의 블로그

(4948) 베르트랑 공준 본문

백준 (C++)/Solve

(4948) 베르트랑 공준

dh-winternagi 2026. 4. 15. 08:43

https://www.acmicpc.net/problem/4948

단계별로 풀어보기

15단계(약수, 배수와 소수 2) 7번째

 

 

 

#include <iostream>
using namespace std;
#define p 246913 // 1+123456*2

int main() 
{
  bool soe[p]= {true, true, false, };
  
  for(int i=4;i<=p;i+=2)  soe[i]= true;
  for(int i=3;i*i<=p;i+=2){
    if(soe[i])  continue;
    
    for(int j=i;i*j<=p;j+=2)  soe[i*j]= true;
  }
  
  while(true){
    int n, res= 0;
    
    cin >> n;
    
    if(!n)  break;
    
    for(int i=n+1;i<=2*n;i++)  res+= (!soe[i]);
    
    cout << res << "\n";
  }
  
  return 0;
}

'백준 (C++) > Solve' 카테고리의 다른 글

(13909) 창문 닫기  (0) 2026.04.15
(17103) 골드바흐 파티션  (0) 2026.04.15
(1929) 소수 구하기  (0) 2026.04.15
(4134) 다음 소수  (0) 2026.04.15
(2485) 가로수  (0) 2026.04.15