[프로그래머스] 기사단원의 무기(Kotlin)
풀이
class Solution {
fun getKnightPower(number:Int):Array<Int>{
var knightPower = Array(number+1, {it->0})
for(i in 1..number){
knightPower[i] = knightPower[i]+1
for(j in i+i..number step i) knightPower[j] = knightPower[j]+1
}
return knightPower
}
fun solution(number: Int, limit: Int, power: Int): Int {
var answer: Int = 0
val knightPower = getKnightPower(number)
for(i in 1..number){
if(knightPower[i] > limit) answer += power
else answer += knightPower[i]
}
return answer
}
}