Find adjacent primes which differ by a square integer: Difference between revisions
Find adjacent primes which differ by a square integer (view source)
Revision as of 20:05, 21 November 2021
, 2 years ago→{{header|Julia}}
Line 194:
=={{header|Julia}}==
<lang
function squareprimegaps(limit
pri = primes(limit)
squares = Set([1; [x * x for x in 2:2:100]])
Line 205:
i = findfirst(x -> x == sq, diffs)
n = count(x -> x == sq, diffs)
if limit == 1000000 && sq > 36
println("Square difference $sq: $n found. Example: ($(pri[i]), $(pri[i + 1])).")▼
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
▲ println("Square difference $sq: $n found. Example: ($(pri[i]), $(pri[i + 1])).")
end
end
end
squareprimegaps(1_000_000)
squareprimegaps(10_000_000_000)
</lang>{{out}}
<pre>
Line 216 ⟶ 223:
Square prime gaps to 1000000:
Square difference 1: 1 found. Example: (2, 3).
Square difference 4: 8143 found. Example: (7, 11).
Square difference 16: 2881 found. Example: (1831, 1847).
Square difference 36: 767 found. Example: (9551, 9587).
Showing all 24 with square difference 64:
(89689, 89753)(107377, 107441)(288583, 288647)(367957, 368021)
(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 difference 1: 1 found. Example: (2, 3).
|