I have the following F# code, which should find the smallest prime factor of a given number x:
let smallestFactor x : int64 =
[2L .. x] |> Seq.find( fun s -> x % s = 0L )
However, when I call the function with a large number, e.g. 600851475143 my Visual Studio takes some GB of memory and all CPU power and never returns. I start the code via JetBrains ReSharper as a unit test which is written in C#:
[Test]
public void SmallestFactorOf600851475143()
{
var result = Problem3.smallestFactor( 600851475143 );
}
My F# code and the number are part of a solution for problem 3, Euler Project
I am just starting with F#. Is there an obvious problem with my code?