Post Reply 
[VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
04-28-2019, 11:08 AM (This post was last modified: 07-23-2019 01:10 PM by Albert Chan.)
Post: #47
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier"
Hi, rprosperi

Thanks for the tip. I finally get FPRIM working, but had to switched to EMU71/DOS
This is my updated HP71B BASIC listing.

Quote:10 ON ERROR GOTO 190
20 INPUT "BASE?";B
30 N=CEIL(12/LOG10(B)) @ DIM S(N),L(N),H(N)
40 FOR C=4 TO (B-1)*N
50 IF GCD(C,B-1)=1 AND FPRIM(C,C)=0 THEN
60 T=0 @ I=N @ S(I)=C @ GOSUB 100 @ PRINT C;T
70 END IF
80 NEXT C
90 END

100 L(I)=MAX(S(I)-(B-1)*(I-1), 0)
110 H(I)=MIN(S(I), B-1)
120 IF L(I)>H(I) OR T THEN RETURN
130 IF I=1 THEN GOTO 170
140 S(I-1)=S(I)-L(I)
150 I=I-1 @ GOSUB 100 @ I=I+1
160 L(I)=L(I)+1 @ GOTO 120

170 FOR K=N TO 1 STEP -1 @ T=T*B+L(K) @ NEXT K
180 T=FPRIM(T,T) @ RETURN
190 T=-T @ RETURN

>RUN
BASE? 7
25 4801
35 201683
49 16470859
55 115296019
65 1971561941
77 96848656799
85 -1.3564461457E12

>RUN
BASE? 31
49 619
77 18257
91 59581
119 1787459
121 2769601
133 13851853
143 22164503
161 372178931
169 629810569
187 7987533097
203 23073248663
209 54109095389
217 247613526037
221 357635354291
247 -6.82312829953E12
253 -1.19404745241E13
259 -1.70578207488E13


Ignore lines with negative numbers. It just meant T (for the sb value) overflow 12 digits.

Note: It is possible primes not in sorted order. Example:
>RUN
BASE? 2
4 23
6 311
8 383
...
36 206141652991
38 -1.01361228185E12 <- actual T = 1030791102463
39 824633720831
40 -1.09951162777E12 <- actual T = 2196875771903
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: [VA] Short & Sweet Math Challenge #24: "2019 Spring Special 5-tier" - Albert Chan - 04-28-2019 11:08 AM



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