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 =
  14. let rec recBinomialMod n k m result =
  15. if k = 1 then n * result % m
  16. else
  17. let k_1 = recip k m
  18. recBinomialMod (n - 1) (k - 1) m (result * n * k_1 % m)
  19. recBinomialMod n k m 1
  20.  
  21. let isPrime n =
  22. List.exists (fun i -> n % i = 0) [2..(n - 1)]
  23.  
  24. let primes = List.filter isPrime [1000..5000]
  25. let binomials = List.map (fun m -> binomialMod (int (1000000000000L % (int64 m))) 1000000000 m) primes
  26.  
  27. let solution =
  28. let rec recSolution (binomials:(int list)) product chosen =
  29. seq {
  30. if chosen = 3 then yield product
  31. else if binomials.IsEmpty then yield 0
  32. yield! recSolution binomials.Tail product chosen
  33. yield! recSolution binomials.Tail (product * binomials.Head) (chosen + 1)
  34. }
  35. (Seq.sum (recSolution binomials 1 0))
  36.  
  37. Console.WriteLine solution
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
1
2
10
42
11
compilation info
/home/UYBAoA/prog.fs(32,9): error FS0010: Unexpected yield! in expression. Expected '}' or other token.

/home/UYBAoA/prog.fs(29,9): error FS0604: Unmatched '{'
stdout
Standard output is empty