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

Square root convergents

It is possible to show that the square root of two can be expressed as an infinite continued fraction.

sqrt( 2) = 1 + 1/(2 + 1/(2 + 1/(2 + … ))) = 1.414213…

By expanding this for the first four iterations, we get:

1 + 1/2 = 3/2 = 1.5
1 + 1/(2 + 1/2) = 7/5 = 1.4
1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666…
1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379…

The next three expansions are 99/70, 239/169, and 577/408, but the eighth expansion, 1393/985, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator.

In the first one-thousand expansions, how many fractions contain a numerator with more digits than denominator?

 

平方根收敛

有可能将2的平方根表示成无限分数:

sqrt(2) = 1 + 1/(2 + 1/(2 + 1/(2 + … ))) = 1.414213…

扩展这个式子的前四项,我们得到

1 + 1/2 = 3/2 = 1.5
1 + 1/(2 + 1/2) = 7/5 = 1.4
1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666…
1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379…

之后的三项是99/70,239/169,和577/408,对于第八项,1393/985,是第一个分子中的数字个数超过分母中的数字个数的项

在前1000项中,一共有多少个分数是分子中的数字个数超过分母的?

解答:

就是如何表示分数,之后定义分数的加法,不难。

联系作者

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

Powerful digit sum

A googol (10100) is a massive number: one followed by one-hundred zeros; 100100 is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

Considering natural numbers of the form, ab, where a, b < 100, what is the maximum digital sum?

幂方数字和
古戈尔 (10100)是一个天文数字:1后面跟着100个零;100100更是不可想象的大:1后面跟着200个零。尽管它们非常大,但是它们的数字和为1.

求幂方ab中,a,b < 100,最大的数字和
解法:
暴力吧。

联系作者

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

Lychrel numbers

If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.

Not all numbers produce palindromes so quickly. For example,

349 + 943 = 1292,
1292 + 2921 = 4213
4213 + 3124 = 7337

That is, 349 took three iterations to arrive at a palindrome.

Although no one has proved it yet, it is thought that some numbers, like 196, never produce a palindrome. A number that never forms a palindrome through the reverse and add process is called a Lychrel number. Due to the theoretical nature of these numbers, and for the purpose of this problem, we shall assume that a number is Lychrel until proven otherwise. In addition you are given that for every number below ten-thousand, it will either (i) become a palindrome in less than fifty iterations, or, (ii) no one, with all the computing power that exists, has managed so far to map it to a palindrome. In fact, 10677 is the first number to be shown to require over fifty iterations before producing a palindrome: 4668731596684224866951378664 (53 iterations, 28-digits).

Surprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is 4994.

How many Lychrel numbers are there below ten-thousand?

NOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers.
利克瑞尔数

如果我们取47,将它逆序并求和,47 + 74 = 121,是一个回文数。
并不是所有的数都可以这么快产生回文数。例如
349 + 943 = 1292,
1292 + 2921 = 4213
4213 + 3124 = 7337
也就是说,349用了3此迭代得到一个回文数。
虽然至今没有人证明,但是有猜想认为一些数,如196,永远不产生回文数。一个数通过逆序和迭代如果永远不产生回文数则称为利克瑞尔数。因为这些数的理论本质以及方便这个问题的目的,我们假设一个数是利克瑞尔数,直到证明不是。另外,对于每个小于10000的数,给定两种可能,它或者是(i)在小于50次迭代变成循环数(ii)没有一个人,在有限的计算能力下,能够将它迭代到一个回文数。事实上,10677是第一个超过50次迭代产生回文数:4668731596684224866951378664(53次迭代,28位数)
令人惊奇的是,有一些回文数自身也是利克瑞尔数,第一个例子是4994.
求10000以下一共有多少个利克瑞尔数?
注意:为了强调利克瑞尔数的理论一些性质,一些单词于2007.4.24更改

解答:
没什么,遍历。

联系作者

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

Poker hands

In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:

  • High Card: Highest value card.
  • One Pair: Two cards of the same value.
  • Two Pairs: Two different pairs.
  • Three of a Kind: Three cards of the same value.
  • Straight: All cards are consecutive values.
  • Flush: All cards of the same suit.
  • Full House: Three of a kind and a pair.
  • Four of a Kind: Four cards of the same value.
  • Straight Flush: All cards are consecutive values of same suit.
  • Royal Flush:Ten, Jack, Queen, King, Ace, in same suit.
    The cards are valued in the order:
    2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.

