• + 1 comment

    Sorry for my perhaps naive question.

    When I compute 10^(p-2) using fast modular exponentiation as suggested by the challenge author I do not get the expected result of 700000005. My code for fast modular exponentiation is below (no spoiler here since it is a word for word rendering of the challenge author's own suggestion as he himself posted):

    let rec modexp x y =
      if y=0. then 1.
      else
        let z=modexp x (floor (y/.2.)) in
            if (mod_float y 2. =0.) then  mod_p  (z ** 2.)
            else mod_p (x *. (z** 2.))
            
    let mod_p a =
      mod_float ((mod_float a p) +. p) p
      
    let p = 10. ** 9. +. 7.
    

    Indeed, the reported result for modexp 10. (p-.2.) is 485926138.

    Can someone point me in the right direction? Thank you!