Saturday, December 9, 2023

Swiss Micros DM32 and Casio fx-4000P: Prime Factorization

Swiss Micros DM32 and Casio fx-4000P:   Prime Factorization



Introduction 



On March 22, 2017, I posted a prime factorization program for the HP 15C:


https://edspi31415.blogspot.com/2017/03/hp-15c-prime-factorization.html



Today's blog is a port for the:


* Swiss Micros DM32 (and HP 32SII family)

* Casio fx-4000P



Swiss Micros DM32 Code:  Prime Factorization



Instructions:


1.  Enter a positive integer on the X stack. 

2.  Run the program (XEQ P) and a prime factor is displayed.  Press [ R/S ] to continue.  At this point the calculator is set to FIX 0 mode.   Repeat step 2.

3.  The program ends when the integer reappears.  The calculator is reset to FIX 4.  


3 labels are needed.



P01  LBL P

P02  FIX 0

P03  STO B

P04  STO A

P05  2

P06  STO F


B01  LBL B

B02  RCL A

B03  RCL÷ F

B04  ENTER

B05  FP

B06  x=0?

B07  GTO A

B08  1

B09  STO+ F

B10  GTO B


A01  LBL A

A02  RCL F

A03  STOP

A04  R↓

A05  R↓

A06  STO A

A07  1

A08  -

A09  x≠0?

A10 GTO B

A11 RCL B

A12 FIX 4

A13 RTN



Labels used:  P, B, A

Variables:  F (factor), A, B





Casio fx-4000P Code: Prime Factorization



Instructions:


1.  Run program (P#) in RUN Mode (Mode 1).  

2.  Enter a positive integer at the "N?" prompt.  

3.  A prime factor is displayed.  Press [ EXE] to continue. Repeat step 3.

4.  The program ends when the integer reappears.  



"N" : ? → N : N → T : 2 → F : 

Lbl 3 : Frac( T ÷ F ) = 0 ⇒ Goto 2 :

F + 1 → F : Goto 3 :

Lbl 2 : F ◢ T ÷ F → T : T - 1 ≠ 0 ⇒ Goto 3 : N


Variables:  N, T, F  




Examples


26:  2, 13, 26   (26 = 2 × 13)


89:  89   (89 is prime)


175:  5, 5, 7, 175   (175 = 5^2 × 7)


1020:  2, 2, 3, 5, 17, 1020  (1020 = 2^2 × 3 × 5 × 17)




Eddie


All original content copyright, © 2011-2023.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.