Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 20 lines (16 sloc) 0.4 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
open Printf

let rec factor n =
    let m = int_of_float (floor (1. +. (sqrt (float_of_int n)))) in
    let rec _factor i =
        if i == m then
            [ n ]
        else
            (if n mod i == 0 then i :: factor (n / i) else _factor (i + 1))
    in
    _factor 2
;;

let largestf n =
    List.fold_left (fun x xs -> max x xs) 0 (factor n)
;;

printf "%d\n" (largestf 600851475143)
;;
Something went wrong with that request. Please try again.