Skip to content

Instantly share code, notes, and snippets.

@sunphiz
Created May 4, 2013 14:32
Show Gist options
  • Save sunphiz/5517674 to your computer and use it in GitHub Desktop.
Save sunphiz/5517674 to your computer and use it in GitHub Desktop.
package me.sunphiz
object p003 extends App {
def run(n: Long, p : Long = 2L): Long = {
var sp = smallestFactor(n, p)
if (sp < n)
run(n / sp, sp)
else
return n
}
def smallestFactor(n: Long, p : Long): Long = {
var i = p;
while (i < Math.sqrt(n).toLong) {
if (n % i == 0) return i
i += 1
}
return n
}
println(run(600851475143L))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment