티스토리 뷰
반응형
백준 6718번 Goldbach's conjecture
https://www.acmicpc.net/problem/6718
6718번: Goldbach’s conjecture
An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 215. The end of the input is indicated by a number 0.
www.acmicpc.net



정답 코드
#include<iostream>
#include<math.h>
using namespace std;
int arr[500001] = { 1, };
int main() {
int n;
for (int x = 2; x <= sqrt(500001); x++) {
for (int y = x * x; y <= 500001; y+=x) {
if (arr[y] != 0)
continue;
arr[y] = 1;
}
}
int count;
while (1) {
count = 0;
cin >> n;
if (n == 0)
return 0;
for (int x = 2; x <= n; x++) {
if (x <= n - x && arr[x] == 0 && arr[n - x] == 0)
count++;
}
cout << count << '\n';
}
}
문제 풀이
6588번 풀고 그냥 영어로 된 거 한 번더 풀어봤어요
풀이는 여기 누르시면 될 것 같아용
반응형
'Algorithm > BOJ' 카테고리의 다른 글
백준 7562번 C++ (0) | 2023.08.22 |
---|---|
백준 7287번 C++ (0) | 2023.08.21 |
백준 6603번 C++ (0) | 2023.08.21 |
백준 6593번 C++ (0) | 2023.08.21 |
백준 6588번 C++ (0) | 2023.08.21 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 유클리드 호제법
- java
- 우선순위 큐
- 알고리즘 공부
- 카운팅 정렬
- 백준 풀이
- 자바스크립트
- 스택
- js
- Do it!
- 세그먼트 트리
- CSS
- html
- DFS
- 자료구조
- 반복문
- DP
- 알고리즘
- HTML5
- 투 포인터
- C++ Stack
- 스프링 부트 crud 게시판 구현
- 이분 매칭
- 에라토스테네스의 체
- 백준
- 자바
- C++
- 유니온 파인드
- c++ string
- BFS
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
글 보관함