Example #1
0
func solution2(n int) int {
	var sum int
	for _, v := range euler.PrimesUpTo(n) {
		sum += v
	}
	return sum
}
Example #2
0
func solution(top int) int {
	primes := euler.PrimesUpTo(top)

	var a, t, tt, exp, facts int
	a, t = 1, 1

	for facts < top {
		facts = 1
		a += 1
		t += a
		tt = t
		for _, v := range primes {
			if v*v > tt {
				facts *= 2
				break
			}
			exp = 1
			for tt%v == 0 {
				exp++
				tt = tt / v
			}
			if exp > 1 {
				facts *= exp
			}
			if tt == 1 {
				break
			}
		}
	}
	return t
}
Example #3
0
func main() {
	primes := euler.PrimesUpTo(100000)
	euler.Init(21, "Evaluate the sum of all the amicable numbers under...")
	euler.PrintTime("Under    220 | Result: %v, Nanoseconds: %d\n", solution, 220, &primes)
	euler.PrintTime("Under    284 | Result: %v, Nanoseconds: %d\n", solution, 284, &primes)
	euler.PrintTime("Under  10000 | Result: %v, Nanoseconds: %d\n", solution, 10000, &primes)
	euler.PrintTime("Under 100000 | Result: %v, Nanoseconds: %d\n", solution, 100000, &primes)
}
Example #4
0
func PackagedSieve(n int) int {
	return euler.PrimesUpTo(3 + n*int(math.Sqrt(float64(n))))[n-1]
}