문제 링크입니다: https://www.acmicpc.net/problem/2501
2501번: 약수 구하기
첫째 줄에 N과 K가 빈칸을 사이에 두고 주어진다. N은 1 이상 10,000 이하이다. K는 1 이상 N 이하이다.
www.acmicpc.net
N이 10,000 이하이기 때문에 완전탐색법으로 찾으면 되는 문제였습니다.
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(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N, K; | |
cin >> N >> K; | |
int cnt = 0; | |
bool flag = false; | |
for (int i = 1; i <= N; i++) | |
{ | |
if (N % i == 0) | |
{ | |
cnt++; | |
if (cnt == K) | |
{ | |
cout << i << "\n"; | |
flag = true; | |
break; | |
} | |
} | |
} | |
if (!flag) | |
{ | |
cout << 0 << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 15736번 청기 백기 (0) | 2019.10.21 |
---|---|
백준 1145번 적어도 대부분의 배수 (0) | 2019.10.21 |
백준 1253번 좋다 (2) | 2019.10.21 |
백준 2467번 용액 (0) | 2019.10.21 |
백준 7785번 회사에 있는 사람 (0) | 2019.10.21 |