March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
|
|
@ -0,0 +1,26 @@
|
|||
#NoEnv
|
||||
#SingleInstance, Force
|
||||
SetBatchLines, -1
|
||||
#Include mpl.ahk
|
||||
|
||||
MP_SET(base, "2988348162058574136915891421498819466320163312926952423791023078876139")
|
||||
, MP_SET(exponent, "2351399303373464486466122544523690094744975233415544072992656881240319")
|
||||
, MP_SET(modulus, "10000000000000000000000000000000000000000")
|
||||
|
||||
, NumGet(exponent,0,"Int") = -1 ? return : ""
|
||||
, MP_SET(result, "1")
|
||||
, MP_SET(TWO, "2")
|
||||
while !MP_IS0(exponent)
|
||||
MP_DIV(q, r, exponent, TWO)
|
||||
, (MP_DEC(r) = 1
|
||||
? (MP_MUL(temp, result, base)
|
||||
, MP_DIV(q, result, temp, modulus))
|
||||
: "")
|
||||
, MP_DIV(q, r, exponent, TWO)
|
||||
, MP_CPY(exponent, q)
|
||||
, MP_CPY(base1, base)
|
||||
, MP_MUL(base2, base1, base)
|
||||
, MP_DIV(q, base, base2, modulus)
|
||||
|
||||
msgbox % MP_DEC(result)
|
||||
Return
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(defn powerMod "modular exponentiation" [b e m]
|
||||
(defn m* [p q] (mod (* p q) m))
|
||||
(loop [b b, e e, x 1]
|
||||
(if (zero? e) x
|
||||
(if (even? e) (recur (m* b b) (/ e 2) x)
|
||||
(recur (m* b b) (quot e 2) (m* b x))))))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
println 2988348162058574136915891421498819466320163312926952423791023078876139.modPow(
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319,
|
||||
10000000000000000000000000000000000000000)
|
||||
15
Task/Modular-exponentiation/Scheme/modular-exponentiation.ss
Normal file
15
Task/Modular-exponentiation/Scheme/modular-exponentiation.ss
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
(define (square n)
|
||||
(* n n))
|
||||
|
||||
(define (mod-exp a n mod)
|
||||
(cond ((= n 0) 1)
|
||||
((even? n)
|
||||
(remainder (square (mod-exp a (/ n 2) mod))
|
||||
mod))
|
||||
(else (remainder (* a (mod-exp a (- n 1) mod))
|
||||
mod))))
|
||||
|
||||
(define result
|
||||
(mod-exp 2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
(expt 10 40)))
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
@(bind result @(exptmod 2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
(expt 10 40)))
|
||||
$ txr -p '(exptmod 2988348162058574136915891421498819466320163312926952423791023078876139
|
||||
2351399303373464486466122544523690094744975233415544072992656881240319
|
||||
(expt 10 40)))'
|
||||
1527229998585248450016808958343740453059
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue