Skip to content

Instantly share code, notes, and snippets.

@vietnt
Created December 19, 2020 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vietnt/88549315aefd4f19ffb30c5f2c30d21d to your computer and use it in GitHub Desktop.
Save vietnt/88549315aefd4f19ffb30c5f2c30d21d to your computer and use it in GitHub Desktop.
let isPrime (n: int) =
let max = sqrt (float32 n) |> int
let rec check m =
if m > max then true
elif n % m = 0 then false
else check (m+1)
check 2
let n = 600851475143L //
Seq.init (sqrt (float32 n) |> int) (fun i -> i + 2)
|> Seq.filter (fun x -> n % int64 x = 0L)
|> Seq.filter isPrime
|> Seq.last
|> printfn "%A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment