728x90
반응형

브루트 포스로 해결할 수 있다.
n이 1이 될 때까지 나누어준다.
//소인수분해
#include <iostream>
using namespace std;
int main(void){
int n, k = 2;
cin >> n;
while(n != 1){
if(n % k == 0){
n = n / k;
cout << k << "\n";
}
else{
k ++;
}
}
}
반응형
'algorithm' 카테고리의 다른 글
[algorithm] 백준 - 스타트와 링크 (0) | 2020.11.17 |
---|---|
[algorithm] 백준 - 단어수학 (0) | 2020.11.14 |
[algorithm] 백준 - 부분 수열의 합 2 (0) | 2020.11.10 |
[algorithm] 백준 - 카잉 달력 (0) | 2020.11.10 |
[algorithm] 백준 - 외판원 순회 2 (0) | 2020.11.06 |