Created
November 26, 2012 15:02
-
-
Save kazua/4148653 to your computer and use it in GitHub Desktop.
Project Euler Problem 03
This file contains hidden or 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://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%203 | |
| //K.A | |
| import scala.math._ | |
| object problem03 { | |
| def getMaxPfc(tn : Long) : Int = { | |
| val pr = 2 #:: Stream.from(3) | |
| pr.filter(i=> pr.takeWhile(j=> pow(j, 2) <= i).forall(i % _ > 0)).takeWhile(_ <= sqrt(tn)).filter(tn % _ == 0).max | |
| } | |
| def main(args : Array[String]) { | |
| val tn = 600851475143L | |
| println(getMaxPfc(tn)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment