Algorithm/Problem Solving 2020. 5. 16. 14:59

(공감과 댓글 하나는 글쓴이에게 큰 힘이 됩니다.)

 

문제 링크

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

 

사용 알고리즘

 

풀이

- 2부터 루트N까지 루프를 돌며 나눠지지 않을 때 까지 계속 나누며 출력

- N 자체가 소수일 수도 있으므로 해당 부분 처리

 

소스 코드

- https://github.com/moomini/algorithm/tree/master/boj

#include <cstdio>
 
int main(void) {
    int n; scanf("%d"&n);
    for (int i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            printf("%d\n", i);
            n /= i;
        }
    }
    if (n > 1printf("%d\n", n);
    return 0;
}
cs

'Algorithm > Problem Solving' 카테고리의 다른 글

[BOJ/1676] 팩토리얼 0의 개수  (0) 2020.05.17
[BOJ/10872] 팩토리얼  (0) 2020.05.16
[BOJ/6588] 골드바흐의 추측  (0) 2020.05.15
[BOJ/1929] 소수 구하기  (0) 2020.05.14
[BOJ/1978] 소수 찾기  (0) 2020.05.13
posted by DevMoomin
: