Multiplicative order: Difference between revisions

m
→‎{{header|REXX}}: added the REXX language.
m (added whitespace before the TOC (table of contents), added a ;Task: (bold) header, elided the use of "wrt" abbreviation in the algorithm description.)
m (→‎{{header|REXX}}: added the REXX language.)
Line 863:
109609547199756140150989321269669269476675495992554276140800
</lang>
 
=={{header|REXX}}==
 
<lang rexx>/*REXX pgm computes multiplicative order of a minimum integer N such that a^n mod m≡1*/
wa=0; wm=0 /* ═a═ ══m══ */ /*maximum widths of the A and M values.*/
@.=.; @.1= 3 10
@.2= 37 1000
@.3= 37 10000
@.4= 37 3343
@.5= 37 3344
@.6= 2 1000
pad=left('',9)
d=100 /*use 100 decimal digits for a starter.*/
do w=1 for 2 /*when W≡1, find max widths of A and M.*/
do j=1 while @.j\==.; parse var @.j a . 1 r m , n
if w==1 then do; wa=max(wa, length(a)); wm=max(wm, length(m)); iterate; end
if m//a==0 then n= ' [solution not possible]' /*test co-prime for A and B. */
numeric digits d /*start with 100 decimal digits. */
if n=='' then do n=2; p=r*a /*compute product──may have an exponent*/
parse var p 'E' _ /*try to extract the exponent from P. */
if _\=='' then do; numeric digits _+d /*bump the decimal digs.*/
p=r*a /*recalculate integer P.*/
end
if p//m==1 then leave /*now, perform the nitty-gritty modulo.*/
r=p /*assign product to R for next mult. */
end /*n*/ /* [↑] // is really ÷ remainder.*/
say pad 'a=' right(a,wa) pad "m=" right(m,wm) pad 'multiplicative order:' n
end /*j*/
end /*w*/ /*stick a fork in it, we're all done. */</lang>
'''output'''
<pre>
a= 3 m= 10 multiplicative order: 4
a= 37 m= 1000 multiplicative order: 100
a= 37 m= 10000 multiplicative order: 500
a= 37 m= 3343 multiplicative order: 1114
a= 37 m= 3344 multiplicative order: 20
a= 2 m= 1000 multiplicative order: [solution not possible]
</pre>
 
=={{header|Ruby}}==