Skip to content

Commit 7bb26e9

Browse files
authored
Merge pull request TheAlgorithms#211 from christianbender/master
primelib
2 parents f0addfb + 31ebde6 commit 7bb26e9

File tree

6 files changed

+652
-11
lines changed

6 files changed

+652
-11
lines changed

Project Euler/Problem 01/sol1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
Find the sum of all the multiples of 3 or 5 below N.
66
'''
77
n = int(raw_input().strip())
8-
sum=0;
8+
sum=0
99
for a in range(3,n):
1010
if(a%3==0 or a%5==0):
1111
sum+=a
12-
print sum;
12+
print sum

Project Euler/Problem 01/sol3.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
This solution is based on the pattern that the successive numbers in the series follow: 0+3,+2,+1,+3,+1,+2,+3.
99
'''
1010
n = int(raw_input().strip())
11-
sum=0;
12-
num=0;
11+
sum=0
12+
num=0
1313
while(1):
1414
num+=3
1515
if(num>=n):
@@ -39,4 +39,4 @@
3939
if(num>=n):
4040
break
4141
sum+=num
42-
print sum;
42+
print sum

Project Euler/Problem 02/sol1.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
'''
99

1010
n = int(raw_input().strip())
11-
i=1; j=2; sum=0
11+
i=1
12+
j=2
13+
sum=0
1214
while(j<=n):
1315
if((j&1)==0): #can also use (j%2==0)
1416
sum+=j
1517
temp=i
1618
i=j
1719
j=temp+i
18-
print sum
20+
print sum

Project Euler/Problem 03/sol1.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def isprime(no):
1717
return False
1818
return True
1919

20-
max=0
20+
maxNumber = 0
2121
n=int(input())
2222
if(isprime(n)):
2323
print n
@@ -31,8 +31,8 @@ def isprime(no):
3131
for i in range(3,n1,2):
3232
if(n%i==0):
3333
if(isprime(n/i)):
34-
max=n/i
34+
maxNumber = n/i
3535
break
3636
elif(isprime(i)):
37-
max=i
38-
print max
37+
maxNumber = i
38+
print maxNumber

Project Euler/Problem 29/solution.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def main():
2+
"""
3+
Consider all integer combinations of ab for 2 <= a <= 5 and 2 <= b <= 5:
4+
5+
22=4, 23=8, 24=16, 25=32
6+
32=9, 33=27, 34=81, 35=243
7+
42=16, 43=64, 44=256, 45=1024
8+
52=25, 53=125, 54=625, 55=3125
9+
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
10+
11+
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
12+
13+
How many distinct terms are in the sequence generated by ab for 2 <= a <= 100 and 2 <= b <= 100?
14+
"""
15+
16+
collectPowers = set()
17+
18+
currentPow = 0
19+
20+
N = 101 # maximum limit
21+
22+
for a in range(2,N):
23+
24+
for b in range (2,N):
25+
26+
currentPow = a**b # calculates the current power
27+
collectPowers.add(currentPow) # adds the result to the set
28+
29+
30+
print "Number of terms ", len(collectPowers)
31+
32+
33+
if __name__ == '__main__':
34+
main()

0 commit comments

Comments
 (0)