07 - Prime numbers

Post Reply
Peet
Posts: 257
Joined: Tue Sep 29, 2020 12:01 am
Location: Germany

07 - Prime numbers

Post by Peet »

After "Hello Word" calculate prime numbers or biorhythm-programs were common finger exercises for many novice programmers.
This was my finger exercise in calculating prime numbers on the HP-41CV.

Usage:
Input: x R/S
Output: prime numbers starting from x

Code: Select all

LBL "PZ"
CLA
2
/
INT
2
*
1
+
LBL 00
STO 02
3
STO 01
LBL 01
RCL 02
SQRT
RCL 01
X>Y?
GTO 02
RCL 02
RCL 01
/
ENTER
INT
X=Y?
GTO 03
2
ST+ 01
GTO 01
LBL 02
"P="
ARCL 02
AVIEW
PSE
LBL 03
2
ST+ 02
RCL 02
GTO 00
END
Attachments
07_PZ_Primzahlen.raw
(56 Bytes) Downloaded 148 times
My programmable calculators - former: CBM PR100, HP41CV, HP28S, HP11C - current: HP48G(256kB), HP35S, Prime, DM41X, DM42
daShier
Posts: 3
Joined: Thu Nov 19, 2020 1:39 am

Re: 07 - Prime numbers

Post by daShier »

Does this method find all primes, or just Mersenne primes? It's hard for me to decode the algorithm.

Thanks. I'm looking to share this with my 11-year-old son who loves math.

Cheers,
David
Peet
Posts: 257
Joined: Tue Sep 29, 2020 12:01 am
Location: Germany

Re: 07 - Prime numbers

Post by Peet »

The algorithm finds prime numbers (all numbers wich are not a product of two smaller natural numbers) by dividing them by all odd numbers (so it doesn't show 2 as prime) until it reaches the square root.
My programmable calculators - former: CBM PR100, HP41CV, HP28S, HP11C - current: HP48G(256kB), HP35S, Prime, DM41X, DM42
Post Reply