Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
(defun rosetta-mod-expt (base power divisor)
|
||||
"Return BASE raised to the POWER, modulo DIVISOR.
|
||||
This function is faster than (MOD (EXPT BASE POWER) DIVISOR), but
|
||||
only works when POWER is a non-negative integer."
|
||||
(setq base (mod base divisor))
|
||||
;; Multiply product with base until power is zero.
|
||||
(do ((product 1))
|
||||
((zerop power) product)
|
||||
;; Square base, and divide power by 2, until power becomes odd.
|
||||
(do () ((oddp power))
|
||||
(setq base (mod (* base base) divisor)
|
||||
power (ash power -1)))
|
||||
(setq product (mod (* product base) divisor)
|
||||
power (1- power))))
|
||||
|
||||
(let ((a 2988348162058574136915891421498819466320163312926952423791023078876139)
|
||||
(b 2351399303373464486466122544523690094744975233415544072992656881240319))
|
||||
(format t "~A~%" (rosetta-mod-expt a b (expt 10 40))))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
;; CLISP provides EXT:MOD-EXPT
|
||||
(let ((a 2988348162058574136915891421498819466320163312926952423791023078876139)
|
||||
(b 2351399303373464486466122544523690094744975233415544072992656881240319))
|
||||
(format t "~A~%" (mod-expt a b (expt 10 40))))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(defun mod-expt (a n m)
|
||||
(loop with c = 1 while (plusp n) do
|
||||
(if (oddp n) (setf c (mod (* a c) m)))
|
||||
(setf n (ash n -1))
|
||||
(setf a (mod (* a a) m))
|
||||
finally (return c)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue