From de6b3e89bd74b6146767b43a448e8c6800cbce94 Mon Sep 17 00:00:00 2001 From: Tibor Bizjak Date: Tue, 28 Mar 2023 01:58:58 +0200 Subject: [PATCH] Last old solutions with code good enough to publish. --- 012_highly_divisable_triangular_numbers.py | 29 ++++++++++++++++++++++ 048_self_powers.py | 3 +++ 2 files changed, 32 insertions(+) create mode 100644 012_highly_divisable_triangular_numbers.py create mode 100644 048_self_powers.py diff --git a/012_highly_divisable_triangular_numbers.py b/012_highly_divisable_triangular_numbers.py new file mode 100644 index 0000000..a57e227 --- /dev/null +++ b/012_highly_divisable_triangular_numbers.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +def nofdivs(n): + sieve = [1] * n + for p in range(2, n): + if sieve[p] > 1: + continue + pw = 1 + while p**pw < n: + for i in range(p**pw, n, p**pw): + sieve[i] += sieve[i] // pw + pw += 1 + return sieve + + +bound = 10**5 + +sieve = nofdivs(bound) + +target = 500 + +for n in range(1, bound-1): + if n % 2: + a, b = (n + 1)//2, n + else: + a, b = n//2, n+1 + if sieve[a] * sieve[b] > target: + print(a * b) + break diff --git a/048_self_powers.py b/048_self_powers.py new file mode 100644 index 0000000..f010edb --- /dev/null +++ b/048_self_powers.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 + +print(sum(pow(x, x, (10**10)) for x in range(1,1000+1)) % 10**10)