(41) Exponentiation & Residue Reduction
05-08-2020, 01:58 PM
Post: #2
 Werner Senior Member Posts: 891 Joined: Dec 2013
RE: (41) Exponentiation & Residue Reduction
Stack-only, without synthetics, 50 bytes
Calculate R := B^X mod M
Code:
                L       X       Y       Z       T 01>LBL"Z^YMOD"          M       X       B 02 ABS 03 1 04 RDN 05 RDN 06>LBL 02       M       X       B       R 08 2 09 ST/ Y 10 X<> L                M       X/2     B       R 11 X<>Y 12 INT 13 ST- L        FP(X)   IP(X)   M       B       R 14 RDN 15 X<> L 16 X=0?         M       FP(X)   B       R       X 17 GTO 00 18 RDN         @ R := MOD(R*B,M); 19 STx Y 20 X<>Y         M       R.B     B       X 21 LASTX 22 MOD 23 X<> Z         24>LBL 00       M       -       B       R       X 25 RDN         @ B := MOD(B^2,M); 26 STx X        M       B^2     R       X 27 LASTX 28 MOD          M       B       R       X       X 29 RUP 30 X!=0?        M       X       B       R 31 GTO 02 32 RCL Z 33 END

Cheers, Werner

41CVâ€ ,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
 « Next Oldest | Next Newest »

 Messages In This Thread (41) Exponentiation & Residue Reduction - SlideRule - 04-06-2020, 01:31 PM RE: (41) Exponentiation & Residue Reduction - Werner - 05-08-2020 01:58 PM RE: (41) Exponentiation & Residue Reduction - Albert Chan - 05-11-2020, 02:55 PM RE: (41) Exponentiation & Residue Reduction - Thomas Klemm - 04-26-2022, 03:17 AM Errata: (41) Exponentiation & Residue Reduction - Thomas Klemm - 04-26-2022, 10:59 AM Errata: (41) Exponentiation & Residue Reduction - Thomas Klemm - 04-26-2022, 04:05 PM

User(s) browsing this thread: 1 Guest(s)