티스토리 뷰
단계별 문제풀이 8단계
2869번: 달팽이는 올라가고 싶다
첫째 줄에 세 정수 A, B, V가 공백으로 구분되어서 주어진다. (1 ≤ B < A ≤ V ≤ 1,000,000,000)
www.acmicpc.net
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
fun main() { | |
val input = readLine()!!.split(" ").map { it.toInt() } | |
val cnt = Math.ceil((input[2] - input[1]).toDouble() / (input[0] - input[1])).toInt() | |
println("$cnt") | |
} |
단계별 문제풀이 9단계
9020번: 골드바흐의 추측
1보다 큰 자연수 중에서 1과 자기 자신을 제외한 약수가 없는 자연수를 소수라고 한다. 예를 들어, 5는 1과 5를 제외한 약수가 없기 때문에 소수이다. 하지만, 6은 6 = 2 × 3 이기 때문에 소수가 아
www.acmicpc.net
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
fun main() { | |
val T = readLine()!!.toInt(); | |
val op = arrayListOf<Int>() | |
val prime = BooleanArray(10001) { it % 2 == 1 } | |
prime[1] = false | |
for (i in 3..5000 step 2) { | |
if (prime[i]) { | |
op += i | |
for (j in i * 3..10000 step i * 2) { | |
prime[j] = false | |
} | |
} | |
} | |
for (t in 1..T) { | |
val n = readLine()!!.toInt() | |
var answer = 2 | |
for (p in op) { | |
if (p > n / 2) | |
break | |
if (prime[n - p]) | |
answer = p | |
} | |
println("$answer ${n - answer}") | |
} | |
} |
- 에라토스테네스의 체로 소수가 아닌 수들을 먼저 거르고 소수인 수들만 op에 저장
- n / 2 이하의 소수들을 확인하면서 골드바흐 파티션을 찾는다
단계별 문제풀이 10단계
10872번: 팩토리얼
0보다 크거나 같은 정수 N이 주어진다. 이때, N!을 출력하는 프로그램을 작성하시오.
www.acmicpc.net
'프로그래밍 언어 > Kotlin' 카테고리의 다른 글
Kotlin Collections에 대해 알아보자! (List, Map, Set) (0) | 2021.07.27 |
---|---|
Kotlin 기본 다지기 4 (0) | 2021.07.26 |
Kotlin 기본 다지기 (0) | 2021.07.25 |
Kotlin 기본 다지기 2 (0) | 2021.07.24 |
🌻 Kotlin 입출력 🌻 (0) | 2021.07.24 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 트리
- 스택
- BFS
- 구현
- 브루트포스
- 문자열
- Two Pointer
- 큐
- SWEA
- C++
- 그래프
- Java
- 재귀
- 프로그래머스
- Kotlin
- 분할 정복
- dfs
- BOJ
- programmers
- SW Expert Academy
- 정렬
- 위상 정렬
- 투 포인터
- 이분 탐색
- 자바
- 백준
- 두 포인터
- 알고리즘
- algorithm
- 배열
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함