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 님의 블로그

(17103) 골드바흐 파티션 본문

백준 (C++)/Solve

(17103) 골드바흐 파티션

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

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

단계별로 풀어보기

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

 

 

 

#include <iostream>
using namespace std;
#define p 1000001

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;
  }
  
  int T;
  
  cin >> T;
  
  while(T--){
    int n, res= 0;
    
    cin >> n;
    
    for(int i=2;2*i<=n;i++){
      if(!soe[i] && !soe[n-i])  res++;
    }
    
    cout << res << "\n";
  }
  
  return 0;
}

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

(28278) 스택 2  (0) 2026.04.15
(13909) 창문 닫기  (0) 2026.04.15
(4948) 베르트랑 공준  (0) 2026.04.15
(1929) 소수 구하기  (0) 2026.04.15
(4134) 다음 소수  (0) 2026.04.15