From bff7ae037109dfb4ec2a530fa1cf79a4a8c04892 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Mon, 5 Jul 2021 15:09:24 -0400 Subject: [PATCH] Solve problem 346 in Python --- python/e346.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 python/e346.py diff --git a/python/e346.py b/python/e346.py new file mode 100644 index 0000000..9530a28 --- /dev/null +++ b/python/e346.py @@ -0,0 +1,23 @@ + +def euler_346(): + n_max = 10**12 + repunits = set() + result = 1 # Our algorithm doesn't catch 1 so we add it here + for base in range(2, n_max): + n = base ** 0 + base ** 1 + for exp in range(2, n_max): + n += base**exp + if exp == 2 and n > n_max: + # There are no more repunits below n_max. + return result + if n >= n_max: + break + if not n in repunits: + repunits.add(n) + result += n + + +if __name__ == "__main__": + solution = euler_346() + print("e346.py: " + str(solution)) + assert(solution == 336108797689259276)