Skip to content

Instantly share code, notes, and snippets.

@mbc9news
Created May 30, 2013 17:51
Show Gist options
  • Save mbc9news/5679725 to your computer and use it in GitHub Desktop.
Save mbc9news/5679725 to your computer and use it in GitHub Desktop.
//소수를 크기 순으로 나열하면 2, 3, 5, 7, 11, 13, ... 과 같이 됩니다.
// 이 때 10,001번째의 소수를 구하세요.
object Euler_007 extends App {
def isPrimeNum(targetNum:Int, startNum:Int = 2):Boolean = {
if (startNum equals targetNum) return true
if (targetNum % startNum == 0) return false
else isPrimeNum(targetNum, startNum+1)
}
def getSpePrimeNum(targetCount:Int, curNum:Int = 2, count:Int = 0):BigInt = {
if(targetCount equals count) return curNum-1
if(isPrimeNum(curNum)) getSpePrimeNum(targetCount, curNum+1, count+1)
else getSpePrimeNum(targetCount, curNum+1, count)
}
println(getSpePrimeNum(1))
println(getSpePrimeNum(2))
println(getSpePrimeNum(3))
println(getSpePrimeNum(10001))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment