| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 연결리스트
- 이분 탐색
- tcache
- 분할 정복
- 완전 탐색
- off by one
- 백트래킹
- heap
- 큐
- 스택
- DFS
- 문자열 처리
- BOF
- 동적 계획법
- OOB
- House of Orange
- 이진트리
- syscall
- fsb
- 브루트 포스
- 이진 탐색
- ROP
- RTL
- 에라토스테네스의 체
- 포맷스트링버그
- 투 포인터
- 수학
- 다이나믹 프로그래밍
- 스위핑 알고리즘
- BFS
Archives
- Today
- Total
SDJ( 수돈재 아님 ㅎ )
[C++] 17014 - Pretty Average Primes 본문
문제 링크 : https://www.acmicpc.net/problem/17014
17014번: Pretty Average Primes
You may have heard about Goldbach’s conjecture, which states that every even integer greater than 2 can be expressed as the sum of two prime numbers. There is no known proof, yet, so if you want to be famous, prove that conjecture (after you finish the CCC
www.acmicpc.net
|
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include<iostream>
#include<algorithm>
#define endl '\n'
using namespace std;
bool eratos[2000005];
void E()
{
for(int i = 2; i*2 <= 2000005; ++i)
{
if(!eratos[i])
{
for(int j = i*2; j <= 2000005; j += i)
eratos[j] = 1;
}
}
}
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
E();
int n;
int T;
cin >> n;
while(n--)
{
cin >> T;
for(int i = 0; i < T-1; ++i)
{
if(!eratos[T+i] && !eratos[T-i])
{
cout << T-i << ' ' << T+i << endl;
break;
}
}
}
return 0;
}
|
'알고리즘 > Backjoon' 카테고리의 다른 글
| [C++] 15990 - 1, 2, 3 더하기 5 (0) | 2020.01.09 |
|---|---|
| [C++] 17013 - Flipper (0) | 2020.01.09 |
| [C++] 17011 - Cold Compress (0) | 2020.01.09 |
| [C++] 2659 - 십자카드 문제 (0) | 2020.01.09 |
| [C++] 1074 - Z (0) | 2020.01.09 |
Comments