If two players have the same ranked hands then the rank made up of the highest value wins; for example, a pair of eights beats a pair of fives (see example 1 below). But if two ranks tie, for example, both players have a pair of queens, then highest cards in each hand are compared (see example 4 below); if the highest cards tie then the next highest cards are compared, and so on.

Consider the following five hands dealt to two players:


























































HandPlayer 1Player 2Winner
15H 5C 6S 7S KD
Pair of Fives
2C 3S 8S 8D TD
Pair of Eights
Player 2
25D 8C 9S JS AC
Highest card Ace
2C 5C 7D 8S QH
Highest card Queen
Player 1
32D 9C AS AH AC
Three Aces
3D 6D 7D TD QD
Flush with Diamonds
Player 2
44D 6S 9H QH QC
Pair of Queens
Highest card Nine
3D 6D 7H QD QS
Pair of Queens
Highest card Seven
Player 1
52H 2D 4C 4D 4S
Full House
With Three Fours
3C 3D 3S 9S 9D
Full House
with Three Threes
Player 1

The file, poker.txt, contains one-thousand random hands dealt to two players. Each line of the file contains ten cards (separated by a single space): the first five are Player 1’s cards and the last five are Player 2’s cards. You can assume that all hands are valid (no invalid characters or repeated cards), each player’s hand is in no specific order, and in each hand there is a clear winner.

How many hands does Player 1 win?

扑克手牌

在扑克牌游戏中,一手牌由5张牌构成,有不同的等级,从最小到最大,规则如下:

大牌:牌中最大的

对子:两张相同的牌

两对:有两对对子

三条:三张相同的牌

顺子:所有的牌是连续的

同花:所有的牌是同一花色

葫芦:三条和一对

四条:四张相同的牌

同花顺:所有的牌连续且是同花

同花大顺:AKQJ10组成的同花顺

牌值的顺序如下:

2,3,4,5,6,7,8,9,10,J,Q,K,A

如果两个玩家有相同等级的牌,则值更大的那个赢,例如一对8赢一对5(如下例1),但是如果等级相同,例如两个玩家都有一对Q,那么将比较手牌中的最大值(如下例4),如果最大的依然相同,则比较次大的,重复如上步骤。

考虑如下5种两个玩家的对局情况:

玩家1

玩家2

赢家

1

5H 5C 6S 7S KD
一对5

2C 3S 8S 8D TD
一对8

玩家2

2

5D 8C 9S JS AC
最大牌A

2C 5C 7D 8S QH
最大牌Q

玩家1

3

2D 9C AS AH AC
3张A

3D 6D 7D TD QD
方块同花

玩家2

4

4D 6S 9H QH QC
一对Q
最大9

3D 6D 7H QD QS
一对Q
最大7

玩家1

5

2H 2D 4C 4D 4S
葫芦
三个四

3C 3D 3S 9S 9D
葫芦
三个三

玩家1




文件 poker.txt中包含一千次两个玩家的对局情况,每一行有10张牌(空格分开),前5张牌是玩家1的牌,后5张牌是玩家2的牌,你可以假设手牌都是有效的(没有无效字符和重复的牌),每个玩家的手牌都没有特殊顺序,并且每一对局一定有一个赢。

求玩家1共赢了多少次。

解答:

这题好麻烦啊,写的代码真是乱。就是按照扑克牌的规则比较大小,真是很麻烦,一度令我有放弃欧拉工程的冲动,还好坚持下来了。

联系作者

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

#

Combinatoric selections

There are exactly ten ways of selecting three from five, 12345:

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

In combinatorics, we use the notation, C(5,3) = 10.

In general,

C(n,r)=n!/(r!(n-r)!), where r <= n, n! = n (n - 1) 3 2 * 1,and 0! = 1.

It is not until n = 23, that a value exceeds one-million: C(23,10) = 1144066.

How many, not necessarily distinct, values of C(n,r), for 1 <= n <= 100, are greater than one-million?

组合选择

从五个,12345中选出三个一共有10中方法

