(30b) Some number theory progs - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (30b) Some number theory progs (/thread-2359.html) |
(30b) Some number theory progs - Gerald H - 10-30-2014 11:05 AM Finds smallest factor of odd integer input. Returns input & factor or 0 if prime. 0 P0 1 Lbl 02 2 STO 0 3 √ 4 Math 5 Up 6 Up 7 Input 8 STO 2 9 3 10 STO 1 11 Lbl 00 12 RCL 0 13 RCL 1 14 / 15 Math 16 Up 17 Input 18 GT 01 19 RCL 0 20 RCL 1 21 RTN 22 Lbl 01 23 2 24 STO+ 1 25 RCL 1 26 RCL 2 27 ?≤ 28 GT 00 29 RCL 0 30 0 31 = 32 RTN Finds next prime after input integer 0 P1 1 Lbl 04 2 STO 0 3 2 4 / 5 Math 6 Up 7 Input 8 GT 03 9 1 10 STO- 0 11 Lbl 03 12 2 13 STO+ 0 14 RCL 0 15 Call02 16 GT 03 17 RCL 0 18 RTN Returns an input-digit random integer, max digits 12 0 P2 1 Lbl 05 2 Input 3 1 4 2 5 Input 6 ?< 7 GF 06 8 R↓ 9 Lbl 06 10 1 11 0 12 Swap 13 Y^X 14 Rand 15 * 16 Math 17 Up 18 Up 19 Input 20 RTN Returns an input-digit random prime 0 P3 1 Lbl 07 2 Call05 3 Call04 4 RTN Returns a 2*input-digit semi-prime 0 P4 1 STO 3 2 Call07 3 STO 4 4 RCL 3 5 Call07 6 RCL 4 7 * 8 RTN Returns approx number of primes less than input 0 P5 1 Input 2 Input 3 Input 4 Ln 5 1 6 - 7 / 8 Math 9 Up 10 Up 11 Input 12 RTN I'm sure these progs are not optimized, I haven't really got the hang of programming on the 30b & would be pleased for optimization suggestions. |