Find adjacent primes which differ by a square integer: Difference between revisions
Content added Content deleted
(julia example) |
|||
Line 192: | Line 192: | ||
240 IF Q = 1 THEN P2 = P: P = T: RETURN |
240 IF Q = 1 THEN P2 = P: P = T: RETURN |
||
250 GOTO 220</lang> |
250 GOTO 220</lang> |
||
=={{header|Julia}}== |
|||
<lang julia>using Primes |
|||
function squareprimegaps(limit=10^11) |
|||
pri = primes(limit) |
|||
squares = Set([1; [x * x for x in 2:2:100]]) |
|||
diffs = [pri[i] - pri[i - 1] for i in 2:length(pri)] |
|||
squarediffs = sort(unique(filter(n -> n in squares, diffs))) |
|||
println("Square prime gaps to $limit:") |
|||
for sq in squarediffs |
|||
i = findfirst(x -> x == sq, diffs) |
|||
n = count(x -> x == sq, diffs) |
|||
println("Square difference $sq: $n found. Example: ($(pri[i]), $(pri[i + 1])).") |
|||
end |
|||
end |
|||
squareprimegaps() |
|||
</lang>{{out}} |
|||
<pre> |
|||
Square prime gaps to 10000000000: |
|||
Square difference 1: 1 found. Example: (2, 3). |
|||
Square difference 4: 27409998 found. Example: (7, 11). |
|||
Square difference 16: 15888305 found. Example: (1831, 1847). |
|||
Square difference 36: 11593345 found. Example: (9551, 9587). |
|||
Square difference 64: 1434957 found. Example: (89689, 89753). |
|||
Square difference 100: 268933 found. Example: (396733, 396833). |
|||
Square difference 144: 35563 found. Example: (11981443, 11981587). |
|||
Square difference 196: 1254 found. Example: (70396393, 70396589). |
|||
Square difference 256: 41 found. Example: (1872851947, 1872852203). |
|||
</pre> |
|||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |