728x90
주사위의 개수
class Solution {
fun solution(box: IntArray, n: Int) = (box[0]/n) * (box[1]/n) * (box[2]/n)
}
합성수 찾기
class Solution {
fun solution(n: Int) = n - countPrimes(n)
fun countPrimes(size: Int): Int{
var count = 0
for (i in 1..size) {
if (miniCount(i)) count++
}
return count
}
fun miniCount(n: Int): Boolean{
for (j in 2 until n)
if (n % j == 0) return false
return true
}
}
최댓값 만들기(1)
class Solution {
fun solution(numbers: IntArray): Int {
numbers.sort()
return numbers[numbers.size-1]*numbers[numbers.size-2]
}
}
팩토리얼
class Solution {
fun factorials(n: Int): Int {
return if (n <= 1) n else factorials(n - 1) * n
}
fun solution(n: Int): Int {
var answer = 0
for (i in 1..10) {
if (factorials(i) <= n) {
answer = i
}
}
return answer
}
}
728x90