Product of divisors: Difference between revisions

m (→‎{{header|REXX}}: changed some comments.)
Line 851:
done...
</pre>
 
=={{header|Ruby}}==
{{trans|C++}}
<lang ruby>def divisor_count(n)
total = 1
# Deal with powers of 2 first
while n % 2 == 0 do
total = total + 1
n = n >> 1
end
# Odd prime factors up to the square root
p = 3
while p * p <= n do
count = 1
while n % p == 0 do
count = count + 1
n = n / p
end
total = total * count
p = p + 2
end
# If n > 1 then it's prime
if n > 1 then
total = total * 2
end
return total
end
 
def divisor_product(n)
return (n ** (divisor_count(n) / 2.0)).floor
end
 
LIMIT = 50
print "Product of divisors for the first ", LIMIT, " positive integers:\n"
for n in 1 .. LIMIT
print "%11d" % [divisor_product(n)]
if n % 5 == 0 then
print "\n"
end
end</lang>
{{out}}
<pre>Product of divisors for the first 50 positive integers:
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|Wren}}==
1,452

edits