From bf50e4a64539a5145cd206fac8a85f273aa78b60 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Sat, 22 Dec 2018 19:39:10 -0500 Subject: [PATCH] Generated html. --- ipython/html/EulerProblem046.html | 11896 +++++++++++++++++++++++++++ ipython/html/EulerProblem047.html | 11906 ++++++++++++++++++++++++++++ ipython/html/EulerProblem048.html | 11833 +++++++++++++++++++++++++++ ipython/html/index.html | 52 +- 4 files changed, 35686 insertions(+), 1 deletion(-) create mode 100644 ipython/html/EulerProblem046.html create mode 100644 ipython/html/EulerProblem047.html create mode 100644 ipython/html/EulerProblem048.html diff --git a/ipython/html/EulerProblem046.html b/ipython/html/EulerProblem046.html new file mode 100644 index 0000000..d99372d --- /dev/null +++ b/ipython/html/EulerProblem046.html @@ -0,0 +1,11896 @@ + + + + +EulerProblem046 + + + + + + + + + + + + + + +
+
+
+
+
+
+

Goldbach's other conjecture (Euler Problem 46)

Back to overview.

+
+
+
+
+
+
+
+

https://projecteuler.net/problem=46

+

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.

+

$9 = 7 + 2×1^2$

+

$15 = 7 + 2×2^2$

+

$21 = 3 + 2×3^2$

+

$25 = 7 + 2×3^2$

+

$27 = 19 + 2×2^2$

+

$33 = 31 + 2×1^2$

+

It turns out that the conjecture was false.

+

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

+
+
+
+
+
+
+
+

Okay, we reuse Fermat's test and brute force. Easy.

+
+
+
+
+
+
In [1]:
+
+
+
def expmod(base, exp, m):
+    if exp == 0:
+        return 1
+    if (exp % 2 == 0):
+        return (expmod(base, exp // 2, m) ** 2 % m)
+    return (base * expmod(base, exp - 1, m) % m)
+
+def fermat_test(n):
+    a = n - 3
+    return expmod(a, n, n) == a
+
+
+
+
+
+
+
+
In [2]:
+
+
+
def twice_square(n):
+    return 2 * n * n
+
+
+
+
+
+
+
+
In [18]:
+
+
+
n_max = 10000
+twice_squares = [twice_square(n) for n in range(1, n_max + 1)]
+
+def test_conjecture(n):
+    for ts in twice_squares:
+        if ts > n:
+            return False
+        if fermat_test(n - ts):
+            return True
+        
+assert(test_conjecture(33))
+
+
+
+
+
+
+
+
In [19]:
+
+
+
for n in range(3, n_max + 1, 2):
+    if not fermat_test(n) and test_conjecture(n) == False:
+        s = n
+
+print(s)
+assert(s == 5777)
+
+
+
+
+
+
+
+
+
+
5777
+
+
+
+
+
+
+
+
+
In [ ]:
+
+
+
 
+
+
+
+
+
+
+
+ + diff --git a/ipython/html/EulerProblem047.html b/ipython/html/EulerProblem047.html new file mode 100644 index 0000000..b63b6c2 --- /dev/null +++ b/ipython/html/EulerProblem047.html @@ -0,0 +1,11906 @@ + + + + +EulerProblem047 + + + + + + + + + + + + + + +
+
+
+
+
+
+

Distinct primes factors (Euler Problem 47)

Back to overview.

+
+
+
+
+
+
+
+

https://projecteuler.net/problem=47

+

The first two consecutive numbers to have two distinct prime factors are:

+

14 = 2 × 7

+

15 = 3 × 5

+

The first three consecutive numbers to have three distinct prime factors are:

+

644 = 2² × 7 × 23

+

645 = 3 × 5 × 43

+

646 = 2 × 17 × 19.

+

Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?

+
+
+
+
+
+
In [46]:
+
+
+
def sieve_of_eratosthenes(number):
+    primes = []
+    prospects = [n for n in range(2, number + 1)]
+    while prospects:
+        p = prospects[0]
+        prospects = [x for x in prospects if x % p != 0]
+        primes.append(p)
+        if p * p > number:
+            break
+    return primes + prospects
+
+import math
+
+def get_prime_factors(n):
+    ps = sieve_of_eratosthenes(n)
+    fs = []
+    for p in ps:
+        if n % p == 0:
+            fs.append(p)
+        while n % p == 0:
+            n = n // p
+    return fs
+
+def trial_division(n):
+    a = []  
+    if n % 2 == 0:
+        a.append(2)
+    while n % 2 == 0:
+        n //= 2
+    f = 3
+    while f * f <= n:
+        if n % f == 0:
+            a.append(f)
+            while n % f == 0:
+                n //= f
+        else:
+            f += 2   
+    if n != 1:
+        a.append(n)
+    return a
+    
+assert(get_prime_factors(14) == [2, 7])
+assert(get_prime_factors(644) == [2, 7, 23])
+
+print(trial_division(126))
+
+
+
+
+
+
+
+
+
+
[2, 3, 7]
+
+
+
+
+
+
+
+
+
In [54]:
+
+
+
s = []
+for n in range(2, 1000000):
+    if len(trial_division(n)) == 4:
+        s.append(n)
+    else:
+        s = []
+    if len(s) == 4:
+        s = s[0]
+        break
+
+print(s)
+assert(s == 134043)
+
+
+
+
+
+
+
+
+
+
134043
+
+
+
+
+
+
+
+
+
In [ ]:
+
+
+
 
+
+
+
+
+
+
+
+ + diff --git a/ipython/html/EulerProblem048.html b/ipython/html/EulerProblem048.html new file mode 100644 index 0000000..f82c13f --- /dev/null +++ b/ipython/html/EulerProblem048.html @@ -0,0 +1,11833 @@ + + + + +EulerProblem048 + + + + + + + + + + + + + + +
+
+
+
+
+
+

Self powers (Euler Problem 48)

Back to overview.

+
+
+
+
+
+
+
+

https://projecteuler.net/problem=48

+

The series, $1^1 + 2^2 + 3^3 + ... + 10^{10} = 10405071317$.

+

Find the last ten digits of the series, $1^1 + 2^2 + 3^3 + ... + 1000^{1000}$.

+
+
+
+
+
+
+
+

Okay, this would be way harder in C/C++. In every language with long int support it is easy. See the number of people who have solved it.

+
+
+
+
+
+
In [7]:
+
+
+
s = int(str(sum([i**i for i in range(1, 1001)]))[-10:])
+assert(s == 9110846700)
+print(s)
+
+
+
+
+
+
+
+
+
+
9110846700
+
+
+
+
+
+
+
+
+
In [ ]:
+
+
+
 
+
+
+
+
+
+
+
+ + diff --git a/ipython/html/index.html b/ipython/html/index.html index 37ae1ac..44a09c8 100644 --- a/ipython/html/index.html +++ b/ipython/html/index.html @@ -717,7 +717,7 @@ triangular - pentagona + pentagonal hexagonal @@ -725,6 +725,56 @@ + + + Problem 046 + Sat, 22 Dec 2018, 23:39 + + + prime + + goldbach + + composite + + square + + fermat + + + + + + + + Problem 047 + Sun, 23 Dec 2018, 00:24 + + + trial division + + prime + + brute force + + + + + + + + Problem 048 + Sun, 23 Dec 2018, 00:32 + + + brute force + + self power + + + + + Problem 067