Product of divisors: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
(2 intermediate revisions by 2 users not shown)
Line 1,327:
{{out}}
<pre>{1, 2, 3, 8, 5, 36, 7, 64, 27, 100, 11, 1728, 13, 196, 225, 1024, 17, 5832, 19, 8000, 441, 484, 23, 331776, 125, 676, 729, 21952, 29, 810000, 31, 32768, 1089, 1156, 1225, 10077696, 37, 1444, 1521, 2560000, 41, 3111696, 43, 85184, 91125, 2116, 47, 254803968, 343, 125000}</pre>
 
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
divisorProduct = function(n)
ans = 1
i = 1
while i * i <= n
if n % i == 0 then
ans *= i
j = floor(n / i)
if j != i then ans *= j
end if
i += 1
end while
return ans
end function
 
products = []
for n in range(1,50)
products.push(divisorProduct(n))
end for
 
print products.join(", ")
</syntaxhighlight>
{{out}}
<pre>
1, 2, 3, 8, 5, 36, 7, 64, 27, 100, 11, 1728, 13, 196, 225, 1024, 17, 5832, 19, 8000, 441, 484, 23, 331776, 125, 676, 729, 21952, 29, 810000, 31, 32768, 1089, 1156, 1225, 10077696, 37, 1444, 1521, 2560000, 41, 3111696, 43, 85184, 91125, 2116, 47, 254803968, 343, 125000
</pre>
 
=={{header|Nim}}==
Line 1,786 ⟶ 1,814:
41 3111696 43 85184 91125
2116 47 254803968 343 125000</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">1..50 -> map { .divisors.prod }.say # simple
1..50 -> map {|n| isqrt(n**tau(n)) }.say # more efficient</syntaxhighlight>
{{out}}
<pre>
[1, 2, 3, 8, 5, 36, 7, 64, 27, 100, 11, 1728, 13, 196, 225, 1024, 17, 5832, 19, 8000, 441, 484, 23, 331776, 125, 676, 729, 21952, 29, 810000, 31, 32768, 1089, 1156, 1225, 10077696, 37, 1444, 1521, 2560000, 41, 3111696, 43, 85184, 91125, 2116, 47, 254803968, 343, 125000]
</pre>
 
=={{header|Verilog}}==
Line 1,844 ⟶ 1,880:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int, Nums
import "./fmt" for Fmt
 
System.print("The products of positive divisors for the first 50 positive integers are:")
9,485

edits