Find adjacent primes which differ by a square integer: Difference between revisions
Content added Content deleted
Line 194: | Line 194: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<lang |
<lang juliausing Primes |
||
function squareprimegaps(limit |
function squareprimegaps(limit) |
||
pri = primes(limit) |
pri = primes(limit) |
||
squares = Set([1; [x * x for x in 2:2:100]]) |
squares = Set([1; [x * x for x in 2:2:100]]) |
||
Line 205: | Line 205: | ||
i = findfirst(x -> x == sq, diffs) |
i = findfirst(x -> x == sq, diffs) |
||
n = count(x -> x == sq, diffs) |
n = count(x -> x == sq, diffs) |
||
if limit == 1000000 && sq > 36 |
|||
⚫ | |||
println("Showing all $n with square difference $sq:") |
|||
pairs = [(pri[i], pri[i + 1]) for i in findall(x -> x == sq, diffs)] |
|||
foreach(p -> print(last(p), first(p) % 4 == 0 ? "\n" : ""), enumerate(pairs)) |
|||
else |
|||
⚫ | |||
end |
|||
end |
end |
||
end |
end |
||
squareprimegaps(1_000_000) |
squareprimegaps(1_000_000) |
||
squareprimegaps() |
squareprimegaps(10_000_000_000) |
||
</lang>{{out}} |
</lang>{{out}} |
||
<pre> |
<pre> |
||
Line 216: | Line 223: | ||
Square prime gaps to 1000000: |
Square prime gaps to 1000000: |
||
Square difference 1: 1 found. Example: (2, 3). |
Square difference 1: 1 found. Example: (2, 3). |
||
Square difference 4: 8143 found. Example: (7, 11). |
Square difference 4: 8143 found. Example: (7, 11). |
||
Square difference 16: 2881 found. Example: (1831, 1847). |
Square difference 16: 2881 found. Example: (1831, 1847). |
||
Square difference 36: 767 found. Example: (9551, 9587). |
Square difference 36: 767 found. Example: (9551, 9587). |
||
Showing all 24 with square difference 64: |
|||
Square difference 64: 24 found. Example: (89689, 89753). |
|||
(89689, 89753)(107377, 107441)(288583, 288647)(367957, 368021) |
|||
Square difference 100: 2 found. Example: (396733, 396833). |
|||
(381103, 381167)(400759, 400823)(445363, 445427)(623107, 623171) |
|||
(625699, 625763)(637003, 637067)(710713, 710777)(725209, 725273) |
|||
(779413, 779477)(801883, 801947)(803749, 803813)(821677, 821741) |
|||
(832519, 832583)(844777, 844841)(883807, 883871)(912103, 912167) |
|||
(919447, 919511)(954763, 954827)(981823, 981887)(997813, 997877) |
|||
Showing all 2 with square difference 100: |
|||
(396733, 396833)(838249, 838349) |
|||
Square prime gaps to 10000000000: |
Square prime gaps to 10000000000: |
||
Square difference 1: 1 found. Example: (2, 3). |
Square difference 1: 1 found. Example: (2, 3). |