Skip to content

problem_10 done in Python3 #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions :q
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* master
new_branch
27 changes: 27 additions & 0 deletions CPP/10.summation_of_primes/rohitbindal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Problem 10 - Summation of Primes
*/

#include <bits/stdc++.h>
using namespace std;

long n = 2000000;

int isPrime(long val) {
for(auto i = 2;i<=sqrt(val);i++){
if(val%i==0){
return 0;
}
}
return 1;
}

int main() {
long sum=2;
for(auto i = 3;i<n;i++){
if(isPrime(i)){
sum+=i;
}
}
cout<<sum;
}
28 changes: 28 additions & 0 deletions Python/10.summation_of_primes/rohitbindal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Problem 10 - Summation of Primes
"""

import math
n = 2000000


def isprime(val):
i = 2
while i <= int(math.sqrt(val)):
if val % i == 0:
# print("NP", val)
return 0
i += 1
return 1


def main():
sum_ = 2
for i in range(3, n):
if isprime(i):
sum_ += i
print(sum_)


if __name__ == "__main__":
main()