123, 124, 125, 134, 135, 145, 234, 235, 245, and 345

在组合中我们使用记号C(5,3) = 10.

一般来说

C(n,r)=n!/(r!(n-r)!),r <= n, n! = n (n - 1) 3 2 * 1, 且0! = 1

直到n = 23,才出现值超过1000000: C(23,10) = 1144066.

求一共有多少个值,没有必要是唯一的,使得C(n,r), 1 <=n<= 100,超过1000000?

解答:

遍历吧。

联系作者

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

Permuted multiples

It can be seen that the number, 125874, and its double, 251748, contain exactly the same digits, but in a different order.

Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
倍数排列
可以看到数125874和它的两倍251748,包含相同的数字,只是顺序不同。
找出最小的正整数x,使得x,2x,3x,4x,5x,和6x包含相同的数字。

解答:
暴力吧,有一点要注意的是,第一个数字一定是1。

联系作者

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

Prime digit replacements

By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.

By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663, 56773, and 56993. Consequently 56003, being the first member of this family, is the smallest prime with this property.

Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime value family.

素数数字替换

通过替换两位数*3的第一位数字,我们得到9个数字中的6个是素数:13,23,43,53,73和83.

通过用同一数字替换数56**3的第3、4位,这个5位数是第一个数,使得替换之后的10个数中,有7个数是素数。这就形成一个家族,它们是:56003,56113,56333,56443,56773和56993。56003则是这个素数族的第一个成员,是具有这种性质的最小素数。

找出最小的素数,通过用相同的数字替换这个素数中的一部分数字(没有必要想邻),可以得到一个素数,这个素数是8素数族的一部分。

解答:

一时还想不出好的办法,先空着。

联系作者

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

Consecutive prime sum

The prime 41, can be written as the sum of six consecutive primes:
41 = 2 + 3 + 5 + 7 + 11 + 13
This is the longest sum of consecutive primes that adds to a prime below one-hundred.

The longest sum of consecutive primes below one-thousand that adds to a prime, contains 21 terms, and is equal to 953.

Which prime, below one-million, can be written as the sum of the most consecutive primes?

连续素数的和
素数41,可以写成6个连续素数的和:
41 = 2 + 3 + 5 + 7 + 11 + 13
这是100以下最长的连续素数的和等于一个素数
1000以下最长的连续素数的和,包含21个数,等于953
求1 000 000​以下能写成最长连续素数的和的素数


解法:
不懂得数学方法,只好暴力了,先求出1000 000以下素数,之后双重循环。太暴力了,竟然用了18分钟,看来还是得想办法改进。果然还是有方法的,想办法生成一个三角形,最底层是1000 000以下素数,上一层是连续两个素数之和,再上一层是连续三个素数之和,。。最后一层就是所有素数之和,从上往下找,第一个小于1000000的素数就是答案。实际过程中,可以不用从最顶上开始找,可以从第一个大于1000000那一行开始往下找,然后由这一行的数生成下一行,继续找。

联系作者

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

Prime permutations

The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual in two ways: (i) each of the three terms are prime, and, (ii) each of the 4-digit numbers are permutations of one another.

There are no arithmetic sequences made up of three 1-, 2-, or 3-digit primes, exhibiting this property, but there is one other 4-digit increasing sequence.

What 12-digit number do you form by concatenating the three terms in this sequence?

素数排列
算术序列1487,4817,8147是按照3330递增的,它有两个平常的性质:(1)这三个数都是素数 (2)这三个4位数中的每一个都是另一个的排列

不存在1位,2位,3位具有这种性质的序列,但是还有另一个4位的具有这种性质的递增序列。

求将这个序列中的三个数链接起来得到的12位数

解答:
没什么好说的,先生成一个素数判别表,之后就简单了。

联系作者

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

Self powers

The series, 11 + 22 + 33 + … + 1010 = 10405071317.

Find the last ten digits of the series, 11 + 22 + 33 + … + 10001000.
​自幂

序列 11 + 22 + 33 + … + 1010 = 10405071317
求序列11 + 22 + 33 + … + 10001000​的最后十个数字​

解答:
无非是大数运算。在Python里很简单。暴力之,只是不知道有什么数学规律没,我想不到。

联系作者