Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- Method
- array
- Number Theory
- Binary Search
- 구현
- implement
- 파이썬
- hash table
- SQL
- 코테
- simulation
- Counting
- Math
- Class
- database
- dynamic programming
- Binary Tree
- two pointers
- Stack
- 자바
- Tree
- bit manipulation
- Data Structure
- java
- greedy
- string
- Matrix
- sorting
- 코딩테스트
- geometry
Archives
- Today
- Total
코린이의 소소한 공부노트
[백준 온라인 저지] 2501. 약수 구하기 본문
- 입력: 첫째 줄에 N과 K가 빈칸을 사이에 두고 주어진다. N은 1 이상 10,000 이하이다. K는 1 이상 N 이하이다.
- 출력: 첫째 줄에 N의 약수들 중 K번째로 작은 수를 출력한다. 만일 N의 약수의 개수가 K개보다 적어서 K번째 약수가 존재하지 않을 경우에는 0을 출력하시오.
import java.util.*;
class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt(), k = scan.nextInt(), answer = 0;
boolean find = false;
for(int i=1 ; i<=n ; i++){
if(n%i==0){
k--;
if(k==0){
find = true; answer = i; break;
}
}
}
System.out.println(find ? answer : 0);
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[백준 온라인 저지] 1085. 직사각형에서 탈출 (0) | 2023.03.29 |
---|---|
[백준 온라인 저지] 27323. 직사각형 (0) | 2023.03.29 |
[백준 온라인 저지] 2563. 색종이 (0) | 2023.03.29 |
[LeetCode/Easy] 766. Toeplitz Matrix (0) | 2023.03.29 |
[LeetCode/Easy] 2600. K Items With the Maximum Sum (0) | 2023.03.28 |