Here are 5 of the most difficult Project Euler statistics problems. All of them have a difficulty rating of 100%.

1) Repeated Permutation

We define a permutation as an operation that rearranges the order of the elements {1, 2, 3, ..., n}. There are n! such permutations, one of which leaves the elements in their initial order. For n = 3 we have 3! = 6 permutations:

- P1 = keep the initial order

- P2 = exchange the 1st and 2nd elements

- P3 = exchange the 1st and 3rd elements

- P4 = exchange the 2nd and 3rd elements

- P5 = rotate the elements to the right

- P6 = rotate the elements to the left

If we select one of these permutations, and we re-apply the same permutation repeatedly, we eventually restore the initial order.

For a permutation Pi, let f(Pi) be the number of steps required to restore the initial order by applying the permutation Pi repeatedly.

For n = 3, we obtain:

- f(P1) = 1 : (1,2,3) → (1,2,3)

- f(P2) = 2 : (1,2,3) → (2,1,3) → (1,2,3)

- f(P3) = 2 : (1,2,3) → (3,2,1) → (1,2,3)

- f(P4) = 2 : (1,2,3) → (1,3,2) → (1,2,3)

- f(P5) = 3 : (1,2,3) → (3,1,2) → (2,3,1) → (1,2,3)

- f(P6) = 3 : (1,2,3) → (2,3,1) → (3,1,2) → (1,2,3)

Let g(n) be the average value of f2(Pi) over all permutations Pi of length n.

g(3) = (12 + 22 + 22 + 22 + 32 + 32)/3! = 31/6 ≈ 5.166666667e0

g(5) = 2081/120 ≈ 1.734166667e1

g(20) = 12422728886023769167301/2432902008176640000 ≈ 5.106136147e3

Find g(350) and write the answer in scientific notation rounded to 10 significant digits, using a lowercase e to separate mantissa and exponent, as in the examples above.





2) Silver Dollar Game





One variant of N.G. de Bruijn's silver dollar game can be described as follows:

On a strip of squares a number of coins are placed, at most one coin per square. Only one coin, called the silver dollar, has any value. Two players take turns making moves. At each turn a player must make either a regular or a special move.

A regular move consists of selecting one coin and moving it one or more squares to the left. The coin cannot move out of the strip or jump on or over another coin.

Alternatively, the player can choose to make the special move of pocketing the leftmost coin rather than making a regular move. If no regular moves are possible, the player is forced to pocket the leftmost coin.





The winner is the player who pockets the silver dollar.

A winning configuration is an arrangement of coins on the strip where the first player can force a win no matter what the second player does.

Let W(n,c) be the number of winning configurations for a strip of n squares, c worthless coins and one silver dollar.

You are given that W(10,2) = 324 and W(100,10) = 1514704946113500.

Find W(1 000 000, 100) modulo the semiprime 1000 036 000 099 (= 1 000 003 · 1 000 033).





3) Cross Flips





N×N disks are placed on a square game board. Each disk has a black side and white side.

At each turn, you may choose a disk and flip all the disks in the same row and the same column as this disk: thus 2× N -1 disks are flipped. The game ends when all disks show their white side. The following example shows a game on a 5×5 board.





It can be proven that 3 is the minimal number of turns to finish this game.

The bottom left disk on the N×N board has coordinates (0,0);

the bottom right disk has coordinates (N-1,0) and the top left disk has coordinates (0,N-1).

Let CN be the following configuration of a board with N×N disks:

A disk at ( x , y ) satisfying



, shows its black side; otherwise, it shows its white side. C5 is shown above.

Let T(N) be the minimal number of turns to finish a game starting from configuration CN or 0 if configuration CN is unsolvable.

We have shown that T(5)=3. You are also given that T(10)=29 and T(1 000)=395253.

Find .







4) St. Petersburg Lottery





A gambler decides to participate in a special lottery. In this lottery the gambler plays a series of one or more games.

Each game costs m pounds to play and starts with an initial pot of 1 pound. The gambler flips an unbiased coin. Every time a head appears, the pot is doubled and the gambler continues. When a tail appears, the game ends and the gambler collects the current value of the pot. The gambler is certain to win at least 1 pound, the starting value of the pot, at the cost of m pounds, the initial fee.

The gambler cannot continue to play if his fortune falls below m pounds. Let pm(s) denote the probability that the gambler will never run out of money in this lottery given his initial fortune s and the cost per game m.

For example p2(2) ≈ 0.2522, p2(5) ≈ 0.6873 and p6(10 000) ≈ 0.9952 (note: pm(s) = 0 for s < m).

Find p15(109) and give your answer rounded to 7 decimal places behind the decimal point in the form 0.abcdefg.







5) Titanic Sets





A set of lattice points S is called a titanic set if there exists a line passing through exactly two points in S.

An example of a titanic set is S = {(0, 0), (0, 1), (0, 2), (1, 1), (2, 0), (1, 0)}, where the line passing through (0, 1) and (2, 0) does not pass through any other point in S.

On the other hand, the set {(0, 0), (1, 1), (2, 2), (4, 4)} is not a titanic set since the line passing through any two points in the set also passes through the other two.

For any positive integer N, let T(N) be the number of titanic sets S whose every point (x, y) satisfies 0 ≤ x, y ≤ N. It can be verified that T(1) = 11, T(2) = 494, T(4) = 33554178, T(111) mod 108 = 13500401 and T(105) mod 108 = 63259062.