From c51351b0e8d084ca52e2625bb5aadb8b72d68619 Mon Sep 17 00:00:00 2001 From: treecity Date: Sat, 7 Apr 2012 01:10:03 +0200 Subject: [PATCH] 1-10 \\4 --- 10.py | 5 +++++ 2.py | 26 ++++++++++++++++++++++++++ 3.py | 33 +++++++++++++++++++++++++++++++++ 5.py | 1 + 6.py | 3 +++ 7.py | 4 ++++ 8.py | 32 ++++++++++++++++++++++++++++++++ 9.py | 11 +++++++++++ 8 files changed, 115 insertions(+) create mode 100644 10.py create mode 100644 2.py create mode 100644 3.py create mode 100644 5.py create mode 100644 6.py create mode 100644 7.py create mode 100644 8.py create mode 100644 9.py diff --git a/10.py b/10.py new file mode 100644 index 0000000..ab5901b --- /dev/null +++ b/10.py @@ -0,0 +1,5 @@ +import func + +lis = func.primes(2*10**6) +print sum(lis) + diff --git a/2.py b/2.py new file mode 100644 index 0000000..a823978 --- /dev/null +++ b/2.py @@ -0,0 +1,26 @@ +def fib(max): + a,b = 1,2 + while b < max: + a,b = b,a+b + return a + +def fib2(max): + a = [1, 2] + i = 1; + while a[i] < max: + a.append(a[i] + a[i-1]) + i = i+1 + return a + +def fibS(max): + a,b = 1,2 + sum = 0 + while b < max: + a,b = b,a+b + if a%2 == 0: + sum = sum +a + + return sum + + +print fibS(4000000) \ No newline at end of file diff --git a/3.py b/3.py new file mode 100644 index 0000000..0843895 --- /dev/null +++ b/3.py @@ -0,0 +1,33 @@ +import math + +def primes(n): + if n < 2: + return 0 + p = range(1,n+1,2) + q = len(p); + p[0] = 2; + for k in range(3,int(n**.5+1),2): + if p[(k-1)/2]: + for i in range(((k*k-1)/2),q,k): + p[i] = 0 + return filter(lambda x:x>0,p) + +def factor(n): + if n<4: + return [] + p = primes(int(n**.5+1)) + f = [] + while n>1: + p = filter(lambda x:n%x==0,p) + if(p==[]): + f.append(n) + break + f[len(f):] = p + n = n/prod(p) + f.sort() + return f + +def prod(seq): + return reduce(lambda x,y:x*y, seq, 1) + +print factor(600851475143) diff --git a/5.py b/5.py new file mode 100644 index 0000000..3c63d70 --- /dev/null +++ b/5.py @@ -0,0 +1 @@ +print 2^4 * 3^2 * 5 * 7 * 11 * 13 * 17 * 19 \ No newline at end of file diff --git a/6.py b/6.py new file mode 100644 index 0000000..cc6be2e --- /dev/null +++ b/6.py @@ -0,0 +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 diff --git a/7.py b/7.py new file mode 100644 index 0000000..3867c9c --- /dev/null +++ b/7.py @@ -0,0 +1,4 @@ +import func + +prim = func.primes(1000000) +print prim[10001] \ No newline at end of file diff --git a/8.py b/8.py new file mode 100644 index 0000000..c4fa9f6 --- /dev/null +++ b/8.py @@ -0,0 +1,32 @@ +import func +number = '73167176531330624919225119674426574742355349194934\ +96983520312774506326239578318016984801869478851843\ +85861560789112949495459501737958331952853208805511\ +12540698747158523863050715693290963295227443043557\ +66896648950445244523161731856403098711121722383113\ +62229893423380308135336276614282806444486645238749\ +30358907296290491560440772390713810515859307960866\ +70172427121883998797908792274921901699720888093776\ +65727333001053367881220235421809751254540594752243\ +52584907711670556013604839586446706324415722155397\ +53697817977846174064955149290862569321978468622482\ +83972241375657056057490261407972968652414535100474\ +82166370484403199890008895243450658541227588666881\ +16427171479924442928230863465674813919123162824586\ +17866458359124566529476545682848912883142607690042\ +24219022671055626321111109370544217506941658960408\ +07198403850962455444362981230987879927244284909188\ +84580156166097919133875499200524063689912560717606\ +05886116467109405077541002256983155200055935729725\ +71636269561882670428252483600823257530420752963450' + +pro = 0; +ind = 0; +for i in range(len(number)-5): + tmp = func.prod(map(lambda x:int(x),number[i:i+5])) + if(tmp>pro): + pro = tmp + ind = i + +print pro +print number[i:i+5] diff --git a/9.py b/9.py new file mode 100644 index 0000000..d38f766 --- /dev/null +++ b/9.py @@ -0,0 +1,11 @@ +import func +def pythtrip(u,v): + return [u*u-v*v, 2*u*v, u*u+v*v] + + +for i in range(100): + for j in range(i): + if(sum(pythtrip(i,j))==10**3): + print [i,j] + print pythtrip(i,j) + print func.prod(pythtrip(i,j)) -- 2.47.3