Project Euler Problem 35

問題 The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime. There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97. How many circular …

Project Euler Problem 34

問題 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. Find the sum of all numbers which are equal to the sum of the factorial of their digits. Note: as 1! = 1 and 2! = 2 are not sums they are not included. ソース class Intege…

Project Euler Problem 33

問題 The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s. We shall consider fractions like, 3…

Project Euler Problem 32

問題 We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital. The product 7254 is unusual, as the identity, 39 × 186 = 7254,…

Project Euler Problem 31

問題 In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation: 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p). It is possible to make £2 in the following way: 1×£1 + 1×50p + 2×20p +…

Project Euler Problem 30

問題 Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits: 1634 = 1^4 + 6^4 + 3^4 + 4^4 8208 = 8^4 + 2^4 + 0^4 + 8^4 9474 = 9^4 + 4^4 + 7^4 + 4^4 As 1 = 1^4 is not a sum it is not includ…

Project Euler Problem 29

問題 Consider all integer combinations of a^b for 2 <= a <= 5 and 2 <= b <= 5: 2^2=4, 2^3=8, 2^4=16, 2^5=32 3^2=9, 3^3=27, 3^4=81, 3^5=243 4^2=16, 4^3=64, 4^4=256, 4^5=1024 5^2=25, 5^3=125, 5^4=625, 5^5=3125 If they are then placed in nume…

Project Euler Problem 28

問題 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 di…

Project Euler Problem 27

問題 Euler published the remarkable quadratic formula: n^2 + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 40^2 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and…

Project Euler Problem 26

問題 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) 1/8 = 0.125 1/9 = 0.(1) 1/10 =…

Project Euler Problem 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 the alphabetical value for each name, multiply this v…

Project Euler Problem 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 amicable numbers. For exa…

Project Euler Problem 20

問題 n! means n × (n − 1) × ... × 3 × 2 × 1 Find the sum of the digits in the number 100! ソース class Integer def fact return 1 if self.zero? self * (self - 1).fact end end puts 100.fact.to_s.scan(/./).map{|x| x.to_i}.inject(:+) 解答 648 …

Project Euler Problem 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 rest have thirty-one, Saving February alone, Which…

Project Euler Problem 67

問題 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]5 2[4]6 8 5[9]3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom in…

Project Euler Problem 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]5 2[4]6 8 5[9]3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom of…

Project Euler Problem 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 thousand) inclusive were written out in words, how many l…

Project Euler Problem 25

問題 The Fibonacci sequence is defined by the recurrence relation: F_(n) = F_(n−1) + F_(n−2), where F_(1) = 1 and F_(2) = 1. Hence the first 12 terms will be: F_(1) = 1 F_(2) = 1 F_(3) = 2 F_(4) = 3 F_(5) = 5 F_(6) = 8 F_(7) = 13 F_(8) = 2…

Project Euler Problem 24

問題 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 le…

Project Eulerで使った階乗/約数/過剰数/不足数/完全数/友愛数(親和数)のまとめ

Project Eulerで使ったメソッドをまとめてみました 特にProject Eulerやっている人には便利だと思うのでぜひ使ってみてください。 (コレを使ったらほとんど答えになるので、自分で正解出した後でこんなやり方もあるんだ程度で。。←ツッコミどころ満載です)…

Project Euler Problem 23

問題 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 numbe…

Project Euler Problem 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 following sequence: 13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 …

Project Euler Problem 13

問題 Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 ・ ・ (略) ・ ・ 5350353422647252425087405…

Project Euler Problem 12

問題 The sequence of triangle numbers is generated by adding the natural numbers. So the 7^(th) triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the…

Project Euler Problem 11

問題 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 56 62 00 81 49 31 73 55 79 14 29 93 71…

Project Euler Problem 10

問題 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. ソース max = 2000000 prime = Array.new(max, 1) prime[0] = 0 prime[1] = 0 i = 2 while i < Math.sqrt(max).to_i + 1 do (i + i).step(m…

Project Euler Problem 9

問題 A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, 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 the product abc. …

Project Euler Problem 8

問題 Find the greatest product of five consecutive digits in the 1000-digit number. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12…

Project Euler Problem 7

問題 By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6^th prime is 13. What is the tex:10001^st prime number? ソース n = 10001 max = 150000 prime = Array.new(max, 1) prime[0] = 0 prime[1] = 0 i = 2 count…

Project Euler Problem 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? ソース x = 1000 puts (2 ** x).to_s.scan(/./).map{|x| x.to_i}.inject(:+) 解答 1366 感想 コレはRubyとinjectのお陰!