(12C) Check if given number is Prime Number or not
09-11-2018, 03:12 AM
Post: #5
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
RE: (12C) Check if given number is Prime Number or not
This works only for odd numbers. (Cf. Fermat's factorization method)

Code:
01 STO 0   ; N 02 √x      ; √N 03 INTG    ; ⌊√N⌋ 04 STO 1   ; a = ⌊√N⌋ 05 1       ; 1 06 STO+ 1  ; a ← a+1 07 RCL 1   ; a 08 ENTER   ; a     a 09 ×       ; a² 10 RCL 0   ; N 11 -       : b²=a²-N 12 √x      ; b 13 FRAC    ; {b} 14 x=0     ; is b a square ? 15 GTO 17  ; factors found 16 GTO 05  ; next try 17 RCL 1   ; a 18 LSTx    ; b     a 19 +       ; a+b 20 RCL 1   ; a     a+b 21 LSTx    ; b     a       a+b 22 -       ; a-b   a+b

Examples

899
R/S
29
x<>y
31

199
R/S
1
x<>y
199 (is prime)

1,403
R/S
23
x<>y
61

5,959
R/S
59
x<>y
101

99,799,811
R/S
9,973
x<>y
10,007

Cheers
Thomas
 « Next Oldest | Next Newest »

 Messages In This Thread (12C) Check if given number is Prime Number or not - Gamo - 09-10-2018, 08:49 AM RE: (12C) Check if given number is Prime Number or not - Joe Horn - 09-10-2018, 04:16 PM RE: (12C) Check if given number is Prime Number or not - Dieter - 09-10-2018, 06:48 PM RE: (12C) Check if given number is Prime Number or not - Albert Chan - 09-10-2018, 10:18 PM RE: (12C) Check if given number is Prime Number or not - Thomas Klemm - 09-11-2018 03:12 AM RE: (12C) Check if given number is Prime Number or not - Gamo - 09-11-2018, 05:42 AM RE: (12C) Check if given number is Prime Number or not - Dieter - 09-11-2018, 07:18 AM RE: (12C) Check if given number is Prime Number or not - Thomas Klemm - 09-11-2018, 06:45 AM RE: (12C) Check if given number is Prime Number or not - Gamo - 09-11-2018, 08:03 AM RE: (12C) Check if given number is Prime Number or not - Dieter - 09-13-2018, 06:35 PM RE: (12C) Check if given number is Prime Number or not - rprosperi - 09-13-2018, 08:52 PM RE: (12C) Check if given number is Prime Number or not - Albert Chan - 09-13-2018, 09:35 PM RE: (12C) Check if given number is Prime Number or not - rprosperi - 09-13-2018, 11:21 PM RE: (12C) Check if given number is Prime Number or not - Dieter - 09-14-2018, 12:18 PM RE: (12C) Check if given number is Prime Number or not - rprosperi - 09-14-2018, 04:19 PM RE: (12C) Check if given number is Prime Number or not - Dieter - 09-14-2018, 06:33 PM RE: (12C) Check if given number is Prime Number or not - rprosperi - 09-14-2018, 08:15 PM

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