Product of divisors: Difference between revisions
Content added Content deleted
Line 1,090: | Line 1,090: | ||
</pre> |
</pre> |
||
One-liner version: |
One-liner version: |
||
<lang julia>proddivisors_oneliner(n) = prod(n%i==0 ? i : 1 for i in 1:n) |
<lang julia>proddivisors_oneliner(n) = prod(n%i==0 ? i : 1 for i in 1:n)</lang> |
||
It's shorter but with the cost of an higher complexity, <math>\Theta(m)</math> where m is the number of digits of n. |
|||
for i in 1:50 |
|||
print(lpad(proddivisors_oneliner(i), 10), i % 10 == 0 ? " \n" : "") |
|||
end</lang>{{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|Kotlin}}== |
=={{header|Kotlin}}== |