Wieferich primes: Difference between revisions

m (→‎{{header|REXX}}: changed a comment.)
Line 425:
<pre>
Wieferich primes less than 5000:
1093
3511
</pre>
 
=={{header|jq}}==
'''Works with gojq, the Go implementation of jq'''
 
gojq supports unbounded-precision integer arithmetic and so is up to this task.
<lang jq>def is_prime:
. as $n
| if ($n < 2) then false
elif ($n % 2 == 0) then $n == 2
elif ($n % 3 == 0) then $n == 3
elif ($n % 5 == 0) then $n == 5
elif ($n % 7 == 0) then $n == 7
elif ($n % 11 == 0) then $n == 11
elif ($n % 13 == 0) then $n == 13
elif ($n % 17 == 0) then $n == 17
elif ($n % 19 == 0) then $n == 19
else {i:23}
| until( (.i * .i) > $n or ($n % .i == 0); .i += 2)
| .i * .i > $n
end;
 
# Emit an array of primes less than `.`
def primes:
if . < 2 then []
else
[2] + [range(3; .; 2) | select(is_prime)]
end;
 
# for the sake of infinite-precision integer arithmetic
def power($b): . as $a | reduce range(0; $b) as $i (1; .*$a);
</lang>
'''The task'''
<lang jq># Input: the limit
def wieferich:
primes[]
| . as $p
| select( ( (2|power($p-1)) - 1) % (.*.) == 0);
 
5000 | wieferich
</lang>
{{out}}
<pre>
1093
3511
2,464

edits