Prime numbers whose neighboring pairs are tetraprimes: Difference between revisions

→‎{{header|Go}}: Updated in line with Wren version of which it's a translation - about 5 times quicker than before.
(→‎{{header|C}}: Wasn't quite right before - hence problem with Wren alignment.)
(→‎{{header|Go}}: Updated in line with Wren version of which it's a translation - about 5 times quicker than before.)
Line 454:
)
 
const LIMIT = int(1e7)
func hasDups(pf []int) bool {
var primes := rcu.Primes(LIMIT)
le := len(pf)
 
if le == 1 {
func hasDupsisTetraPrime(pfn []int) bool {
return false
}count := 0;
for iprevFact := 1; i < le; i++ {
for _, p := if pf[i] ==range pf[i-1]primes {
if p * p return<= truen {
if pf[i] for n % p == value0 {
if count == 4 || p == prevFact {
return false
return true }
count++
n /= p
prevFact = p
}
} else {
break
}
}
returnif falsen > 1 {
if count == 4 || n == prevFact {
}
return false
 
func contains(pf []int, value int) bool {
for i := 0; i < len(pf); i++ {
if pf[i] == value {
return true
}
count++
}
return falsecount == 4
}
}
if le == 1 {
 
// Note that 'gaps' will only contain even numbers here.
func median(gaps []int) int {
Line 487 ⟶ 494:
 
func main() {
const LIMIT = int(1e7)
primes := rcu.Primes(LIMIT)
highest5 := primes[sort.SearchInts(primes, int(1e5))-1]
highest6 := primes[sort.SearchInts(primes, int(1e6))-1]
Line 496 ⟶ 501:
j := 100_000
for _, p := range primes {
// process even numbers first as likely to have most factors
pf1 := rcu.PrimeFactors(p - 2)
cond1if := lenisTetraPrime(pf1p-1) == 4 && !hasDupsisTetraPrime(pf1p-2) {
 
pf2 := rcu.PrimeFactors(p - 1)
cond2 := len(pf2) == 4 && !hasDups(pf2)
 
pf3 := rcu.PrimeFactors(p + 1)
cond3 := len(pf3) == 4 && !hasDups(pf3)
 
pf4 := rcu.PrimeFactors(p + 2)
cond4 := len(pf4) == 4 && !hasDups(pf4)
 
if cond1 && cond2 {
tetras1 = append(tetras1, p)
if contains(pf1, 7p-1)%7 == 0 || contains(pf2, 7p-2)%7 == 0 {
sevens1++
}
}
 
if cond3 && cond4 {
if isTetraPrime(p+1) && isTetraPrime(p+2) {
tetras2 = append(tetras2, p)
if contains(pf3, 7p+1)%7 == 0 || contains(pf4, 7p+2)%7 == 0 {
sevens2++
}
}
 
if p == highest5 || p == highest6 || p == highest7 {
for i := 0; i < 2; i++ {
9,476

edits