BOJ : https://www.acmicpc.net/problem/11653

GitHub : https://github.com/junho0956/Algorithm/blob/master/11653/11653/%EC%86%8C%EC%8A%A4.cpp

 

** 사실 이 문제는 소수를 구해놓고 답을 찾지 않아도 된다

 

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cstdio>
#pragma warning(disable:4996)
#define Max 10000001
 
 
int main() {
 
    int N;
    scanf("%d"&N);
 
    for (int i = 2; i <= N; i++)
    {
        if (N % i == 0) {
            printf("%d\n", i);
            N /= i;
            i--;
        }
    }
 
    return 0;
}

'algorithm > BOJ' 카테고리의 다른 글

BOJ 1676번 팩토리얼 0의 개수  (0) 2020.01.13
BOJ 10872번 팩토리얼  (0) 2020.01.13
BOJ 6588번 골드바흐의 추측  (0) 2020.01.13
BOJ 1929번 소수 구하기  (0) 2020.01.13
BOJ 1978번 소수 찾기  (0) 2020.01.13

BOJ : https://www.acmicpc.net/problem/6588

GitHub : https://github.com/junho0956/Algorithm/blob/master/6588/6588/%EC%86%8C%EC%8A%A4.cpp

 

가장 작은 홀수이자 소수인 3부터 N-3 을 해가며 짝을 찾아주면된다.

처음에 시간초과가 뜨길래 문제가 있나 싶었는데

ios::sync_with_stdio(false) 는 사용했으면서 cin.tie(NULL)을 해줘야되는지 몰랐다,, 알았으니 됬다

 

더보기
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
#include <iostream>
using namespace std;
#define Max 1000001
 
bool arr[Max];
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    for (int i = 2; i < Max; i++) arr[i] = true;
    for (int i = 2; i * i < Max; i++) {
        if (!arr[i]) continue;
        for (int k = i * i; k < Max; k += i) arr[k] = false;
    }
 
    int num;
    while (1) {
        cin >> num;
        if (!num) break;
        for (int i = 3; i < Max; i+=2) {
            if (arr[i] && arr[num - i]) {
                cout << num << " = " << i << " + " << num - i << '\n';
                break;
            }
        }
    }
 
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 10872번 팩토리얼  (0) 2020.01.13
BOJ 11653번 소인수분해  (0) 2020.01.13
BOJ 1929번 소수 구하기  (0) 2020.01.13
BOJ 1978번 소수 찾기  (0) 2020.01.13
BOJ 2089번 -2진수  (0) 2020.01.13

BOJ : https://www.acmicpc.net/problem/1929

GitHub : https://github.com/junho0956/Algorithm/blob/master/1929/1929/%EC%86%8C%EC%8A%A4.cpp

 

에라토스테네스의 체에 대한 개념을 알고있다면 해결할 수 있다.

 

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
#define Max 1000001
 
bool arr[Max];
 
int main() {
    ios::sync_with_stdio(0);
    for (int i = 2; i < Max; i++)
        arr[i] = true;
 
    for (int i = 2; i * i < Max; i++) {
        if (!arr[i]) continue;
        for (int k = i * i; k < Max; k += i) arr[k] = false;
    }
 
    int N, M;
    cin >> N >> M;
    for (int i = N; i <= M; i++) {
        if (arr[i]) cout << i << '\n';
    }
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 11653번 소인수분해  (0) 2020.01.13
BOJ 6588번 골드바흐의 추측  (0) 2020.01.13
BOJ 1978번 소수 찾기  (0) 2020.01.13
BOJ 2089번 -2진수  (0) 2020.01.13
BOJ 1212번 8진수 2진수  (0) 2020.01.13

BOJ : https://www.acmicpc.net/problem/1978

GitHub : https://github.com/junho0956/Algorithm/blob/master/1978/1978/%EC%86%8C%EC%8A%A4.cpp

 

소수를 찾기위한 정확한 개념을 기억해두자.

** 소수는 소수로 나누어떨어지지 않는다.

 

더보기
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
//에라토스테네스의 체
#include <iostream>
using namespace std;
 
#define MAX 1001
 
bool sosu[MAX];
 
int main() {
    for (int i = 2; i < MAX; i++) sosu[i] = true;
 
    for (int i = 2; i * i < MAX; i++) {
        if (!sosu[i]) continue;
        for (int k = i * i; k < MAX; k += i) sosu[k] = false;
    }
 
    int N,n, cnt=0cin >> N;
 
    while (N--) {
        cin >> n;
        cnt += sosu[n];
    }
 
    cout << cnt;
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter

'algorithm > BOJ' 카테고리의 다른 글

BOJ 6588번 골드바흐의 추측  (0) 2020.01.13
BOJ 1929번 소수 구하기  (0) 2020.01.13
BOJ 2089번 -2진수  (0) 2020.01.13
BOJ 1212번 8진수 2진수  (0) 2020.01.13
BOJ 1373번 2진수 8진수  (0) 2020.01.13

+ Recent posts