문제) 백준 - 정수론 - 소인수분해
https://www.acmicpc.net/problem/11653
11653번: 소인수분해
첫째 줄에 정수 N (1 ≤ N ≤ 10,000,000)이 주어진다.
www.acmicpc.net
소인수분해 기본 문제. k를 2부터 증가시키면서 나눠질 경우 출력 후 나눈다.
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 <bits/stdc++.h> | |
#define endl "\n" | |
#define MAX 501 | |
using namespace std; | |
typedef pair<int, int> p; | |
signed main(){ | |
ios::sync_with_stdio(0); | |
cin.tie(0); cout.tie(0); | |
int n; cin >> n; | |
int k = 2; | |
while (n != 1) { | |
if (n % k == 0) | |
{ | |
n /= k; | |
cout << k << endl; | |
} | |
else | |
k++; | |
} | |
} |
반응형
'PS(Problem Solving) > 백준_BOJ' 카테고리의 다른 글
[백준] 4811번 - 알약 (C++) 문제 및 풀이 (0) | 2021.09.29 |
---|---|
[백준] 20040번 - 사이클 게임 (C++) 문제 및 풀이 (0) | 2021.09.28 |
[백준] 14881번 - 물통 문제 (C++) 문제 및 풀이 (0) | 2021.09.24 |
[백준] 1972번 - 놀라운 문자열 (C++) 문제 및 풀이 (0) | 2021.09.23 |
[백준] 2631번 - 줄세우기 (C++) 문제 및 풀이 (0) | 2021.09.03 |
댓글