[BOJ] 11653번 : 소인수분해

2024. 9. 22. 19:26Algorithm

1. problem : 

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

 

 

2. solution 1 :

#include <bits/stdc++.h>
using namespace std;
int n; 

vector<int> prime_factor(int n) {
	vector<int> ans; 
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ans.push_back(i); 
			n /= i;
		}
	}
	if (n != 1) ans.push_back(n);
	return ans; 
}
int main(void) {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n; 
	vector<int> ans = prime_factor(n);
	for (auto p : ans) cout << p << '\n';
}

source code 출처 : https://github.com/encrypted-def/basic-algo-lecture/blob/master/0x12/solutions/11653.cpp

 

basic-algo-lecture/0x12/solutions/11653.cpp at master · encrypted-def/basic-algo-lecture

바킹독의 실전 알고리즘 강의 자료. Contribute to encrypted-def/basic-algo-lecture development by creating an account on GitHub.

github.com

아직 완벽히 이해가 가지않는다. ( N이 합성수라면, x <= root(N) 을 만족하는 소인수를 가진다.)

'Algorithm' 카테고리의 다른 글

[BOJ] 11050번 : 이항 계수 1  (0) 2024.09.24
[BOJ] 15988번 : 1,2,3 더하기 3  (0) 2024.09.23
[BOJ] 1929번 : 소수 구하기  (1) 2024.09.22
[BOJ] 1978번 : 소수 찾기  (1) 2024.09.22
[BOJ] 2156번 : 포도주 시식  (0) 2024.09.22