![[백준 / BOJ] 11653번 소인수분해 (C++, Python)](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fb0qZ6E%2FbtrJlWtbLoY%2Fsg9lfIgmjSA8xUkEuiGVs0%2Fimg.png)
[백준 / BOJ] 11653번 소인수분해 (C++, Python)◎ 자료구조와 알고리즘/백준(BOJ) 문제풀이2022. 4. 6. 21:37
Table of Contents
반응형
링크 : https://www.acmicpc.net/problem/11653
11653번: 소인수분해
첫째 줄에 정수 N (1 ≤ N ≤ 10,000,000)이 주어진다.
www.acmicpc.net
문제

문제 풀이
N이 i로 나누어지면 출력하는 식으로 반복해주면 된다.
C++ 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() { | |
int N; | |
cin >> N; | |
if (N == 1) return 0; | |
for (int i = 2; i <= N; ++i) { | |
while (N % i == 0) { | |
cout << i << "\n"; | |
N /= i; | |
} | |
} | |
} |
Python 코드 전문
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
N = int(input()) | |
i = 2 | |
while N != 1: | |
if N % i == 0: | |
N = N // i | |
print(i) | |
else: | |
i += 1 |
소감
반응형
'◎ 자료구조와 알고리즘 > 백준(BOJ) 문제풀이' 카테고리의 다른 글
[백준 / BOJ] 4948번 베르트랑 공준 (C++, Python) (0) | 2022.04.08 |
---|---|
[백준 / BOJ] 1929번 소수 구하기 (C++, Python) (0) | 2022.04.06 |
[백준 / BOJ] 2581번 소수 (C++, Python) (0) | 2022.04.06 |
[백준 / BOJ] 1978번 소수 찾기 (C++, Python) (0) | 2022.04.06 |
[백준 / BOJ] 10757번 큰 수 A + B (C++, Python) (0) | 2022.04.05 |
@Reo :: 코드 아카이브
자기계발 블로그