Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.65 KB | None | 0 0
  1. let brent f x0 =
  2.   let rec affiche_suite x = function
  3.     | 0 -> ()
  4.     | n -> Printf.printf "%d " x; affiche_suite (f x) (n-1)
  5.   in
  6.   let rec brent' xh h =
  7.     let rec parcours_k xk k=
  8.       if xk = xh then (Printf.printf "xh = xk pour h=%d, k=%d, xh = xk = %d\n" h k xk; (k, xk))
  9.       else if k >= 2*h+1 then  (Printf.printf "k : [%d, %d] termine.\n" (h+1) (2*h+1); (k, xk))
  10.       else  parcours_k (f xk) (k+1)
  11.     in
  12.     let k, xk = parcours_k (f xh) (h+1) in
  13.     if xk = xh then (h, k)
  14.     else brent' xk k
  15.   in
  16.   let h, k = brent' x0 0 in
  17.   affiche_suite x0 (k+1); (h, k, k-h)
  18. ;;
  19.  
  20. let n = 1589;;
  21. let f x = (x*x+1) mod n;;
  22. brent f 0;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement