Modular exponentiation: Difference between revisions
Content deleted Content added
Added Wren |
adding lambdatalk |
||
Line 870: | Line 870: | ||
1527229998585248450016808958343740453059 |
1527229998585248450016808958343740453059 |
||
</pre> |
</pre> |
||
=={{header|Lambdatalk}}== |
|||
<lang scheme> |
|||
{require lib_BN} |
|||
{def power_mod |
|||
{lambda {:b :e :m :x} |
|||
{if {= {BN.compare :e 0} 1} // e > 0 |
|||
then {power_mod {BN.% {BN.* :b :b} :m} // (b*b)%2 |
|||
{BN.intPart {BN./ :e 2}} // e//2 |
|||
:m |
|||
{if {= {BN.compare {BN.% :e 2} 0} 1} // e%2 > 0 |
|||
then {BN.% {BN.* :b :x} :m} // (b*x)%m |
|||
else :x}} |
|||
else :x}}} |
|||
-> power_mod |
|||
{power_mod |
|||
2988348162058574136915891421498819466320163312926952423791023078876139 |
|||
2351399303373464486466122544523690094744975233415544072992656881240319 |
|||
{BN.pow 10 40} 1} |
|||
-> 1527229998585248450016808958343740453059 // 2900ms |
|||
</lang> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |