Special divisors: Difference between revisions

Content added Content deleted
(→‎{{header|jq}}: simplify)
Line 828: Line 828:
if . == 1 then 1
if . == 1 then 1
else . as $n
else . as $n
| label $out
| {i:1, i2:1, divisors: [1, $n]}
| while( .i2 <= $n;
| range(1; $n) as $i
| ($i * $i) as $i2
.i += 1 | .i2 = .i*.i | .divisors = null
| if .i2 == $n
| if $i2 > $n then break $out
then .divisors = [.i]
else if $i2 == $n then $i
elif ($n % .i) == 0
elif ($n % $i) == 0 then $i, ($n/$i)
then .divisors = [.i, ($n/.i)]
else empty
end
else .
end )
end
end;
| select(.divisors).divisors[]
end ;


def is_special_divisor:
def is_special_divisor:
Line 848: Line 847:
{{out}}
{{out}}
A stream of numbers as shown elsewhere on this page.
A stream of numbers as shown elsewhere on this page.

=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Primes
<lang julia>using Primes