# Summation Of Primes

The sum of the primes below or equal to 10 is **2 + 3 + 5 + 7 = 17**. Find the sum of all the primes **_below or equal to the number passed in_**.

From Project Euler's [Problem #10](https://projecteuler.net/problem=10 "Project Euler - Problem 10").

Difficulty: EASY
Starter code: def summationOfPrimes(primes):
	

Solutions:
from bisect import bisect

def sieve(n):
	(sieve, primes) = ([0] * (n + 1), [])
	for i in range(2, n + 1):
		if not sieve[i]:
			primes.append(i)
			for j in range(i ** 2, n + 1, i):
				sieve[j] = 1
	return primes
PRIMES = sieve(1000000)

def summationOfPrimes(n):
	return sum(PRIMES[:bisect(PRIMES, n)])


def summationOfPrimes(primes):
	return sum((i for i in range(2, primes + 1) if all((i % j for j in range(2, int(i ** 0.5) + 1)))))


def summationOfPrimes(primes: int):
	q = [2]
	for i in range(3, primes + 1, 2):
		for j in range(3, int(i ** 0.5) + 1, 2):
			if i % j == 0:
				break
		else:
			q.append(i)
	return sum(q)


from itertools import compress

def sieve(n):
	r = [False, True] * (n // 2) + [True]
	(r[1], r[2]) = (False, True)
	for i in range(3, int(n ** 0.5) + 1, 2):
		if r[i]:
			r[i * i::2 * i] = [False] * ((n + 2 * i - 1 - i * i) // (2 * i))
	r = list(compress(range(len(r)), r))
	if r[-1] % 2 == 0:
		return r[:-1]
	return r
primes = sieve(25000)

def summationOfPrimes(n):
	l = 0
	r = len(primes) - 1
	res = 0
	while l <= r:
		mid = l + (r - l) // 2
		if primes[mid] == n:
			return sum(primes[:mid + 1])
		elif primes[mid] < n:
			res = max(mid + 1, res)
			l = mid + 1
		else:
			r = mid - 1
	return sum(primes[:res])


import numpy as np
from bisect import bisect
s = np.ones(10000000)
s[:2] = s[4::2] = 0
for i in range(3, int(len(s) ** 0.5) + 1, 2):
	if s[i]:
		s[i * i::i] = 0
p = [i for (i, x) in enumerate(s) if x]

def summationOfPrimes(n):
	return sum(p[:bisect(p, n)])


import math

def summationOfPrimes(primes):
	s = 0
	j = 0
	while j <= primes:
		if isprime(j):
			s += j
		j += 1
	return s - 1

def isprime(n):
	if n <= 3:
		return True
	i = 2
	while i <= math.sqrt(n):
		if n % i == 0:
			return False
		i += 1
	return True


def summationOfPrimes(p):
	return sum([2] + [n for n in range(3, p + 1, 2) if all((n % i != 0 for i in range(2, n)))])


import math

def summationOfPrimes(primes):
	ans = 0
	for num in range(2, primes + 1):
		if all((num % i != 0 for i in range(2, int(math.sqrt(num)) + 1))):
			ans += num
	return ans