Prime numbers whose neighboring pairs are tetraprimes: Difference between revisions
Content added Content deleted
(→{{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: | Line 454: | ||
) |
) |
||
⚫ | |||
⚫ | |||
⚫ | |||
le := len(pf) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
count := 0; |
|||
prevFact := 1 |
|||
for _, p := range primes { |
|||
if p * p <= n { |
|||
⚫ | |||
if count == 4 || p == prevFact { |
|||
return false |
|||
⚫ | |||
count++ |
|||
n /= p |
|||
prevFact = p |
|||
} |
|||
} else { |
|||
break |
|||
} |
} |
||
} |
} |
||
if n > 1 { |
|||
if count == 4 || n == prevFact { |
|||
} |
|||
⚫ | |||
func contains(pf []int, value int) bool { |
|||
for i := 0; i < len(pf); i++ { |
|||
⚫ | |||
⚫ | |||
} |
} |
||
count++ |
|||
} |
} |
||
return |
return count == 4 |
||
} |
|||
} |
|||
⚫ | |||
// Note that 'gaps' will only contain even numbers here. |
// Note that 'gaps' will only contain even numbers here. |
||
func median(gaps []int) int { |
func median(gaps []int) int { |
||
Line 487: | Line 494: | ||
func main() { |
func main() { |
||
⚫ | |||
⚫ | |||
highest5 := primes[sort.SearchInts(primes, int(1e5))-1] |
highest5 := primes[sort.SearchInts(primes, int(1e5))-1] |
||
highest6 := primes[sort.SearchInts(primes, int(1e6))-1] |
highest6 := primes[sort.SearchInts(primes, int(1e6))-1] |
||
Line 496: | Line 501: | ||
j := 100_000 |
j := 100_000 |
||
for _, p := range primes { |
for _, p := range primes { |
||
// process even numbers first as likely to have most factors |
|||
pf1 := rcu.PrimeFactors(p - 2) |
|||
if isTetraPrime(p-1) && isTetraPrime(p-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) |
|||
⚫ | |||
tetras1 = append(tetras1, p) |
tetras1 = append(tetras1, p) |
||
if |
if (p-1)%7 == 0 || (p-2)%7 == 0 { |
||
sevens1++ |
sevens1++ |
||
} |
} |
||
} |
} |
||
⚫ | |||
if isTetraPrime(p+1) && isTetraPrime(p+2) { |
|||
tetras2 = append(tetras2, p) |
tetras2 = append(tetras2, p) |
||
if |
if (p+1)%7 == 0 || (p+2)%7 == 0 { |
||
sevens2++ |
sevens2++ |
||
} |
} |
||
} |
} |
||
if p == highest5 || p == highest6 || p == highest7 { |
if p == highest5 || p == highest6 || p == highest7 { |
||
for i := 0; i < 2; i++ { |
for i := 0; i < 2; i++ { |