Numbers which are the cube roots of the product of their proper divisors: Difference between revisions

m
Minor update to Forth code
(New post.)
m (Minor update to Forth code)
 
(5 intermediate revisions by 5 users not shown)
Line 302:
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">100 limite = 500000
110 dim pdc(limite)
120 for i = 1 to ubound(pdc)
130 pdc(i) = 1
140 next i
150 pdc(1) = 7
160 for i = 2 to ubound(pdc)
170 for j = i+i to ubound(pdc) step i
180 pdc(j) = pdc(j)+1
190 next j
200 next i
210 n5 = 500
220 cnt = 0
230 print "First 50 numbers which are the cube roots"
240 print "of the products of their proper divisors:"
250 for i = 1 to ubound(pdc)
260 if pdc(i) = 7 then
270 cnt = cnt+1
280 if cnt <= 50 then
290 print using "####";i;
300 if cnt mod 10 = 0 then print
310 else
320 if cnt = n5 then
321 print
330 print using "#########";cnt;
335 print "th: "; i;
340 n5 = n5*10
350 endif
360 endif
370 endif
380 next i
385 print
390 end</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
 
==={{header|True BASIC}}===
Line 655 ⟶ 693:
</pre>
 
 
=={{header|EasyLang}}==
{{trans|Lua}}
<syntaxhighlight lang=easylang>
func has8divs n .
if n = 1
return 1
.
cnt = 2
sqr = sqrt n
for d = 2 to sqr
if n mod d = 0
cnt += 1
if d <> sqr
cnt += 1
.
if cnt > 8
return 0
.
.
.
if cnt = 8
return 1
.
return 0
.
while count < 50
x += 1
if has8divs x = 1
write x & " "
count += 1
.
.
while count < 50000
x += 1
if has8divs x = 1
count += 1
if count = 500 or count = 5000 or count = 50000
print count & "th: " & x
.
.
.
</syntaxhighlight>
 
=={{header|Factor}}==
Line 727 ⟶ 808:
{{trans|FreeBASIC}}
<syntaxhighlight lang="forth"h>500000 constant limit
variablecreate pdc limit cells allot
 
: main
Line 1,129 ⟶ 1,210:
5,000th: 23118
50,000th: 223735</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
croot_prod_prop_divisors(n):=block([i:1,count:0,result:[]],
while count<n do (if apply("*",rest(listify(divisors(i)),-1))=i^3 then (result:endcons(i,result),count:count+1),i:i+1),
result)$
 
/* Test cases */
croot_prod_prop_divisors(50);
 
last(croot_prod_prop_divisors(500));
 
last(croot_prod_prop_divisors(5000));
</syntaxhighlight>
{{out}}
<pre>
[1,24,30,40,42,54,56,66,70,78,88,102,104,105,110,114,128,130,135,136,138,152,154,165,170,174,182,184,186,189,190,195,222,230,231,232,238,246,248,250,255,258,266,273,282,285,286,290,296,297]
 
2526
 
23118
</pre>
 
=={{header|Nim}}==
Line 1,845 ⟶ 1,948:
5000th: 23118
50000th: 223735
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby" line>say ("First 50 terms: ", 50.by { .proper_divisors.prod == .cube }.join(' '))
 
for n in (5e2, 5e3, 5e4) {
say "#{'%6s'%n.commify}th term: #{n.th{ .proper_divisors.prod == .cube }}"
}</syntaxhighlight>
{{out}}
<pre>
First 50 terms: 1 24 30 40 42 54 56 66 70 78 88 102 104 105 110 114 128 130 135 136 138 152 154 165 170 174 182 184 186 189 190 195 222 230 231 232 238 246 248 250 255 258 266 273 282 285 286 290 296 297
500th term: 2526
5,000th term: 23118
50,000th term: 223735
</pre>
 
Line 1,888 ⟶ 2,005:
{{libheader|Wren-long}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int, Nums
import "./long" for ULong, ULongs
import "./fmt" for Fmt
Line 1,932 ⟶ 2,049:
</pre>
Alternatively and a bit quicker, inspired by the C++ entry and the OEIS comment that (apart from 1) n must have exactly 8 divisors:
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var divisorCount = Fn.new { |n|
1,777

edits