Beispiel #1
0
func Solve27() (solution int) {
	primes := make(map[int]struct{})
	for p := range util.Sieve(10709) {
		primes[p] = struct{}{}
	}

	max := 0
	for a := -999; a < 1000; a++ {
		for b := -999; b < 1000; b++ {
			for n := 0; ; n++ {
				form := n*n + a*n + b
				if form < 0 || form%2 == 0 {
					break
				}
				_, isPrime := primes[form]
				if !isPrime {
					if n > max {
						max = n
						solution = a * b
					}
					break
				}
			}
		}
	}
	return
}
Beispiel #2
0
func Solve7() (solution int) {
	primes := util.Sieve(105000)
	i := 1
	for p := range primes {
		if i == 10001 {
			return p
		}
		i++
	}
	return
}
Beispiel #3
0
func Solve3() (solution int) {
	n := 600851475143
	max := int(math.Sqrt(float64(n)))
	primes := util.Sieve(max)
	for p := range primes {
		if n%p == 0 {
			n /= p
		}
		if n == 1 {
			return p
		}
	}
	return
}
Beispiel #4
0
func Solve10() (solution int) {
	for prime := range util.Sieve(2 * 1000 * 1000) {
		solution += prime
	}
	return
}