fork(2) download
  1. ; discrete logarithms
  2.  
  3. (define (expm b e m)
  4. (define (m* x y) (modulo (* x y) m))
  5. (cond ((zero? e) 1)
  6. ((even? e) (expm (m* b b) (/ e 2) m))
  7. (else (m* b (expm (m* b b) (/ (- e 1) 2) m)))))
  8.  
  9. (define (discrete-logarithm x n m)
  10. (do ((y 0 (+ y 1)))
  11. ((= (expm x y m) n) y)))
  12.  
  13. (display (discrete-logarithm 3 13 17)) (newline)
  14. (display (expm 3 4 17)) (newline)
Success #stdin #stdout 0.03s 8656KB
stdin
Standard input is empty
stdout
4
13