原题链接 http://projecteuler.net/problem=34

Digit factorials

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.

数字的阶乘

145是一个特殊的数字,因为1! + 4! + 5! = 1 + 24 + 120 = 145.

求所有满足数的每位数的阶乘之和等于数本身这个条件的数的和
注意:因为1!= 1 和 2!= 2不是和,所以没有被包括进来。

联系作者

原题链接 http://projecteuler.net/problem=33

Digit canceling fractions

The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that49/98 = 4/8, which is correct, is obtained by cancelling the 9s.

We shall consider fractions like, 30/50 = 3/5, to be trivial examples.

There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.

If the product of these four fractions is given in its lowest common terms, find the value of the denominator.

数字约分

分数49/98是一个特殊的分数,对于一个不熟练的数学爱好者在尝试化简它时,可能会错误地消去9,认为49/98 = 4 / 8,最终的到的结果是正确的。

对于分数30/50 = 3/5,我们认为这是平凡的例子

正好存在4个这种不平凡的分数,它们的值小于1,分子和分母都是两位数。

如果将这四个分数的乘积化简为最简形式,得到的分母是什么?

解答:

这题没什么好说的。

联系作者

原题链接 http://projecteuler.net/problem=32

Pandigital products

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, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

全位数乘积
如果一个n位数恰好使用1到n各一次,我们称这个数为全位数;例如,5位数,15234,是一个1到5的全位数。

乘积7254不寻常,对于恒等式 39 * 186 = 7254,包括被乘数,乘数,乘积,正好是一个1到9的全位数

求所有满足被乘数,乘数,乘积这个恒等式是从1到9的全位数这个条件的乘积的和。
提示:有些乘积可以有不只一种形式,要确保只计算一次。
解法:
这题没什么好说的。

联系作者

原题链接 http://projecteuler.net/problem=31

Coin sums

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 + 150p + 220p + 15p + 12p + 31p

How many different ways can £2 be made using any number of coins?

硬币的和

在英国,货币单位有磅(£),便士(p),一共有八种硬币发行:

1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).

对于£2可以有以下组成形式:

1£1 + 150p + 220p + 15p + 12p + 31p

求£2的组成方式一共有多少种?

解法:

这是一个多重背包问题。两个循环解决问题,注意循环的顺序。

联系作者

原题链接 http://projecteuler.net/problem=30

Digit fifth powers

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:

1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

As 1 = 14 is not a sum it is not included.

The sum of these numbers is 1634 + 8208 + 9474 = 19316.

Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.

数字的5次幂

令人惊奇的是只存在3个数可以写成数的每位数字的4次幂的和

1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44

这里1 = 14 不是和所以没有包括进来

这些数字的和为1634 + 8208 + 9474 = 19316.

求所有满足数的每位数字的5次幂等于数本身这个条件的数的和

解法:

没什么好说的。

联系作者

原题链接 http://projecteuler.net/problem=29

Distinct powers

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
52=25, 53=125, 54=625, 55=3125

If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:

4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125

How many distinct terms are in the sequence generated by ab for 2 <= a <= 100 and 2 <= b <= 100?

唯一的幂方

考虑ab形式的所有整数,其中2 <= a <= 5,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
52=25, 53=125, 54=625, 55=3125

如果将它们按大小排序,去除重复数字,我们可以得到如下15个唯一的数:

4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125

求在ab 其中 2 <= a <= 100 ,2 <= b <= 100中,唯一的数有多少个?

解法:

这里用一个set来存。数学方法还没想到。

联系作者

原题链接 http://projecteuler.net/problem=28

Number spiral diagonals

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 the numbers on the diagonals is 101.

What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?

数字螺旋的对角线

从1开始向右顺时针方向螺旋得到一个5 * 5的螺旋数如下:

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

可以验证对角线上的数之和为101

求以相同形式构成的1001 * 1001的螺旋数的对角线之和。

解答:

这题没什么好说的,就是找规律。

联系作者

原题链接 http://projecteuler.net/problem=27

Quadratic primes

Euler discovered 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 is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly divisible by 41.

The incredible formula n² -79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, -79 and 1601, is -126479.

Considering quadratics of the form:

n² + an + b, where |a| <1000 and |b| <1000
where |n| is the modulus/absolute value of n
e.g. |11| = 11 and |-4| = 4
Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.

二项式素数

欧拉发现著名的二项式公式:

n² + n + 41

当n从0到39时,这个公式可以产生40个连续的素数。然而,当n = 40时, 402 + 40 + 41 = 40(40 + 1) + 41可以被41整除,毫无疑问的,当n = 41时,41² + 41 + 41可以被41整除

另一个惊人的公式n² − 79n + 1601 被发现,这个公式当n = 0到79时可以产生80个连续的素数。两个系数-79和1601的乘积为-126479.

考虑如下的二项式形式

n² + an + b, 且|a| <1000 , |b| <1000

这里 |n| 是 n的绝对值
e.g. |11| = 11 and |-4| = 4

求对于这个二项式表达式,从n = 0开始,连续产生最多素数的系数a和b的乘积。

解法:

这题没什么好说的,先用筛法生成一个素数判断表,之后就是遍历了。

联系作者

原题链接 http://projecteuler.net/problem=26

Reciprocal cycles

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= 0.1

Where 0.1(6) means 0.166666…, and has a 1-digit recurring cycle. It can be seen that 1/7 has a 6-digit recurring cycle.

Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.

倒数循环

单分数指的是分子为1的分数。分母为2到10的单分数的小数表示为:

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= 0.1

其中0.1(6)表示0.166666…,也就是有一个循环数字.可以看到1/7有6个循环数字.

求d < 1000中 1/d包含最多循环数字的那个d.

解法:

这题还没想好。

更新于2013年8月15日:问题解决了,现在才知道,如果尝试自己去实现表示无穷小数,就会发现规律。

联系作者

原题链接 http://projecteuler.net/problem=25

1000-digit Fibonacci number

The Fibonacci sequence is defined by the recurrence relation:

F(n) = F(n-1)+ F(n-2), where F1 = 1 and F2 = 1.

Hence the first 12 terms will be:

F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144

The 12th term, F12, is the first term to contain three digits.

What is the first term in the Fibonacci sequence to contain 1000 digits?

1000个数字的斐波纳契数

斐波那契数列由如下递归关系定义:

F(n) = F(n-1)+ F(n-2), 且 F1 = 1 ,F2 = 1

因此数列的前12项为:

F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144

第12项,即是第一个包含三个数字的项

求数列中第一个包含1000个数字的项

解法:

用第二题中的方法,生成斐波那契数列,之后判断。

联系作者