mu chance or much chance ?

日々の戯れ言

Project Euler

Project Euler 20

問題 Problem 20:Factorial digit sum n! means n × (n − 1) × ... × 3 × 2 × 1For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.Find the sum of the digits in t…

Project Euler 19

問題 Problem 19:Counting Sundays You are given the following information, but you may prefer to do some research for yourself.1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have thirty-one, Savi…

Project Euler 18

問題 Problem 18:Maximum path sum I By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23.3 7 4 2 4 6 8 5 9 3That is, 3 + 7 + 4 + 9 = 23.Find the maximum to…

Project Euler 17

問題 Problem 17:Number letter counts If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.If all the numbers from 1 to 1000 (one thousand) inclusive were …

Project Euler 16

問題 Problem 16:Power digit sum 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.What is the sum of the digits of the number 2^1000? 解答例 strNum = str(2 ** 1000) sum = 0 for i in strNum: sum += int(i) print(sum)

Project Euler 15

問題 Problem 15:Lattice paths Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.How many such routes are there through a 20×20 grid? 解…

Project Euler 14

問題 Problem 14:Longest Collatz sequence The following iterative sequence is defined for the set of positive integers:n → n/2 (n is even) n → 3n + 1 (n is odd)Using the rule above and starting with 13, we generate the following sequence:1…

Project Euler 13

問題 Problem 13:Large sum Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474…

Project Euler 12

問題 Problem 12:Highly divisible triangular number The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:1, 3, 6, 10, …

Project Euler 11

問題 Problem 11:Largest product in a grid In the 20×20 grid below, four numbers along a diagonal line have been marked in red.08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 5…

Project Euler 10

問題 Problem 10:Summation of primes The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million. 解答例 def sieveEratosthenes(num): isPrime = [True] * (num + 1) isPrime[0] = False isPrime[1] = Fal…

Project Euler 9

問題 Problem 9:Special Pythagorean triplet A Pythagorean triplet is a set of three natural numbers, a a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find…

Project Euler 8

問題 Problem 8:Largest product in a series The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801…

Project Euler 7

問題 Problem 7:10001st prime By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.What is the 10001st prime number? 解答例 def primeNum(num): prime = [2] i = 3 while len(prime) < num: for n i…

Project Euler 6

問題 Problem 6:Sum square difference The sum of the squares of the first ten natural numbers is,1^2 + 2^2 + ... + 10^2 = 385 The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)^2 = 55^2 = 3025 Hence the difference…

Project Euler 5

問題 Problem 5:Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? …

Project Euler 4

問題 Problem 4:Largest palindrome product A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-dig…

Project Euler 3

問題 Problem 3:Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 解答例 def primeFactorization(n): i = 2 table = [] while i * i <= n: while n % i == 0: n //=…

Project Euler 2

問題 Problem 2:Even Fibonacci numbers Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the t…

Project Euler 1

Python3勉強のために,Project Eulerを解いてみました.projecteuler.net 問題 Problem 1:Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Fin…