일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- c++
- 문자열
- object detection
- 세그먼트 트리
- 플로이드 와샬
- 이분 탐색
- NEXT
- 백트래킹
- BFS
- 가끔은_말로
- 미래는_현재와_과거로
- 자바스크립트
- back propagation
- dropout
- Overfitting
- 분할 정복
- 2023
- 회고록
- pytorch
- 가끔은 말로
- 알고리즘
- 우선 순위 큐
- 크루스칼
- 다익스트라
- 조합론
- 너비 우선 탐색
- dfs
- tensorflow
- lazy propagation
- DP
Archives
- Today
- Total
Doby's Lab
백준 17103번: 골드바흐 파티션 (C++) 본문
https://www.acmicpc.net/problem/17103
17103번: 골드바흐 파티션
첫째 줄에 테스트 케이스의 개수 T (1 ≤ T ≤ 100)가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있고, 정수 N은 짝수이고, 2 < N ≤ 1,000,000을 만족한다.
www.acmicpc.net
Solved By: Primality Test
#include <iostream>
#include <cmath>
#include <memory.h>
#define MAX 1000000
using namespace std;
int T;
int n;
bool isPrime[MAX];
void fastIO(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
void getPrime(){
memset(isPrime, true, sizeof(isPrime));
for(int i = 2; i <= sqrt(MAX); i++){
if(isPrime[i]){
for(int j = i + i; j <= MAX; j += i){
isPrime[j] = false;
}
}
}
return;
}
int gold(int v){
//cout << "Value is " << v * 2 << '\n';
int cnt = 0;
for(int i = 2; i <= v; i++){
if(isPrime[i] && isPrime[2 * v - i]){
//cout << i << ' ' << 2 * v - i << '\n';
cnt++;
}
}
return cnt;
}
int main(){
fastIO();
getPrime();
cin >> T;
while(T--){
cin >> n;
cout << gold(n / 2) << '\n';
}
return 0;
}
728x90
'PS > BOJ' 카테고리의 다른 글
백준 13237번: Binary tree (C++) (0) | 2022.07.24 |
---|---|
백준 2210번: 숫자판 점프 (C++) (0) | 2022.07.24 |
백준 24309번: 2021은 무엇이 특별할까? (C++) (0) | 2022.07.21 |
백준 24479번: 알고리즘 수업 - 깊이 우선 탐색 1 (C++) (0) | 2022.07.20 |
백준 17419번: 비트가 넘쳐흘러 (Python) (0) | 2022.07.18 |