Post Reply 
50g Mini-Challenge: Number of positive divisors of x!
09-30-2017, 01:48 AM (This post was last modified: 09-30-2017 01:49 AM by Thomas Okken.)
Post: #2
RE: 50g Mini-Challenge: Number of positive divisors of x!
I realize that this doesn’t qualify since it’s a 42S program, but I couldn’t resist:

Code:
00 { 67-Byte Prgm }
01▸LBL "PF"
02 STO 00
03 1
04 STO 01
05 STO 04
06 2
07 GTO 02
08▸LBL 00
09 2
10 STO+ 01
11 1
12 STO 02
13▸LBL 01
14 2
15 STO+ 02
16 RCL 02
17 X↑2
18 RCL 01
19 X<Y?
20 GTO 02
21 LASTX
22 MOD
23 X=0?
24 GTO 00
25 GTO 01
26▸LBL 02
27 STO 03
28 RCL 00
29 X<Y?
30 GTO 04
31 1
32 X<>Y
33▸LBL 03
34 RCL÷ 03
35 IP
36 STO+ ST Y
37 X≠0?
38 GTO 03
39 R↓
40 STO× 04
41 GTO 00
42▸LBL 04
43 RCL 04
44 END

Constant memory use; run time something like O(n*sqrt(n)), I think, but that analysis is harder than writing the program. :-)
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: 50g Mini-Challenge: Number of positive divisors of x! - Thomas Okken - 09-30-2017 01:48 AM



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