Project Euler 20: Factorial digit sum

Project Euler 20 Problem Statement n! means n × (n − 1) × … × 3 × 2 × 1 Find the digit sum in the number 100! Solution Python natively supports arbitrary-precision integers and arithmetic with as many digits as necessary to perform a calculation.  For...

Project Euler 21: Amicable numbers

Project Euler 21 Problem Statement Project Euler 21: Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called...

Project Euler 22: Names scores – SOLVED

Project Euler 22 Problem Statement Project Euler 22: Using names.txt, a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out the alphabetical value for each name, multiply this value by its alphabetical...

Project Euler 23: Non-abundant sums – SOLVED

Project Euler 23 Problem Statement A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number. A...

Project Euler 24: Lexicographic permutations – SOLVED

Project Euler 24 Problem Statement A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The...

Project Euler 25: N-digit Fibonacci number – SOLVED

Project Euler 25 Problem Statement The Fibonacci sequence is defined by the recurrence relation: Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1. Hence the first 12 terms will be: {1,1,2,3,5,8,13,21,34,55,89,144} The 12th term, F12, is the first term to contain three...

Project Euler 26: Reciprocal cycles – SOLVED

Project Euler 26 Problem Statement A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominators 2 to 10 are given: 1/2= 0.5 1/3= 0.(3) 1/4= 0.25 1/5= 0.2 1/6= 0.1(6) 1/7= 0.(142857)...

Project Euler 27: Quadratic primes – SOLVED

Project Euler 27 Problem Statement Project Euler 27: Euler published the remarkable quadratic formula: n² + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41...

Project Euler 28: Number spiral diagonals – SOLVED

Project Euler 28 Problem Statement Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows: 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 It can be verified that the sum of both diagonals is...

Project Euler 29: Distinct powers – SOLVED

Project Euler 29 Problem Statement Originally published on blog.dreamshire.com, M. Molony, APRIL 7, 2009. Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: 22=4, 23=8, 24=16, 25=32 32=9, 33=27, 34=81, 35=243 42=16, 43=64, 44=256, 45=1024...