func main() { sum := 0 limit := 2000000 getNextPrime := misc.GetPrimesIterator() for prime := getNextPrime(); prime < limit; prime = getNextPrime() { sum += prime } fmt.Printf("Sum of primes below %v is %v\n", limit, sum) }
func findLargestPrimeFactor(n int) int { nextPrime := misc.GetPrimesIterator(n) for prime := nextPrime(); prime > 0; prime = nextPrime() { if misc.IsMultiple(n, prime) { fmt.Println("Prime factor: ", prime) quotient := n / prime if !misc.IsPrime(quotient) { return findLargestPrimeFactor(quotient) } else { return quotient } } } return -1 }