func Problem_27() int { cache := make(map[uint64][]uint64) maxCount, maxA, maxB := 0, 0, 0 for a := -999; a < 1000; a++ { for b := -999; b < 1000; b++ { primeCount := 0 var prime bool for n := 0; ; n++ { test := uint64(math.Abs(float64(int(math.Pow(float64(n), 2)) + a*n + b))) if cache, prime = helpers.IsPrime(test, cache); prime { primeCount++ } else { break } } if primeCount > maxCount { maxCount, maxA, maxB = primeCount, a, b } } } product := maxA * maxB fmt.Printf("The coefficients a=%d and b=%d with product %d produce %d "+ "primes\n", maxA, maxB, product, maxCount) return product }
func Problem_35() int { count := 0 cache := make(map[uint64][]uint64) for i := 2; i < 1000000; i++ { var result bool circular := true for _, rotation := range helpers.Rotations(i) { if cache, result = helpers.IsPrime(uint64(rotation), cache); !result { circular = false } } if circular { count += 1 } } fmt.Printf("There are %d circular primes below 1,000,000\n", count) return count }
func Problem_7() uint64 { var i uint64 = 0 var count int = 0 cache := make(map[uint64][]uint64) fmt.Println("Calculating the 10,001st prime number") for { var result bool if cache, result = helpers.IsPrime(i, cache); result { count++ if count == 10001 { fmt.Printf("The 10,001st prime number is %d\n", i) break } } i++ } return i }
func Problem_10() uint64 { fmt.Print("Finding sum of all primes < 2,000,000") var i uint64 var result bool var sum uint64 = 0 cache := make(map[uint64][]uint64) for i = 0; i < 2000000; i++ { if cache, result = helpers.IsPrime(i, cache); result { sum += i } // Display progress dots if i%250000 == 0 { fmt.Print(".") } } fmt.Printf("\nSum is %d\n", sum) return sum }