2 Commity 54c8c1ad0c ... 0c49f88120

Autor SHA1 Správa Dátum
  estelendur 0c49f88120 Merge branch 'master' of notabug.org:estelendur/projecteuler 9 rokov pred
  esty 9b5d197844 Initial commit 10 rokov pred
5 zmenil súbory, kde vykonal 44 pridanie a 0 odobranie
  1. 9 0
      pe1.py
  2. 11 0
      pe2.py
  3. 21 0
      pe3.py
  4. BIN
      pe3.pyc
  5. 3 0
      pea.txt

+ 9 - 0
pe1.py

@@ -0,0 +1,9 @@
+#!usr/bin/python
+### Project Euler problem 1 (estelendur)
+# Find the sum of all multiples of 3 or 5 under 1000
+
+sum = 0
+for i in range(1,1000):	# assuming strictly less than 1000
+	if (i%3==0 or i%5==0):
+		sum += i
+print sum

+ 11 - 0
pe2.py

@@ -0,0 +1,11 @@
+### Project Euler problem 2 (estelendur)
+# Find the sum of all even Fibonacci numbers below 4 million
+
+sum=0	# not being a stupid, unlike last time
+fib1=1
+fib2=1
+while fib2 < 4000000:
+	(fib1,fib2) = (fib2,fib1+fib2)
+	if (fib2%2==0):
+		sum += fib2
+print sum

+ 21 - 0
pe3.py

@@ -0,0 +1,21 @@
+### Project Euler problem 3 (estelendur)
+# What is the largest prime factor of 600851475143?
+
+import math
+
+def not_square(b2):
+	root = math.sqrt(b2)
+	return (math.ceil(root) != math.floor(root))
+
+def fermat_factor(N): 
+	if(N%2==0): # N should be odd
+		fermat_factor(N/2)
+	else:
+		a = math.ceil(math.sqrt(N)) 
+		b2 = a**2 - N
+		while not_square(b2):
+			a += 1
+			b2 = a**2 - N
+		return (a-math.sqrt(b2))
+
+print fermat_factor(600851475143)

BIN
pe3.pyc


+ 3 - 0
pea.txt

@@ -0,0 +1,3 @@
+233168
+4613732
+486847.0