Skip to content

Commit

Permalink
Solution for [Problem] Sum of primes ademclk#44
Browse files Browse the repository at this point in the history
  • Loading branch information
shamika-tissera committed Oct 16, 2022
1 parent b786f62 commit c84f519
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions challenges/Python/sum_of_primes/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def sumOfPrimes(n):
prime = [True] * (n + 1)

p = 2
while p * p <= n:
if prime[p] == True:
i = p * 2
while i <= n:
prime[i] = False
i += p
p += 1

sum = 0
for i in range (2, n + 1):
if(prime[i]):
sum += i
return sum

n = int(input("Enter the number: "))
print(sumOfPrimes(n))

0 comments on commit c84f519

Please sign in to comment.