티스토리 뷰

Algorithm/BOJ

백준 6718번 C++

poopooreum 2023. 8. 21. 17:14
반응형
백준 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
링크
«   2024/07   »
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
글 보관함