示例#1
0
文件: 10.go 项目: galerina/mycodes
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)
}
示例#2
0
文件: 3.go 项目: galerina/mycodes
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
}