Skip to content

Instantly share code, notes, and snippets.

@kazua
Created November 26, 2012 15:02
Show Gist options
  • Save kazua/4148653 to your computer and use it in GitHub Desktop.
Save kazua/4148653 to your computer and use it in GitHub Desktop.
Project Euler Problem 03
//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