2010-10-01から1ヶ月間の記事一覧

Project Euler Problem 031

http://projecteuler.net/index.php?section=problems&id=31 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2031 In England the currency is made up of pound, e, and pence, p, and there are eight coins in general circulati…

Project Euler Problem 030

http://projecteuler.net/index.php?section=problems&id=30 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2030 Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: 1…

Project Euler Problem 029

http://projecteuler.net/index.php?section=problems&id=29 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2029 Consider all integer combinations of a^b for 2 全部計算して結果を数えた。あんまり良いやり方ではないとおもう…

Project Euler Problem 028

http://projecteuler.net/index.php?section=problems&id=28 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2028 Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as fol…

Project Euler Problem 027

http://projecteuler.net/index.php?section=problems&id=27 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2027 Euler published the remarkable quadratic formula: n^2 + n + 41 It turns out that the formula will produce 40…

Project Euler Problem 026

http://projecteuler.net/index.php?section=problems&id=26 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2026 A unit fraction contains 1 in the numerator. The decimal representation of the unit fractions with denominat…

Project Euler Problem 025

http://projecteuler.net/index.php?section=problems&id=25 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2025 The Fibonacci sequence is defined by the recurrence relation: Fn = Fn-1 + Fn-2, where F1 = 1 and F2 = 1. Hen…

Project Euler Problem 024

http://projecteuler.net/index.php?section=problems&id=24 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2024 A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the dig…

Project Euler Problem 023

http://projecteuler.net/index.php?section=problems&id=23 http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2023 A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For ex…

Project Euler Problem 022

http://projecteuler.net/index.php?section=problems&id=22 Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-thousand first names, begin by sorting it into alphabetical order. Then working out t…

Project Euler Problem 021

http://projecteuler.net/index.php?section=problems&id=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 ea…

Project Euler Problem 020

http://projecteuler.net/index.php?section=problems&id=20 n! means n (n 1) ... 3 2 1 Find the sum of the digits in the number 100! 100の階乗の各桁の合計。非常にてきとう。 import operator import datetime def sum_of_digits(n): result = 0 whil…

Project Euler Problem 019

http://projecteuler.net/index.php?section=problems&id=19 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 re…

Project Euler Problem 018

http://projecteuler.net/index.php?section=problems&id=18 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 3 That is, 3 + 7 + 4 + 9 =…

Project Euler Problem 017

http://projecteuler.net/index.php?section=problems&id=17 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 thous…

Project Euler Problem 016

http://projecteuler.net/index.php?section=problems&id=16 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? 2の1000乗の各桁の合計。 ** 演算子を忘れていて math.pow を使って…

Project Euler Problem 015

http://projecteuler.net/index.php?section=problems&id=15 Starting in the top left corner of a 2x2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20x20 grid? 何通りの経路があ…

Project Euler Problem 014

http://projecteuler.net/index.php?section=problems&id=14 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 f…

Project Euler Problem 013

http://projecteuler.net/index.php?section=problems&id=13 Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 足して割るだけ。桁数を求めるには対数を使う。C ではこうはいくまい、Python様々。 s =""" 37107287…

Project Euler Problem 012

http://projecteuler.net/index.php?section=problems&id=12 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…

Project Euler Problem 011

http://projecteuler.net/index.php?section=problems&id=11 In the 20x20 grid below, four numbers along a diagonal line have been marked in red. What is the greatest product of four adjacent numbers in any direction (up, down, left, right, or…

Project Euler Problem 010

http://projecteuler.net/index.php?section=problems&id=10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 2000000未満の素数を合計する。素数は1とその数自体でしか割れない自然数なので、既…

Project Euler Problem 009

http://projecteuler.net/index.php?section=problems&id=9 A Pythagorean triplet is a set of three natural numbers, a b c, for which, a^2 + b^2 = c^2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for wh…

Project Euler Problem 008

http://projecteuler.net/index.php?section=problems&id=8 Find the greatest product of five consecutive digits in the 1000-digit number. 1000桁の数のなかで5桁の数字を抜き出して各桁を積算したときに一番大きな値を求める。Greedyに探す方法しかな…

Project Euler Problem 007

http://projecteuler.net/index.php?section=problems&id=7 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? 10001番目の素数を調べる。 素数でない数はいずれか…

Project Euler Problem 006

http://projecteuler.net/index.php?section=problems&id=6 The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence…

Project Euler Problem 005

http://projecteuler.net/index.php?section=problems&id=5 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 …

Project Euler Problem 004

http://projecteuler.net/index.php?section=problems&id=4 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 o…

Project Euler Problem 003

http://projecteuler.net/index.php?section=problems&id=3 The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? 問題文にあるとおり素因数分解をする。これ以外の方法はわからん。 import mat…

Project Euler Problem 002

http://projecteuler.net/index.php?section=problems&id=2 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, ... Fin…