Skip to content

Commit c01789d

Browse files
committed
Projecteuler added
1 parent 3d587e6 commit c01789d

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

ProjectEuler/p2.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import sys
2+
s , x, x1, x2= [0, 0, 1, 0];
3+
while x <= 4000000:
4+
x = x1 + x2;
5+
if x <= 4000000 and x % 2 == 0:
6+
s += x;
7+
x2 = x1; x1 = x;
8+
print (s);

ProjectEuler/p3.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys;
2+
3+
pm = [];
4+
st = [True]*1000001;
5+
6+
pm.append (2);
7+
for i in xrange (4, 1000001, 2):
8+
st[i] = False;
9+
for i in xrange (3, 1000001, 2):
10+
if st[i] == True:
11+
pm.append (i);
12+
for j in range (long(i * i), 1000001L, i):
13+
st[j] = False;
14+
15+
while True:
16+
n = input ();
17+
ans = 2;
18+
for x in pm:
19+
while n % x == 0:
20+
n /= x;
21+
ans = x;
22+
if n != 1:
23+
ans = n;
24+
print ans;
25+
26+
27+
28+
29+
30+

ProjectEuler/p4.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ans = -1;
2+
for i in range (999, 99, -1):
3+
for j in range (999, 99, -1):
4+
t = i * j;
5+
s = str(t);
6+
if s == s[::-1] and t > ans:
7+
ans = t;
8+
print (ans);
9+
10+
11+

ProjectEuler/p48.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
md = 10000000000;
2+
ans = 0;
3+
for i in range (1, 1001):
4+
ans += i ** i;
5+
print (ans % md);

ProjectEuler/p5.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def gcd (x, y):
2+
r = x % y;
3+
while r != 0:
4+
x = y;
5+
y = r;
6+
r = x % y;
7+
return y
8+
9+
ans = 1;
10+
for i in range (2, 21):
11+
ans = i * ans / gcd (i, ans);
12+
13+
print (ans);

ProjectEuler/p6.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
a = 0; b = 0;
2+
for i in range (101):
3+
a += i**2;
4+
b += i;
5+
print (b**2 - a);

0 commit comments

Comments
 (0)