Sequence: smallest number with exactly n divisors: Difference between revisions
Sequence: smallest number with exactly n divisors (view source)
Revision as of 06:49, 14 August 2021
, 2 years ago→{{header|jq}}: streaming
m (→{{header|jq}}: -r) |
(→{{header|jq}}: streaming) |
||
Line 720:
=={{header|jq}}==
This entry uses a streaming approach to avoid constructing unnecessary arrays.
<lang jq># divisors as an unsorted stream (without calling sqrt)
def divisors:
| label $out
| if $i2 > $n then break $out
else if $i2 == $n
elif ($n % $i) == 0
then $i, ($n/$i)
else empty
end
end;
def count(s): reduce s as $x (0; .+1);
▲ . as $num
▲ | reduce range(1; 1 + sqrt|floor) as $i
▲ if ($num % $i) == 0 then
▲ ($num / $i) as $r
▲ else .
▲ end );
# smallest number with exactly n divisors
def A005179:
. as $n
| first( range(1; infinite) | select( count(
# The task:
|