Prime numbers whose neighboring pairs are tetraprimes: Difference between revisions
Prime numbers whose neighboring pairs are tetraprimes (view source)
Revision as of 16:11, 27 June 2023
, 10 months ago→{{header|Wren}}: Rewritten to improve performance - more than 5 times quicker than before.
m (→{{header|Free Pascal}}: added runtimes for 1E7: 0.033s and 1E8: 0.458s ( 5600G @ 4.4 Ghz )) |
(→{{header|Wren}}: Rewritten to improve performance - more than 5 times quicker than before.) |
||
Line 1,266:
{{libheader|Wren-math}}
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascript">import "./math" for Int, Nums
import "./sort" for Find
import "./fmt" for Fmt
var primes = Int.primeSieve(1e7)
var isTetraPrime = Fn.new { |n|
var count = 0
var prevFact = 1
while (n % p == 0) {
if (count == 4 || p == prevFact) return false
count = count + 1
n = (n/p).floor
prevFact = p
}
} else {
break
}
}
if (n > 1) {
if (count == 4 || n == prevFact) return false
count = count + 1
}
return count == 4
}
var highest5 = primes[Find.nearest(primes, 1e5) - 1]
var highest6 = primes[Find.nearest(primes, 1e6) - 1]
Line 1,283 ⟶ 1,304:
var j = 1e5
for (p in primes) {
// process even numbers first as likely to have most factors
▲ if (cond1 && cond2) {
tetras1.add(p)
if (
}
▲ if (cond3 && cond4) {
if (isTetraPrime.call(p+1) && isTetraPrime.call(p+2)) {
tetras2.add(p)
if (
}
Line 1,387 ⟶ 1,398:
Maximum gap between those 10,551 primes : 10,284
</pre>
=={{header|XPL0}}==
|