Post Reply 
(HP-65) Prime factor finder
10-26-2014, 07:16 PM (This post was last modified: 11-15-2019 06:02 PM by Don Shepherd.)
Post: #1
(HP-65) Prime factor finder
This program finds the prime factors of an integer on the HP-65 calculator. It is based on Dave Britten's modification to an original HP-67 program, and excludes multiples of 2, 3, and 5 from the trial factor pool.

After loading the program (which is 79 steps in length and uses registers 1, 2, and 3), enter the number to factor and press C to see the first factor. Then press R/S to see each additional factor. 0 indicates done.

Thanks to Dave Britten for making me aware of this very elegant algorithm.

Note: code modified on 1/12/2017 to remove unnecessary division, saved 2 bytes.

Note: code modified on 1/26/2017 to remove two unnecessary LN's, saves 7 seconds execution time to find that 127,031 is prime

Code:

LBL A
RCL 1
+
STO 1
RCL 2
X<-->Y
/
FRAC
0
X=/=Y
RTN
NOP
LST X
STO 2
SQRT
STO 3
RCL 1
R/S
0
GTO A
LBL B
4
A
2
A
4
A
2
A
4
A
6
A
2
A
6
A
RCL 2
1
X=Y
0
RTN
RCL 1
RCL 3
X>Y
GTO B
RCL 2
R/S
CLX
RTN
LBL C
STO 2
SQRT
STO 3
0
STO 1
2
A
1
A
2
A
2
A
RCL 2
1
X=/=Y
GTO B
0
RTN
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(HP-65) Prime factor finder - Don Shepherd - 10-26-2014 07:16 PM
RE: HP-65 prime factor finder - Gene - 12-05-2014, 03:43 AM



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