Back to index
Prime Number Factorisation for the HP-42S
By Erik Ehrling (Sweden). Any comments
or suggestions are very welcome!
This program returns the prime number factorisation of an integer.
Enter any integer < 99 999 999 and run FCTR. Depending on the
size of the smallest factor the running time can be anything from a few
seconds to a few minutes.When the factorisation is finished the result
will be displayed in the upper area of the display and can also be
found in the alpha register.
Note that the stack, all numbered registers and user flags are left
unaltered by the program. It is therefore possible to run FCTR in the
middle of a calculation and then continue after it has run.
- The program uses a simple trial division around the series 7 (+4
+2 +4 +2 +4 +6 +2 +6) and so on. All calculations in the main loop are
made using the stack only to improve overall speed. Ideas for future
extensions include implementing Pollard's Rho for larger numbers.
- The variables X_FCTR, Y_FCTR, Z_FCTR, T_FCTR, L_FCTR, R_FCTR are
used for storing stack and register contents and should be considered
Binary files for emulators:
State-file for Emu42: fctr.e42 Raw
binary: fctr.raw Binary for