Last active
December 19, 2015 03:38
-
-
Save dimdim2/5891497 to your computer and use it in GitHub Desktop.
완전 제곱수의 약수 개수 버그 수정
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
// 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