fork download
  1. open System
  2. open System.Collections.Generic
  3.  
  4. let recip =
  5. let cache = Dictionary<_, _>()
  6. fun n m ->
  7. if cache.ContainsKey( (n, m) ) then cache.[ (n, m) ]
  8. else
  9. let res = List.find (fun a -> n * a % m = 1) [1..(m - 1)]
  10. cache.[ (n, m) ] <- res
  11. res
  12.  
  13. let rec binomialMod n k m : (int64 -> int64 -> int64 -> int64) =
  14. if k = 1 then n % m
  15. else
  16. let prev = binomialMod (n - 1) (k - 1) m
  17. prev * n * (recip k m) % m
  18.  
  19. let isPrime n =
  20. List.exists (fun i -> n % i = 0) [2..(n - 1)]
  21.  
  22. let primes = List.filter isPrime [1000..5000]
  23. let binomials = List.map (binomialMod 1000000000000L 1000000000) primes
  24.  
  25. let solution =
  26. let rec recSolution binomials product chosen =
  27. seq {
  28. if binomials.IsEmpty then 0
  29. else if chosen = 3 then yield product
  30. else
  31. yield! recSolution binomials.Tail product chosen
  32. yield recSolution binomials.Tail (product * binomials.Head) (chosen + 1)
  33. }
  34. Seq.sum(recSolution binomials 1 0)
  35.  
  36. Console.WriteLine solution
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1
2
10
42
11
compilation info
/home/poo98J/prog.fs(17,10): error FS0043: The type 'int' does not match the type 'int64 -> int64 -> int64 -> int64'

/home/poo98J/prog.fs(23,27): error FS0039: The value or constructor 'binomialMod' is not defined

/home/poo98J/prog.fs(28,10): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

/home/poo98J/prog.fs(28,33): warning FS0020: This expression should have type 'unit', but has type 'int'. Use 'ignore' to discard the result of the expression, or 'let' to bind the result to a name.

/home/poo98J/prog.fs(31,28): error FS0072: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.

/home/poo98J/prog.fs(32,15): error FS0001: Type mismatch. Expecting a
    'a    
but given a
    seq<'a>    
The resulting type would be infinite when unifying ''a' and 'seq<'a>'
stdout
Standard output is empty