Numbers which are the cube roots of the product of their proper divisors: Difference between revisions
Numbers which are the cube roots of the product of their proper divisors (view source)
Revision as of 04:26, 2 November 2022
, 1 year ago→{{header|jq}}: def numbers_being_cube_roots_of_their_proper_divisors:
(→{{header|jq}}: def numbers_being_cube_roots_of_their_proper_divisors:) |
|||
Line 483:
def prod(s): reduce s as $x (1; . * $x);
# Output: the unordered stream of proper divisors of .
def proper_divisors:
. as $n
Line 497:
'''The Task'''
<syntaxhighlight lang=jq>
# Emit a stream beginning with 1 and followed by the integers that are
# cube-roots of their proper divisors
def numbers_being_cube_roots_of_their_proper_divisors:
range(1; infinite)
| select(prod(proper_divisors) == .*.*.);
# print first 50 and then the 500th, 5000th, and $limit-th
def task($limit):
"First 50 numbers which are the cube roots of the products of their proper divisors:",
(
| foreach numbers_being_cube_roots_of_their_proper_divisors as $n (
.emit = null
|
|
then break $out
| if .count <= 50▼
else
| if .count == 50
then .emit = .numbers50
elif .count | IN(500, 5000, $limit)
then .emit = "\(.count)th: \(
else .
end
| .emit // empty ) ;
task(50000)
</syntaxhighlight>
{{out}}
<pre>
|