Skip to content

Commit

Permalink
[정수론] 3월 4일
Browse files Browse the repository at this point in the history
  • Loading branch information
ri-naa committed Mar 4, 2024
1 parent f1747d3 commit e1f63bf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
5 changes: 5 additions & 0 deletions 03_정수론/필수/1735.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ vector<int> add(int a1, int a2, int b1, int b2) {
}

int main() {
//입출력 속도 향상
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int a1, a2, b1, b2;

cin >> a1 >> b1;
Expand Down
9 changes: 7 additions & 2 deletions 03_정수론/필수/2840.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using namespace std;

vector<char> random (int n, int k) {
vector<char> lucky_wheel (int n, int k) {
vector<char> v(n, '?'); //처음 가르킨 곳이 v[0] 알파벳
int cnt;
int order = 0;
Expand Down Expand Up @@ -43,11 +43,16 @@ vector<char> random (int n, int k) {


int main() {
//입출력 속도 향상
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

int n, k;
cin >> n >> k;

vector<char> result;
result = random(n, k);
result = lucky_wheel(n, k);

if(result[0] == '!'){
cout << '!';
Expand Down
43 changes: 34 additions & 9 deletions 03_정수론/필수/6588.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

/*
b - a가 가장 큰 경우가 언제일지 잘 생각해보아요!
n = a + b를 만족시키는 두 소수들을 어디서부터 탐색하면 좋을까요?
*/
using namespace std;

int getPrime() {
vector<bool> prime(1000001, true); // 인덱스 0부터 1000000까지 사용

}
// 에라토스테네스의 체 이용하기
void findPrime() {
prime[0] = prime[1] = false;

for (int i = 2; i * i <= 1000000; ++i) {
if (prime[i]) {
for (int j = i * i; j <= 1000000; j += i) {
prime[j] = false;
}
}
}
}

int main() {
//입출력 속도 향상
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

findPrime();

int input;
cin >> input;

while(input != 0) {
getPrime();

bool check = false;
for(int i=3; i <= input/2; i++) {
if(prime[i] && prime[input-i]) {
cout << input << " = " << i << " + " << input-i << '\n';
check = true;
break;
}
}

if(!check) {
cout << "Goldbach's conjecture is wrong." << '\n';
}

cin >> input;
}

}

0 comments on commit e1f63bf

Please sign in to comment.