From 28bc3a34049a093149b8ebac22bbe0c775e9eb82 Mon Sep 17 00:00:00 2001 From: treecity Date: Sat, 7 Apr 2012 18:29:38 +0200 Subject: [PATCH] func update --- 12.py | 12 ++++++++---- 3.py | 2 +- 6.py | 2 +- func.py | 38 +++++++++++++++++++++----------------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/12.py b/12.py index 87c8732..19b529f 100644 --- a/12.py +++ b/12.py @@ -3,7 +3,7 @@ import math def factor2(n): if n<4: - return [] + return {n:1} p = func.primes(int(n**.5+1)) f = {} while n>1: @@ -32,11 +32,15 @@ def catult(seq): def possi(test): return sum(catult(map(lambda x:test[x],test.keys()))[1:])+1 +def devisors(num): + test = factor2(num) + return sum(catult(map(lambda x:test[x],test.keys()))[1:])+1 + # Eigene Loesung for i in range(3,15000): - if(possi(factor2(func.summandielle(i)))>500): - print [possi(factor2(func.summandielle(i))), i, func.summandielle(i)], + if(possi(factor2(func.summandial(i)))>500): + print [possi(factor2(func.summandial(i))), i, func.summandial(i)], break # Phil Buff @@ -46,7 +50,7 @@ for i in range(10,15000): else: pos = possi(factor2(i))*possi(factor2((i+1)/2)) if(pos>500): - print [possi(factor2(func.summandielle(i))), i, func.summandielle(i)], + print [possi(factor2(func.summandial(i))), i, func.summandial(i)], break diff --git a/3.py b/3.py index 0843895..e1fb70b 100644 --- a/3.py +++ b/3.py @@ -14,7 +14,7 @@ def primes(n): def factor(n): if n<4: - return [] + return [n] p = primes(int(n**.5+1)) f = [] while n>1: diff --git a/6.py b/6.py index cc6be2e..3570bee 100644 --- a/6.py +++ b/6.py @@ -1,3 +1,3 @@ import func -print abs(func.summandielle(100)**2 - reduce(lambda x,y:x+y*y,range(1,101),0)) \ No newline at end of file +print abs(func.summandial(100)**2 - reduce(lambda x,y:x+y*y,range(1,101),0)) \ No newline at end of file diff --git a/func.py b/func.py index d943894..4d2c589 100644 --- a/func.py +++ b/func.py @@ -1,36 +1,36 @@ import math # Berechnet die Summe aller vielfachen von base bis max -def summandielle(max,base=1): - max = int(max/base)*base - return max*(max+base)/(2*base) +def summandial(m,base=1): + m = int(m/base)*base + return m*(m+base)/(2*base) # Gibt die naechst kleine Fib zu max zurueck -def fib(max): +def fib(m): a,b = 1,2 - while b < max: + while b < m: a,b = b,a+b return a # Gibt die Liste aller Fib zur naechst kleineren Fib von max zurueck -def fib2(max): +def fibV(m): a = [1, 2] i = 1; - while a[i] < max: + while a[i] < m: a.append(a[i] + a[i-1]) i = i+1 return a # Gibt die Summe aller geraden Fib zu max zurueck -def fibS(max): +def fibS(m): a,b = 1,2 - sum = 0 - while b < max: + s = 0 + while b < m: a,b = b,a+b if a%2 == 0: - sum = sum +a - - return sum + s = s +a + return s + # Gibt alle Primzahlen bis n zurueck def primes(n): if n < 2: @@ -47,7 +47,7 @@ def primes(n): # Gibt alle Primfaktoren bis von n zurueck def factor(n): if n<4: - return [] + return [n] p = primes(int(n**.5+1)) f = [] while n>1: @@ -60,9 +60,9 @@ def factor(n): f.sort() return f -def factor2(n): +def factorD(n): if n<4: - return [] + return {n:1} p = primes(int(n**.5+1)) f = {} while n>1: @@ -98,4 +98,8 @@ def ebinomial(seq): vek[j] = vek[j]+vek[j-1]*i vek[len(vek):]=[0] - return vek[:len(vek)-1] \ No newline at end of file + return vek[:len(vek)-1] + +def divisors(num): + test = factorD(num) + return sum(ebinomial(map(lambda x:test[x],test.keys()))[1:])+1 \ No newline at end of file -- 2.47.3