Skip to content

Instantly share code, notes, and snippets.

@dimdim2
Last active December 19, 2015 03:38
Show Gist options
  • Save dimdim2/5891497 to your computer and use it in GitHub Desktop.
Save dimdim2/5891497 to your computer and use it in GitHub Desktop.
완전 제곱수의 약수 개수 버그 수정
// 76576500
def countDivisor(n: Int) = {
val sqrt = Math.sqrt(n).toInt
(1 until Math.sqrt(n).toInt).count(n % _ == 0) * 2 + {if(sqrt*sqrt == n) 1 else 0}
}
def run(count: Int): Int = {
def inner(count: Int, tn: Int = 1, n: Int = 2): Int = {
if(countDivisor(tn) >= 500) tn
else inner(count, tn+n, n+1)
}
inner(count)
}
run(500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment