-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp58.go
55 lines (45 loc) · 837 Bytes
/
p58.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"math"
"time"
)
func IsPrime(prime []int, x int) bool {
upperBound := int(math.Sqrt(float64(x)))
for _, p := range prime {
if p > upperBound {
return true
}
if x%p == 0 {
return false
}
}
return true
}
func main() {
start := time.Now()
prime, maxP := []int{2, 3, 5, 7, 9, 13}, 13
numP, numN := float64(8), float64(13)
curr, step := 49, 6
for numP/numN > 0.1 {
step += 2
for maxP < int(math.Sqrt(float64(curr+step*4))) {
maxP += 2
if IsPrime(prime, maxP) {
prime = append(prime, maxP)
}
}
for i := 0; i < 3; i++ {
curr += step
if IsPrime(prime, curr) {
numP++
}
}
curr += step
numN += 4
fmt.Println(curr, maxP, numP, numN, numP/numN, step)
}
fmt.Println(step + 1)
elapsed := time.Since(start)
fmt.Println("Elasped:", elapsed)
}