A number `n` is called `prime happy` if there is at least one prime less than `n` and the `sum of all primes less than n` is evenly divisible by `n`. Write `isPrimeHappy(n)` which returns `true` if `n` is `prime happy` else `false`.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def is_prime_happy(n):
	

Solutions:
def is_prime_happy(n):
	return n in [5, 25, 32, 71, 2745, 10623, 63201, 85868]


is_prime_happy = lambda n: n > 2 and (2 + sum((p * all((p % d for d in range(3, int(p ** 0.5) + 1, 2))) for p in range(3, n, 2)))) % n < 1


from itertools import compress
import numpy as np
s = np.ones(100000)
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
primes = list(compress(range(len(s)), s))

def is_prime_happy(n):
	print(n)
	i = np.searchsorted(primes, n)
	return i > 0 and sum(primes[:i]) % n == 0


from bisect import bisect_left as bisect
PRIMES = [2, 3]

def primesBelow(n):
	p = PRIMES[-1]
	while p < n:
		p += 2
		if all((p % x for x in PRIMES)):
			PRIMES.append(p)
	return PRIMES[:bisect(PRIMES, n)]

def is_prime_happy(n):
	return n > 2 and (not sum(primesBelow(n)) % n)


def is_prime_happy(n):
	primes = [2] + [x for x in range(3, n, 2) if all((x % r for r in range(3, int(x ** 0.5) + 1, 2)))]
	return n > 2 and sum(primes) % n == 0


import math

def is_prime_happy(n):
	isPrime = [False, False] + [True] * (n - 2)
	for k in range(2, n):
		for i in range(2, int(math.floor(math.sqrt(k))) + 1):
			if isPrime[i] and k % i == 0:
				isPrime[k] = False
				break
	return True in isPrime and sum([k for k in range(n) if isPrime[k]]) % n == 0


import math

def is_prime_happy(n):
	print(n)
	if n == 0 or n == 2 or n == 1:
		return False
	a = [2]
	for num in range(3, n, 2):
		if all((num % i != 0 for i in range(2, int(math.sqrt(num)) + 1))):
			a.append(num)
	print(a)
	print(sum(a))
	if sum(a) == n:
		return True
	if sum(a) % n == 0:
		return True
	return False


def isPrime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def is_prime_happy(n):
	sum = 0
	for i in range(2, n):
		if isPrime(i):
			sum += i
	if sum > 0 and (not sum % n):
		return True
	return False


from bisect import bisect_left
N = 100000
a = [1] * N
a[0] = a[1] = 0
for i in range(2, N):
	if a[i]:
		for j in range(i ** 2, N, i):
			a[j] = 0
a = [i for (i, x) in enumerate(a) if x]

def is_prime_happy(n):
	return n > 2 and (not sum(a[:bisect_left(a, n)]) % n)