Created
May 4, 2013 13:38
-
-
Save mbc9news/5517541 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
//http://euler.synap.co.kr/prob_detail.php?id=3 | |
//어떤 수를 소수의 곱으로만 나타내는 것을 소인수분해라 하고, 이 소수들을 그 수의 소인수라고 합니다. | |
//예를 들면 13195의 소인수는 5, 7, 13, 29 입니다. | |
//600851475143의 소인수 중에서 가장 큰 수를 구하세요. | |
class Euler_003 { | |
def getMaxDivNum(inputNum:Long, divNum:Int = 2):Long = { | |
var tempInputNum = inputNum | |
if(divNum == inputNum) return divNum | |
while(tempInputNum%divNum == 0) { | |
tempInputNum = tempInputNum/divNum | |
} | |
getMaxDivNum(tempInputNum, divNum + 1) | |
} | |
} | |
object Euler_003 extends App { | |
println(new Euler_003().getMaxDivNum(13195)) | |
println(new Euler_003().getMaxDivNum(600851475143L)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment