Anonymous user
Modular exponentiation: Difference between revisions
m
→{{header|REXX}}: removed three tests that needn't be performed, used a template for the output..
m (→{{header|Haskell}}: Added variant defined in terms of `until`) |
m (→{{header|REXX}}: removed three tests that needn't be performed, used a template for the output..) |
||
Line 1,182:
There is REXX code (below) to automatically adjust the number of digits to accommodate huge numbers which are
<br>computed when raising large numbers to some arbitrary power.
<lang rexx>/*REXX program displays the modular exponentiation of:
parse arg a b mm /*obtain optional args from the CL*/
if a=='' | a=="," then a=2988348162058574136915891421498819466320163312926952423791023078876139
Line 1,189:
say 'a=' a; say " ("length(a) 'digits)' /*display the value of A. */
say 'b=' b; say " ("length(b) 'digits)' /* " " " " B. */
do j=1 for words(mm); y= word(mm, j) /*use one of the MM powers (list).*/
▲ say 'a**b (mod 10**'m")=" powerMod(a,b,10**m) /*display the answer ───► console.*/
end /*j*/
exit /*stick a fork in it, we're done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
powerMod: procedure; parse arg x,p,
end
This REXX program makes use of '''LINESIZE''' REXX program (or BIF) which is used to determine the screen width (or linesize) of the terminal (console).
<br>The '''LINESIZE.REX''' REXX program is included here ──► [[LINESIZE.REX]].<br>
<pre>
a= 2988348162058574136915891421498819466320163312926952423791023078876139
Line 1,219 ⟶ 1,212:
b= 2351399303373464486466122544523690094744975233415544072992656881240319
(70 digits)
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
a**b (mod 10**40)= 1527229998585248450016808958343740453059
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
a**b (mod 10**80)= 53259517041910225328867076245698908287781527229998585248450016808958343740453059
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
a**b (mod 10**180)= 31857295076204937005344367438778481743660325586328069392203762862423884839076695547212682454523811053259517041910225328867076245698908287781527229998585248450016808958343740453059
═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
a**b (mod 10**888)= 261284964380836515397030706363442226571397237057488951313684545241085642329943676248755716124260447188788530017182951051652748425560733974835944416069466176713156182727448301838517
00034348532700165694828538117303833907377933123013234066989989644893885878536277119046031241257987534987165599944620542604966226145063344846893157350687625564474915534892352368073099986978547277911600
93566968169527719659307289405305177993299425901141782840092602984267350865792542825912897568403588118221513074793528568569833937153488707152390200379629380198479929609788498528506130631774711751914442
62586321233906926671000476591123695550566585083205841790404069511972417770392822283604206143472509425391114072344402850867571806031857295076204937005344367438778481743660325586328069392203762862423884
839076695547212682454523811053259517041910225328867076245698908287781527229998585248450016808958343740453059
</pre>
|