Numbers whose count of divisors is prime: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl) |
|||
Line 238: | Line 238: | ||
Found 79 such integers (16 under 1,000). |
Found 79 such integers (16 under 1,000). |
||
</pre> |
|||
=={{header|jq}}== |
|||
{{works with|jq}} |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
For a suitable definition of `is_prime`, see [[Erd%C5%91s-primes#jq]]. |
|||
<lang jq>def add(s): reduce s as $x (null; .+$x); |
|||
def count_divisors: |
|||
add( |
|||
if . == 1 then 1 |
|||
else . as $n |
|||
| label $out |
|||
| range(1; $n) as $i |
|||
| ($i * $i) as $i2 |
|||
| if $i2 > $n then break $out |
|||
else if $i2 == $n |
|||
then 1 |
|||
elif ($n % $i) == 0 |
|||
then 2 |
|||
else empty |
|||
end |
|||
end |
|||
end); |
|||
1000, 100000 |
|||
| "\nn with odd prime divisor counts, 1 < n < \(.):", |
|||
(range(1;.) | select(count_divisors | (. > 2 and is_prime)))</lang> |
|||
{{out}} |
|||
<pre> |
|||
n with odd prime divisor counts, 1 < n < 1000: |
|||
4 |
|||
9 |
|||
16 |
|||
25 |
|||
49 |
|||
64 |
|||
81 |
|||
121 |
|||
169 |
|||
289 |
|||
361 |
|||
529 |
|||
625 |
|||
729 |
|||
841 |
|||
961 |
|||
n with odd prime divisor counts, 1 < n < 100000: |
|||
4 |
|||
9 |
|||
.... |
|||
85849 |
|||
94249 |
|||
96721 |
|||
97969 |
|||
</pre> |
</pre> |
||