링크 : https://www.acmicpc.net/problem/11653
소인수분해. 2,3을 따로 나눠주면 빨르게 처리 가능했던 것을 기억하며 진행하자.
#include <iostream>
#include <algorithm>
using namespace std;
void prime(int N) {
int limit = N;
int key = 2;
while (key <= N) {
if (N == 2) {
cout << 2 << endl;
return;
}
else if (N == 3) {
cout << 3 << endl;
return;
}
if (N % key == 0) {
cout << key << endl;
N = N / key;
}
else
key++;
}
}
int main() {
int N;
cin >> N;
prime(N);
return 0;
}
다음 블로그를 참고하였다. 링크 : https://aossuper8.tistory.com/7
소인수분해를 하면서 원래의 N을 나눠주는 것. 잊지말자.