forked from ademclk/callofcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution for [Problem] Sum of primes ademclk#44
- Loading branch information
1 parent
b786f62
commit c84f519
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |