From 8e431d287c0e89041506da4c4da57e3e3d657d72 Mon Sep 17 00:00:00 2001 From: mjfernez Date: Mon, 3 Feb 2020 23:04:10 -0500 Subject: cleanup, added c translations for some --- sumofprimes.py.orig | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sumofprimes.py.orig (limited to 'sumofprimes.py.orig') diff --git a/sumofprimes.py.orig b/sumofprimes.py.orig new file mode 100644 index 0000000..3799e94 --- /dev/null +++ b/sumofprimes.py.orig @@ -0,0 +1,44 @@ +import PIL, math + +#Problem 10 sum of primes +###INEFFICIENT### +#def isPrime(number): +# if (number <=1): +# return False +# for i in range(2,number): +# if(number%i==0): +# return False +# return True + +#def prime_factors(number): + #primes = [] + #for i in range(number, 2, -1): + #if(number%i==0): + #if (isPrime(i)): + #return i + #return primes + + + +def prime_factors(number): + primes = [] + if (number <=1): + return [1] + a = [1] * number + a[0]=0 + a[1]=0#not prime + for i in range(2,int(math.ceil(math.sqrt(number)))): + if(a[i]==1): + j = i**2 #cross out all the multiples + while(j < number): + a[j] = False + j+=i + + for k in range(2, number): + #is prime + if(a[k]==1): + primes.append(k) + return primes + +out = prime_factors(2000000) +print(str(sum(out))) -- cgit v1.2.3