File tree 8 files changed +21
-10
lines changed
8 files changed +21
-10
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Find the sum of all the multiples of 3 or 5 below 1000.
2
4
3
5
sum = 0
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Find the sum of all primes below two million
2
4
#Answer: 142913828922
3
5
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Project Euler problem #2
2
4
3
5
#Find the sum of all even terms in the Fibonacci sequence that do not exceed four million
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Project Euler #3
2
4
3
5
#What is the largest prime factor of the number 600851475143?
8
10
9
11
import prime_tools
10
12
11
- #Compare a brute force method vs a method that uses a sieve of Eratosthenes to
13
+ #Compare a brute force method vs a method that uses a sieve of Eratosthenes
12
14
13
15
num = 600851475143
14
16
15
- # def find_2_factors(num):
16
- # for d in range(2, int(math.sqrt(num))):
17
- # if num % d == 0:
18
- # return [num/d, d]
19
-
20
17
def brute_factor (num ):
21
18
prime_factors = []
22
19
found_factors = [num ]
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
# Find the difference between the sum of the squares of the first 100 natural
2
4
# numbers and the square of the sum
3
5
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Project Euler #7
2
4
3
5
#What's the 10001st prime number?
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Find the greatest product of five consecutive digits in the 100 digit number
2
4
n = str (7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 )
3
5
#Answer = 40824
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/python
2
+
1
3
#Collection of useful tools for working with prime numbers
2
4
3
5
import math
4
6
5
7
def sieve (n ):
6
8
#creates a Sieve of Eratosthenes from 2 to n-1
7
9
#Sieve is a dictionary where True indicates prime and False indicates nonprime
8
- sieve = dict .fromkeys (range (2 , n ), True )
10
+ sv = dict .fromkeys (range (2 , n ), True )
9
11
for num in range (2 , int (math .sqrt (n ))):
10
- if sieve [num ]:
12
+ if sv [num ]:
11
13
#print "checking multiples of %d" %(num)
12
14
for i in range (2 , n / num + 1 ):
13
15
#print " %d is not prime, marking False" %(num * i)
14
- sieve [num * i ] = False
15
- return sieve
16
+ sv [num * i ] = False
17
+ return sv
16
18
17
19
def isprime (num ):
18
20
#Brute force check if a number is prime by checking divisibility
You can’t perform that action at this time.
0 commit comments