[백준 17103] 골드 바흐 파티션

alsry._.112·2023년 9월 30일
0

백준

목록 보기
70/102

🔗문제 풀러가기
단계별로 풀어보기 단계 15의 8번째 문제이다.

문제 분석

코드

#include <iostream>
using namespace std;

int arr[1000001];

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    for (int i = 2; i <= 1000001; i++)
    {
        arr[i] = i;
    }

    for (int i = 2; i * i <= 1000001; i++)
    {
        if (arr[i] == 0)
        {
            continue;
        }
        for (int j = i * i; j <= 1000001; j += i)
        {
            arr[j] = 0;
        }
    }

    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;

        int cnt(0);
        for (int i = 2; i < n; i++)
        {
            if (arr[n - i] + arr[i] == n)
            {
                cnt++;
                if (n - i == i)
                {
                    cnt++;
                }
            }
        }
        cout << cnt / 2 << "\n";
    }
}
profile
소통해요

0개의 댓글