{"id": 1, "problem": "If we list all the natural numbers below $10$ that are multiples of $3$ or $5$, we get $3, 5, 6$ and $9$. The sum of these multiples is $23$.\n\nFind the sum of all the multiples of $3$ or $5$ below $1000$.", "raw_html": "

If we list all the natural numbers below $10$ that are multiples of $3$ or $5$, we get $3, 5, 6$ and $9$. The sum of these multiples is $23$.

\n

Find the sum of all the multiples of $3$ or $5$ below $1000$.

", "url": "https://projecteuler.net/problem=1", "answer": "233168"} {"id": 2, "problem": "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:\n$$1, 2, 3, 5, 8, 13, 21, 34, 55, 89, \\dots$$\n\nBy considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.", "raw_html": "

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:\n$$1, 2, 3, 5, 8, 13, 21, 34, 55, 89, \\dots$$

\n

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

", "url": "https://projecteuler.net/problem=2", "answer": "4613732"} {"id": 3, "problem": "The prime factors of $13195$ are $5, 7, 13$ and $29$.\n\nWhat is the largest prime factor of the number $600851475143$?", "raw_html": "

The prime factors of $13195$ are $5, 7, 13$ and $29$.

\n

What is the largest prime factor of the number $600851475143$?

", "url": "https://projecteuler.net/problem=3", "answer": "6857"} {"id": 4, "problem": "A palindromic number reads the same both ways. The largest palindrome made from the product of two $2$-digit numbers is $9009 = 91 \\times 99$.\n\nFind the largest palindrome made from the product of two $3$-digit numbers.", "raw_html": "

A palindromic number reads the same both ways. The largest palindrome made from the product of two $2$-digit numbers is $9009 = 91 \\times 99$.

\n

Find the largest palindrome made from the product of two $3$-digit numbers.

", "url": "https://projecteuler.net/problem=4", "answer": "906609"} {"id": 5, "problem": "$2520$ is the smallest number that can be divided by each of the numbers from $1$ to $10$ without any remainder.\n\nWhat is the smallest positive number that is evenly divisibledivisible with no remainder by all of the numbers from $1$ to $20$?", "raw_html": "

$2520$ is the smallest number that can be divided by each of the numbers from $1$ to $10$ without any remainder.

\n

What is the smallest positive number that is evenly divisibledivisible with no remainder by all of the numbers from $1$ to $20$?

", "url": "https://projecteuler.net/problem=5", "answer": "232792560"} {"id": 6, "problem": "The sum of the squares of the first ten natural numbers is,\n\n$$1^2 + 2^2 + ... + 10^2 = 385.$$\nThe square of the sum of the first ten natural numbers is,\n\n$$(1 + 2 + ... + 10)^2 = 55^2 = 3025.$$\nHence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is $3025 - 385 = 2640$.\n\nFind the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.", "raw_html": "

The sum of the squares of the first ten natural numbers is,

\n$$1^2 + 2^2 + ... + 10^2 = 385.$$\n

The square of the sum of the first ten natural numbers is,

\n$$(1 + 2 + ... + 10)^2 = 55^2 = 3025.$$\n

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is $3025 - 385 = 2640$.

\n

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

", "url": "https://projecteuler.net/problem=6", "answer": "25164150"} {"id": 7, "problem": "By listing the first six prime numbers: $2, 3, 5, 7, 11$, and $13$, we can see that the $6$th prime is $13$.\n\nWhat is the $10\\,001$st prime number?", "raw_html": "

By listing the first six prime numbers: $2, 3, 5, 7, 11$, and $13$, we can see that the $6$th prime is $13$.

\n

What is the $10\\,001$st prime number?

", "url": "https://projecteuler.net/problem=7", "answer": "104743"} {"id": 8, "problem": "The four adjacent digits in the $1000$-digit number that have the greatest product are $9 \\times 9 \\times 8 \\times 9 = 5832$.\n\n73167176531330624919225119674426574742355349194934\n\n96983520312774506326239578318016984801869478851843\n\n85861560789112949495459501737958331952853208805511\n\n12540698747158523863050715693290963295227443043557\n\n66896648950445244523161731856403098711121722383113\n\n62229893423380308135336276614282806444486645238749\n\n30358907296290491560440772390713810515859307960866\n\n70172427121883998797908792274921901699720888093776\n\n65727333001053367881220235421809751254540594752243\n\n52584907711670556013604839586446706324415722155397\n\n53697817977846174064955149290862569321978468622482\n\n83972241375657056057490261407972968652414535100474\n\n82166370484403199890008895243450658541227588666881\n\n16427171479924442928230863465674813919123162824586\n\n17866458359124566529476545682848912883142607690042\n\n24219022671055626321111109370544217506941658960408\n\n07198403850962455444362981230987879927244284909188\n\n84580156166097919133875499200524063689912560717606\n\n05886116467109405077541002256983155200055935729725\n\n71636269561882670428252483600823257530420752963450\n\nFind the thirteen adjacent digits in the $1000$-digit number that have the greatest product. What is the value of this product?", "raw_html": "

The four adjacent digits in the $1000$-digit number that have the greatest product are $9 \\times 9 \\times 8 \\times 9 = 5832$.

\n

\n73167176531330624919225119674426574742355349194934
\n96983520312774506326239578318016984801869478851843
\n85861560789112949495459501737958331952853208805511
\n12540698747158523863050715693290963295227443043557
\n66896648950445244523161731856403098711121722383113
\n62229893423380308135336276614282806444486645238749
\n30358907296290491560440772390713810515859307960866
\n70172427121883998797908792274921901699720888093776
\n65727333001053367881220235421809751254540594752243
\n52584907711670556013604839586446706324415722155397
\n53697817977846174064955149290862569321978468622482
\n83972241375657056057490261407972968652414535100474
\n82166370484403199890008895243450658541227588666881
\n16427171479924442928230863465674813919123162824586
\n17866458359124566529476545682848912883142607690042
\n24219022671055626321111109370544217506941658960408
\n07198403850962455444362981230987879927244284909188
\n84580156166097919133875499200524063689912560717606
\n05886116467109405077541002256983155200055935729725
\n71636269561882670428252483600823257530420752963450

\n

Find the thirteen adjacent digits in the $1000$-digit number that have the greatest product. What is the value of this product?

", "url": "https://projecteuler.net/problem=8", "answer": "23514624000"} {"id": 9, "problem": "A Pythagorean triplet is a set of three natural numbers, $a \\lt b \\lt c$, for which,\n$$a^2 + b^2 = c^2.$$\n\nFor example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$.\n\nThere exists exactly one Pythagorean triplet for which $a + b + c = 1000$.\nFind the product $abc$.", "raw_html": "

A Pythagorean triplet is a set of three natural numbers, $a \\lt b \\lt c$, for which,\n$$a^2 + b^2 = c^2.$$

\n

For example, $3^2 + 4^2 = 9 + 16 = 25 = 5^2$.

\n

There exists exactly one Pythagorean triplet for which $a + b + c = 1000$.
Find the product $abc$.

", "url": "https://projecteuler.net/problem=9", "answer": "31875000"} {"id": 10, "problem": "The sum of the primes below $10$ is $2 + 3 + 5 + 7 = 17$.\n\nFind the sum of all the primes below two million.", "raw_html": "

The sum of the primes below $10$ is $2 + 3 + 5 + 7 = 17$.

\n

Find the sum of all the primes below two million.

", "url": "https://projecteuler.net/problem=10", "answer": "142913828922"} {"id": 11, "problem": "In the $20 \\times 20$ grid below, four numbers along a diagonal line have been marked in red.\n\n08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08\n\n49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00\n\n81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65\n\n52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91\n\n22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80\n\n24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50\n\n32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70\n\n67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21\n\n24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72\n\n21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95\n\n78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92\n\n16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57\n\n86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58\n\n19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40\n\n04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66\n\n88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69\n\n04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36\n\n20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16\n\n20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54\n\n01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48\n\nThe product of these numbers is $26 \\times 63 \\times 78 \\times 14 = 1788696$.\n\nWhat is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the $20 \\times 20$ grid?", "raw_html": "

In the $20 \\times 20$ grid below, four numbers along a diagonal line have been marked in red.

\n

\n08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
\n49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
\n81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
\n52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
\n22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
\n24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
\n32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
\n67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
\n24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
\n21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
\n78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
\n16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
\n86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
\n19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
\n04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
\n88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
\n04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
\n20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
\n20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
\n01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48

\n

The product of these numbers is $26 \\times 63 \\times 78 \\times 14 = 1788696$.

\n

What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the $20 \\times 20$ grid?

", "url": "https://projecteuler.net/problem=11", "answer": "70600674"} {"id": 12, "problem": "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:\n$$1, 3, 6, 10, 15, 21, 28, 36, 45, 55, \\dots$$\n\nLet us list the factors of the first seven triangle numbers:\n\n$$\\begin{align}\n\\mathbf 1 &\\colon 1\\\\\n\\mathbf 3 &\\colon 1,3\\\\\n\\mathbf 6 &\\colon 1,2,3,6\\\\\n\\mathbf{10} &\\colon 1,2,5,10\\\\\n\\mathbf{15} &\\colon 1,3,5,15\\\\\n\\mathbf{21} &\\colon 1,3,7,21\\\\\n\\mathbf{28} &\\colon 1,2,4,7,14,28\n\\end{align}$$\nWe can see that $28$ is the first triangle number to have over five divisors.\n\nWhat is the value of the first triangle number to have over five hundred divisors?", "raw_html": "

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:\n$$1, 3, 6, 10, 15, 21, 28, 36, 45, 55, \\dots$$

\n

Let us list the factors of the first seven triangle numbers:

\n$$\\begin{align}\n\\mathbf 1 &\\colon 1\\\\\n\\mathbf 3 &\\colon 1,3\\\\\n\\mathbf 6 &\\colon 1,2,3,6\\\\\n\\mathbf{10} &\\colon 1,2,5,10\\\\\n\\mathbf{15} &\\colon 1,3,5,15\\\\\n\\mathbf{21} &\\colon 1,3,7,21\\\\\n\\mathbf{28} &\\colon 1,2,4,7,14,28\n\\end{align}$$\n

We can see that $28$ is the first triangle number to have over five divisors.

\n

What is the value of the first triangle number to have over five hundred divisors?

", "url": "https://projecteuler.net/problem=12", "answer": "76576500"} {"id": 13, "problem": "Work out the first ten digits of the sum of the following one-hundred $50$-digit numbers.\n\n37107287533902102798797998220837590246510135740250\n\n46376937677490009712648124896970078050417018260538\n\n74324986199524741059474233309513058123726617309629\n\n91942213363574161572522430563301811072406154908250\n\n23067588207539346171171980310421047513778063246676\n\n89261670696623633820136378418383684178734361726757\n\n28112879812849979408065481931592621691275889832738\n\n44274228917432520321923589422876796487670272189318\n\n47451445736001306439091167216856844588711603153276\n\n70386486105843025439939619828917593665686757934951\n\n62176457141856560629502157223196586755079324193331\n\n64906352462741904929101432445813822663347944758178\n\n92575867718337217661963751590579239728245598838407\n\n58203565325359399008402633568948830189458628227828\n\n80181199384826282014278194139940567587151170094390\n\n35398664372827112653829987240784473053190104293586\n\n86515506006295864861532075273371959191420517255829\n\n71693888707715466499115593487603532921714970056938\n\n54370070576826684624621495650076471787294438377604\n\n53282654108756828443191190634694037855217779295145\n\n36123272525000296071075082563815656710885258350721\n\n45876576172410976447339110607218265236877223636045\n\n17423706905851860660448207621209813287860733969412\n\n81142660418086830619328460811191061556940512689692\n\n51934325451728388641918047049293215058642563049483\n\n62467221648435076201727918039944693004732956340691\n\n15732444386908125794514089057706229429197107928209\n\n55037687525678773091862540744969844508330393682126\n\n18336384825330154686196124348767681297534375946515\n\n80386287592878490201521685554828717201219257766954\n\n78182833757993103614740356856449095527097864797581\n\n16726320100436897842553539920931837441497806860984\n\n48403098129077791799088218795327364475675590848030\n\n87086987551392711854517078544161852424320693150332\n\n59959406895756536782107074926966537676326235447210\n\n69793950679652694742597709739166693763042633987085\n\n41052684708299085211399427365734116182760315001271\n\n65378607361501080857009149939512557028198746004375\n\n35829035317434717326932123578154982629742552737307\n\n94953759765105305946966067683156574377167401875275\n\n88902802571733229619176668713819931811048770190271\n\n25267680276078003013678680992525463401061632866526\n\n36270218540497705585629946580636237993140746255962\n\n24074486908231174977792365466257246923322810917141\n\n91430288197103288597806669760892938638285025333403\n\n34413065578016127815921815005561868836468420090470\n\n23053081172816430487623791969842487255036638784583\n\n11487696932154902810424020138335124462181441773470\n\n63783299490636259666498587618221225225512486764533\n\n67720186971698544312419572409913959008952310058822\n\n95548255300263520781532296796249481641953868218774\n\n76085327132285723110424803456124867697064507995236\n\n37774242535411291684276865538926205024910326572967\n\n23701913275725675285653248258265463092207058596522\n\n29798860272258331913126375147341994889534765745501\n\n18495701454879288984856827726077713721403798879715\n\n38298203783031473527721580348144513491373226651381\n\n34829543829199918180278916522431027392251122869539\n\n40957953066405232632538044100059654939159879593635\n\n29746152185502371307642255121183693803580388584903\n\n41698116222072977186158236678424689157993532961922\n\n62467957194401269043877107275048102390895523597457\n\n23189706772547915061505504953922979530901129967519\n\n86188088225875314529584099251203829009407770775672\n\n11306739708304724483816533873502340845647058077308\n\n82959174767140363198008187129011875491310547126581\n\n97623331044818386269515456334926366572897563400500\n\n42846280183517070527831839425882145521227251250327\n\n55121603546981200581762165212827652751691296897789\n\n32238195734329339946437501907836945765883352399886\n\n75506164965184775180738168837861091527357929701337\n\n62177842752192623401942399639168044983993173312731\n\n32924185707147349566916674687634660915035914677504\n\n99518671430235219628894890102423325116913619626622\n\n73267460800591547471830798392868535206946944540724\n\n76841822524674417161514036427982273348055556214818\n\n97142617910342598647204516893989422179826088076852\n\n87783646182799346313767754307809363333018982642090\n\n10848802521674670883215120185883543223812876952786\n\n71329612474782464538636993009049310363619763878039\n\n62184073572399794223406235393808339651327408011116\n\n66627891981488087797941876876144230030984490851411\n\n60661826293682836764744779239180335110989069790714\n\n85786944089552990653640447425576083659976645795096\n\n66024396409905389607120198219976047599490197230297\n\n64913982680032973156037120041377903785566085089252\n\n16730939319872750275468906903707539413042652315011\n\n94809377245048795150954100921645863754710598436791\n\n78639167021187492431995700641917969777599028300699\n\n15368713711936614952811305876380278410754449733078\n\n40789923115535562561142322423255033685442488917353\n\n44889911501440648020369068063960672322193204149535\n\n41503128880339536053299340368006977710650566631954\n\n81234880673210146739058568557934581403627822703280\n\n82616570773948327592232845941706525094512325230608\n\n22918802058777319719839450180888072429661980811197\n\n77158542502016545090413245809786882778948721859617\n\n72107838435069186155435662884062257473692284509516\n\n20849603980134001723930671666823555245252804609722\n\n53503534226472524250874054075591789781264330331690", "raw_html": "

Work out the first ten digits of the sum of the following one-hundred $50$-digit numbers.

\n
\n37107287533902102798797998220837590246510135740250
\n46376937677490009712648124896970078050417018260538
\n74324986199524741059474233309513058123726617309629
\n91942213363574161572522430563301811072406154908250
\n23067588207539346171171980310421047513778063246676
\n89261670696623633820136378418383684178734361726757
\n28112879812849979408065481931592621691275889832738
\n44274228917432520321923589422876796487670272189318
\n47451445736001306439091167216856844588711603153276
\n70386486105843025439939619828917593665686757934951
\n62176457141856560629502157223196586755079324193331
\n64906352462741904929101432445813822663347944758178
\n92575867718337217661963751590579239728245598838407
\n58203565325359399008402633568948830189458628227828
\n80181199384826282014278194139940567587151170094390
\n35398664372827112653829987240784473053190104293586
\n86515506006295864861532075273371959191420517255829
\n71693888707715466499115593487603532921714970056938
\n54370070576826684624621495650076471787294438377604
\n53282654108756828443191190634694037855217779295145
\n36123272525000296071075082563815656710885258350721
\n45876576172410976447339110607218265236877223636045
\n17423706905851860660448207621209813287860733969412
\n81142660418086830619328460811191061556940512689692
\n51934325451728388641918047049293215058642563049483
\n62467221648435076201727918039944693004732956340691
\n15732444386908125794514089057706229429197107928209
\n55037687525678773091862540744969844508330393682126
\n18336384825330154686196124348767681297534375946515
\n80386287592878490201521685554828717201219257766954
\n78182833757993103614740356856449095527097864797581
\n16726320100436897842553539920931837441497806860984
\n48403098129077791799088218795327364475675590848030
\n87086987551392711854517078544161852424320693150332
\n59959406895756536782107074926966537676326235447210
\n69793950679652694742597709739166693763042633987085
\n41052684708299085211399427365734116182760315001271
\n65378607361501080857009149939512557028198746004375
\n35829035317434717326932123578154982629742552737307
\n94953759765105305946966067683156574377167401875275
\n88902802571733229619176668713819931811048770190271
\n25267680276078003013678680992525463401061632866526
\n36270218540497705585629946580636237993140746255962
\n24074486908231174977792365466257246923322810917141
\n91430288197103288597806669760892938638285025333403
\n34413065578016127815921815005561868836468420090470
\n23053081172816430487623791969842487255036638784583
\n11487696932154902810424020138335124462181441773470
\n63783299490636259666498587618221225225512486764533
\n67720186971698544312419572409913959008952310058822
\n95548255300263520781532296796249481641953868218774
\n76085327132285723110424803456124867697064507995236
\n37774242535411291684276865538926205024910326572967
\n23701913275725675285653248258265463092207058596522
\n29798860272258331913126375147341994889534765745501
\n18495701454879288984856827726077713721403798879715
\n38298203783031473527721580348144513491373226651381
\n34829543829199918180278916522431027392251122869539
\n40957953066405232632538044100059654939159879593635
\n29746152185502371307642255121183693803580388584903
\n41698116222072977186158236678424689157993532961922
\n62467957194401269043877107275048102390895523597457
\n23189706772547915061505504953922979530901129967519
\n86188088225875314529584099251203829009407770775672
\n11306739708304724483816533873502340845647058077308
\n82959174767140363198008187129011875491310547126581
\n97623331044818386269515456334926366572897563400500
\n42846280183517070527831839425882145521227251250327
\n55121603546981200581762165212827652751691296897789
\n32238195734329339946437501907836945765883352399886
\n75506164965184775180738168837861091527357929701337
\n62177842752192623401942399639168044983993173312731
\n32924185707147349566916674687634660915035914677504
\n99518671430235219628894890102423325116913619626622
\n73267460800591547471830798392868535206946944540724
\n76841822524674417161514036427982273348055556214818
\n97142617910342598647204516893989422179826088076852
\n87783646182799346313767754307809363333018982642090
\n10848802521674670883215120185883543223812876952786
\n71329612474782464538636993009049310363619763878039
\n62184073572399794223406235393808339651327408011116
\n66627891981488087797941876876144230030984490851411
\n60661826293682836764744779239180335110989069790714
\n85786944089552990653640447425576083659976645795096
\n66024396409905389607120198219976047599490197230297
\n64913982680032973156037120041377903785566085089252
\n16730939319872750275468906903707539413042652315011
\n94809377245048795150954100921645863754710598436791
\n78639167021187492431995700641917969777599028300699
\n15368713711936614952811305876380278410754449733078
\n40789923115535562561142322423255033685442488917353
\n44889911501440648020369068063960672322193204149535
\n41503128880339536053299340368006977710650566631954
\n81234880673210146739058568557934581403627822703280
\n82616570773948327592232845941706525094512325230608
\n22918802058777319719839450180888072429661980811197
\n77158542502016545090413245809786882778948721859617
\n72107838435069186155435662884062257473692284509516
\n20849603980134001723930671666823555245252804609722
\n53503534226472524250874054075591789781264330331690
", "url": "https://projecteuler.net/problem=13", "answer": "5537376230"} {"id": 14, "problem": "The following iterative sequence is defined for the set of positive integers:\n\n- $n \\to n/2$ ($n$ is even)\n\n- $n \\to 3n + 1$ ($n$ is odd)\n\nUsing the rule above and starting with $13$, we generate the following sequence:\n$$13 \\to 40 \\to 20 \\to 10 \\to 5 \\to 16 \\to 8 \\to 4 \\to 2 \\to 1.$$\n\nIt can be seen that this sequence (starting at $13$ and finishing at $1$) contains $10$ terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at $1$.\n\nWhich starting number, under one million, produces the longest chain?\n\nNOTE: Once the chain starts the terms are allowed to go above one million.", "raw_html": "

The following iterative sequence is defined for the set of positive integers:

\n\n

Using the rule above and starting with $13$, we generate the following sequence:\n$$13 \\to 40 \\to 20 \\to 10 \\to 5 \\to 16 \\to 8 \\to 4 \\to 2 \\to 1.$$

\n

It can be seen that this sequence (starting at $13$ and finishing at $1$) contains $10$ terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at $1$.

\n

Which starting number, under one million, produces the longest chain?

\n

NOTE: Once the chain starts the terms are allowed to go above one million.

", "url": "https://projecteuler.net/problem=14", "answer": "837799"} {"id": 15, "problem": "Starting in the top left corner of a $2 \\times 2$ grid, and only being able to move to the right and down, there are exactly $6$ routes to the bottom right corner.\n\nHow many such routes are there through a $20 \\times 20$ grid?", "raw_html": "

Starting in the top left corner of a $2 \\times 2$ grid, and only being able to move to the right and down, there are exactly $6$ routes to the bottom right corner.

\n
\n\"\"
\n

How many such routes are there through a $20 \\times 20$ grid?

", "url": "https://projecteuler.net/problem=15", "answer": "137846528820"} {"id": 16, "problem": "$2^{15} = 32768$ and the sum of its digits is $3 + 2 + 7 + 6 + 8 = 26$.\n\nWhat is the sum of the digits of the number $2^{1000}$?", "raw_html": "

$2^{15} = 32768$ and the sum of its digits is $3 + 2 + 7 + 6 + 8 = 26$.

\n

What is the sum of the digits of the number $2^{1000}$?

", "url": "https://projecteuler.net/problem=16", "answer": "1366"} {"id": 17, "problem": "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.\n\nIf all the numbers from $1$ to $1000$ (one thousand) inclusive were written out in words, how many letters would be used?\n\nNOTE: Do not count spaces or hyphens. For example, $342$ (three hundred and forty-two) contains $23$ letters and $115$ (one hundred and fifteen) contains $20$ letters. The use of \"and\" when writing out numbers is in compliance with British usage.", "raw_html": "

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.

\n

If all the numbers from $1$ to $1000$ (one thousand) inclusive were written out in words, how many letters would be used?

\n

NOTE: Do not count spaces or hyphens. For example, $342$ (three hundred and forty-two) contains $23$ letters and $115$ (one hundred and fifteen) contains $20$ letters. The use of \"and\" when writing out numbers is in compliance with British usage.

", "url": "https://projecteuler.net/problem=17", "answer": "21124"} {"id": 18, "problem": "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$.\n\n3\n7 4\n\n2 4 6\n\n8 5 9 3\n\nThat is, $3 + 7 + 4 + 9 = 23$.\n\nFind the maximum total from top to bottom of the triangle below:\n\n75\n\n95 64\n\n17 47 82\n\n18 35 87 10\n\n20 04 82 47 65\n\n19 01 23 75 03 34\n\n88 02 77 73 07 63 67\n\n99 65 04 28 06 16 70 92\n\n41 41 26 56 83 40 80 70 33\n\n41 48 72 33 47 32 37 16 94 29\n\n53 71 44 65 25 43 91 52 97 51 14\n\n70 11 33 28 77 73 17 78 39 68 17 57\n\n91 71 52 38 17 14 91 43 58 50 27 29 48\n\n63 66 04 68 89 53 67 30 73 16 69 87 40 31\n\n04 62 98 27 23 09 70 98 73 93 38 53 60 04 23\n\nNOTE: As there are only $16384$ routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o)", "raw_html": "

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$.

\n

3
7 4
\n2 4 6
\n8 5 9 3

\n

That is, $3 + 7 + 4 + 9 = 23$.

\n

Find the maximum total from top to bottom of the triangle below:

\n

75
\n95 64
\n17 47 82
\n18 35 87 10
\n20 04 82 47 65
\n19 01 23 75 03 34
\n88 02 77 73 07 63 67
\n99 65 04 28 06 16 70 92
\n41 41 26 56 83 40 80 70 33
\n41 48 72 33 47 32 37 16 94 29
\n53 71 44 65 25 43 91 52 97 51 14
\n70 11 33 28 77 73 17 78 39 68 17 57
\n91 71 52 38 17 14 91 43 58 50 27 29 48
\n63 66 04 68 89 53 67 30 73 16 69 87 40 31
\n04 62 98 27 23 09 70 98 73 93 38 53 60 04 23

\n

NOTE: As there are only $16384$ routes, it is possible to solve this problem by trying every route. However, Problem 67, is the same challenge with a triangle containing one-hundred rows; it cannot be solved by brute force, and requires a clever method! ;o)

", "url": "https://projecteuler.net/problem=18", "answer": "1074"} {"id": 19, "problem": "You are given the following information, but you may prefer to do some research for yourself.\n\n- 1 Jan 1900 was a Monday.\n\n- Thirty days has September,\n\nApril, June and November.\n\nAll the rest have thirty-one,\n\nSaving February alone,\n\nWhich has twenty-eight, rain or shine.\n\nAnd on leap years, twenty-nine.\n\n- A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.\n\nHow many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?", "raw_html": "

You are given the following information, but you may prefer to do some research for yourself.

\n

How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?

", "url": "https://projecteuler.net/problem=19", "answer": "171"} {"id": 20, "problem": "$n!$ means $n \\times (n - 1) \\times \\cdots \\times 3 \\times 2 \\times 1$.\n\nFor example, $10! = 10 \\times 9 \\times \\cdots \\times 3 \\times 2 \\times 1 = 3628800$,\nand the sum of the digits in the number $10!$ is $3 + 6 + 2 + 8 + 8 + 0 + 0 = 27$.\n\nFind the sum of the digits in the number $100!$.", "raw_html": "

$n!$ means $n \\times (n - 1) \\times \\cdots \\times 3 \\times 2 \\times 1$.

\n

For example, $10! = 10 \\times 9 \\times \\cdots \\times 3 \\times 2 \\times 1 = 3628800$,
and the sum of the digits in the number $10!$ is $3 + 6 + 2 + 8 + 8 + 0 + 0 = 27$.

\n

Find the sum of the digits in the number $100!$.

", "url": "https://projecteuler.net/problem=20", "answer": "648"} {"id": 21, "problem": "Let $d(n)$ be defined as the sum of proper divisors of $n$ (numbers less than $n$ which divide evenly into $n$).\n\nIf $d(a) = b$ and $d(b) = a$, where $a \\ne b$, then $a$ and $b$ are an amicable pair and each of $a$ and $b$ are called amicable numbers.\n\nFor example, the proper divisors of $220$ are $1, 2, 4, 5, 10, 11, 20, 22, 44, 55$ and $110$; therefore $d(220) = 284$. The proper divisors of $284$ are $1, 2, 4, 71$ and $142$; so $d(284) = 220$.\n\nEvaluate the sum of all the amicable numbers under $10000$.", "raw_html": "

Let $d(n)$ be defined as the sum of proper divisors of $n$ (numbers less than $n$ which divide evenly into $n$).
\nIf $d(a) = b$ and $d(b) = a$, where $a \\ne b$, then $a$ and $b$ are an amicable pair and each of $a$ and $b$ are called amicable numbers.

\n

For example, the proper divisors of $220$ are $1, 2, 4, 5, 10, 11, 20, 22, 44, 55$ and $110$; therefore $d(220) = 284$. The proper divisors of $284$ are $1, 2, 4, 71$ and $142$; so $d(284) = 220$.

\n

Evaluate the sum of all the amicable numbers under $10000$.

", "url": "https://projecteuler.net/problem=21", "answer": "31626"} {"id": 22, "problem": "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 value by its alphabetical position in the list to obtain a name score.\n\nFor example, when the list is sorted into alphabetical order, COLIN, which is worth $3 + 15 + 12 + 9 + 14 = 53$, is the $938$th name in the list. So, COLIN would obtain a score of $938 \\times 53 = 49714$.\n\nWhat is the total of all the name scores in the file?", "raw_html": "

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 value by its alphabetical position in the list to obtain a name score.

\n

For example, when the list is sorted into alphabetical order, COLIN, which is worth $3 + 15 + 12 + 9 + 14 = 53$, is the $938$th name in the list. So, COLIN would obtain a score of $938 \\times 53 = 49714$.

\n

What is the total of all the name scores in the file?

", "url": "https://projecteuler.net/problem=22", "answer": "871198282"} {"id": 23, "problem": "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.\n\nA number $n$ is called deficient if the sum of its proper divisors is less than $n$ and it is called abundant if this sum exceeds $n$.\n\nAs $12$ is the smallest abundant number, $1 + 2 + 3 + 4 + 6 = 16$, the smallest number that can be written as the sum of two abundant numbers is $24$. By mathematical analysis, it can be shown that all integers greater than $28123$ can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.\n\nFind the sum of all the positive integers which cannot be written as the sum of two abundant numbers.", "raw_html": "

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.

\n

A number $n$ is called deficient if the sum of its proper divisors is less than $n$ and it is called abundant if this sum exceeds $n$.

\n\n

As $12$ is the smallest abundant number, $1 + 2 + 3 + 4 + 6 = 16$, the smallest number that can be written as the sum of two abundant numbers is $24$. By mathematical analysis, it can be shown that all integers greater than $28123$ can be written as the sum of two abundant numbers. However, this upper limit cannot be reduced any further by analysis even though it is known that the greatest number that cannot be expressed as the sum of two abundant numbers is less than this limit.

\n

Find the sum of all the positive integers which cannot be written as the sum of two abundant numbers.

", "url": "https://projecteuler.net/problem=23", "answer": "4179871"} {"id": 24, "problem": "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 lexicographic permutations of 0, 1 and 2 are:\n\n012   021   102   120   201   210\n\nWhat is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?", "raw_html": "

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 lexicographic permutations of 0, 1 and 2 are:

\n

012   021   102   120   201   210

\n

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

", "url": "https://projecteuler.net/problem=24", "answer": "2783915460"} {"id": 25, "problem": "The Fibonacci sequence is defined by the recurrence relation:\n\n$F_n = F_{n - 1} + F_{n - 2}$, where $F_1 = 1$ and $F_2 = 1$.\nHence the first $12$ terms will be:\n\n$$\\begin{align}\nF_1 &= 1\\\\\nF_2 &= 1\\\\\nF_3 &= 2\\\\\nF_4 &= 3\\\\\nF_5 &= 5\\\\\nF_6 &= 8\\\\\nF_7 &= 13\\\\\nF_8 &= 21\\\\\nF_9 &= 34\\\\\nF_{10} &= 55\\\\\nF_{11} &= 89\\\\\nF_{12} &= 144\n\\end{align}$$\nThe $12$th term, $F_{12}$, is the first term to contain three digits.\n\nWhat is the index of the first term in the Fibonacci sequence to contain $1000$ digits?", "raw_html": "

The Fibonacci sequence is defined by the recurrence relation:

\n
$F_n = F_{n - 1} + F_{n - 2}$, where $F_1 = 1$ and $F_2 = 1$.
\n

Hence the first $12$ terms will be:

\n$$\\begin{align}\nF_1 &= 1\\\\\nF_2 &= 1\\\\\nF_3 &= 2\\\\\nF_4 &= 3\\\\\nF_5 &= 5\\\\\nF_6 &= 8\\\\\nF_7 &= 13\\\\\nF_8 &= 21\\\\\nF_9 &= 34\\\\\nF_{10} &= 55\\\\\nF_{11} &= 89\\\\\nF_{12} &= 144\n\\end{align}$$\n

The $12$th term, $F_{12}$, is the first term to contain three digits.

\n

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

", "url": "https://projecteuler.net/problem=25", "answer": "4782"} {"id": 26, "problem": "A unit fraction contains $1$ in the numerator. The decimal representation of the unit fractions with denominators $2$ to $10$ are given:\n\n$$\\begin{align}\n1/2 &= 0.5\\\\\n1/3 &=0.(3)\\\\\n1/4 &=0.25\\\\\n1/5 &= 0.2\\\\\n1/6 &= 0.1(6)\\\\\n1/7 &= 0.(142857)\\\\\n1/8 &= 0.125\\\\\n1/9 &= 0.(1)\\\\\n1/10 &= 0.1\n\\end{align}$$\nWhere $0.1(6)$ means $0.166666\\cdots$, and has a $1$-digit recurring cycle. It can be seen that $1/7$ has a $6$-digit recurring cycle.\n\nFind the value of $d \\lt 1000$ for which $1/d$ contains the longest recurring cycle in its decimal fraction part.", "raw_html": "

A unit fraction contains $1$ in the numerator. The decimal representation of the unit fractions with denominators $2$ to $10$ are given:

\n$$\\begin{align}\n1/2 &= 0.5\\\\\n1/3 &=0.(3)\\\\\n1/4 &=0.25\\\\\n1/5 &= 0.2\\\\\n1/6 &= 0.1(6)\\\\\n1/7 &= 0.(142857)\\\\\n1/8 &= 0.125\\\\\n1/9 &= 0.(1)\\\\\n1/10 &= 0.1\n\\end{align}$$\n

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

\n

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

", "url": "https://projecteuler.net/problem=26", "answer": "983"} {"id": 27, "problem": "Euler discovered the remarkable quadratic formula:\n\n$n^2 + n + 41$\n\nIt turns out that the formula will produce $40$ primes for the consecutive integer values $0 \\le n \\le 39$. However, when $n = 40, 40^2 + 40 + 41 = 40(40 + 1) + 41$ is divisible by $41$, and certainly when $n = 41, 41^2 + 41 + 41$ is clearly divisible by $41$.\n\nThe incredible formula $n^2 - 79n + 1601$ was discovered, which produces $80$ primes for the consecutive values $0 \\le n \\le 79$. The product of the coefficients, $-79$ and $1601$, is $-126479$.\n\nConsidering quadratics of the form:\n\n$n^2 + an + b$, where $|a| < 1000$ and $|b| \\le 1000$\n\nwhere $|n|$ is the modulus/absolute value of $n$\ne.g. $|11| = 11$ and $|-4| = 4$\n\nFind 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$.", "raw_html": "

Euler discovered the remarkable quadratic formula:

\n

$n^2 + n + 41$

\n

It turns out that the formula will produce $40$ primes for the consecutive integer values $0 \\le n \\le 39$. However, when $n = 40, 40^2 + 40 + 41 = 40(40 + 1) + 41$ is divisible by $41$, and certainly when $n = 41, 41^2 + 41 + 41$ is clearly divisible by $41$.

\n

The incredible formula $n^2 - 79n + 1601$ was discovered, which produces $80$ primes for the consecutive values $0 \\le n \\le 79$. The product of the coefficients, $-79$ and $1601$, is $-126479$.

\n

Considering quadratics of the form:

\n
\n$n^2 + an + b$, where $|a| < 1000$ and $|b| \\le 1000$

where $|n|$ is the modulus/absolute value of $n$
e.g. $|11| = 11$ and $|-4| = 4$
\n
\n

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$.

", "url": "https://projecteuler.net/problem=27", "answer": "-59231"} {"id": 28, "problem": "Starting with the number $1$ and moving to the right in a clockwise direction a $5$ by $5$ spiral is formed as follows:\n\n21 22 23 24 25\n\n20  7  8  9 10\n\n19  6  1  2 11\n\n18  5  4  3 12\n17 16 15 14 13\n\nIt can be verified that the sum of the numbers on the diagonals is $101$.\n\nWhat is the sum of the numbers on the diagonals in a $1001$ by $1001$ spiral formed in the same way?", "raw_html": "

Starting with the number $1$ and moving to the right in a clockwise direction a $5$ by $5$ spiral is formed as follows:

\n

21 22 23 24 25
\n20  7  8  9 10
\n19  6  1  2 11
\n18  5  4  3 12
17 16 15 14 13

\n

It can be verified that the sum of the numbers on the diagonals is $101$.

\n

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

", "url": "https://projecteuler.net/problem=28", "answer": "669171001"} {"id": 29, "problem": "Consider all integer combinations of $a^b$ for $2 \\le a \\le 5$ and $2 \\le b \\le 5$:\n$$\\begin{array}{rrrr}\n2^2=4, &2^3=8, &2^4=16, &2^5=32\\\\\n3^2=9, &3^3=27, &3^4=81, &3^5=243\\\\\n4^2=16, &4^3=64, &4^4=256, &4^5=1024\\\\\n5^2=25, &5^3=125, &5^4=625, &5^5=3125\n\\end{array}$$\n\nIf they are then placed in numerical order, with any repeats removed, we get the following sequence of $15$ distinct terms:\n$$4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125.$$\n\nHow many distinct terms are in the sequence generated by $a^b$ for $2 \\le a \\le 100$ and $2 \\le b \\le 100$?", "raw_html": "

Consider all integer combinations of $a^b$ for $2 \\le a \\le 5$ and $2 \\le b \\le 5$:\n$$\\begin{array}{rrrr}\n2^2=4, &2^3=8, &2^4=16, &2^5=32\\\\\n3^2=9, &3^3=27, &3^4=81, &3^5=243\\\\\n4^2=16, &4^3=64, &4^4=256, &4^5=1024\\\\\n5^2=25, &5^3=125, &5^4=625, &5^5=3125\n\\end{array}$$

\n

If they are then placed in numerical order, with any repeats removed, we get the following sequence of $15$ distinct terms:\n$$4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125.$$

\n

How many distinct terms are in the sequence generated by $a^b$ for $2 \\le a \\le 100$ and $2 \\le b \\le 100$?

", "url": "https://projecteuler.net/problem=29", "answer": "9183"} {"id": 30, "problem": "Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:\n$$\\begin{align}\n1634 &= 1^4 + 6^4 + 3^4 + 4^4\\\\\n8208 &= 8^4 + 2^4 + 0^4 + 8^4\\\\\n9474 &= 9^4 + 4^4 + 7^4 + 4^4\n\\end{align}$$\n\nAs $1 = 1^4$ is not a sum it is not included.\n\nThe sum of these numbers is $1634 + 8208 + 9474 = 19316$.\n\nFind the sum of all the numbers that can be written as the sum of fifth powers of their digits.", "raw_html": "

Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:\n$$\\begin{align}\n1634 &= 1^4 + 6^4 + 3^4 + 4^4\\\\\n8208 &= 8^4 + 2^4 + 0^4 + 8^4\\\\\n9474 &= 9^4 + 4^4 + 7^4 + 4^4\n\\end{align}$$\n

As $1 = 1^4$ is not a sum it is not included.

\n

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

\n

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

", "url": "https://projecteuler.net/problem=30", "answer": "443839"} {"id": 31, "problem": "In the United Kingdom the currency is made up of pound (£) and pence (p). There are eight coins in general circulation:\n\n1p, 2p, 5p, 10p, 20p, 50p, £1 (100p), and £2 (200p).\nIt is possible to make £2 in the following way:\n\n1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p\nHow many different ways can £2 be made using any number of coins?", "raw_html": "

In the United Kingdom the currency is made up of pound (£) and pence (p). There are eight coins in general circulation:

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

It is possible to make £2 in the following way:

\n
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
\n

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

", "url": "https://projecteuler.net/problem=31", "answer": "73682"} {"id": 32, "problem": "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.\n\nThe product $7254$ is unusual, as the identity, $39 \\times 186 = 7254$, containing multiplicand, multiplier, and product is $1$ through $9$ pandigital.\n\nFind the sum of all products whose multiplicand/multiplier/product identity can be written as a $1$ through $9$ pandigital.\n\nHINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.", "raw_html": "

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.

\n\n

The product $7254$ is unusual, as the identity, $39 \\times 186 = 7254$, containing multiplicand, multiplier, and product is $1$ through $9$ pandigital.

\n\n

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a $1$ through $9$ pandigital.

\n\n
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
", "url": "https://projecteuler.net/problem=32", "answer": "45228"} {"id": 33, "problem": "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 $9$s.\n\nWe shall consider fractions like, $30/50 = 3/5$, to be trivial examples.\n\nThere 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.\n\nIf the product of these four fractions is given in its lowest common terms, find the value of the denominator.", "raw_html": "

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 $9$s.

\n

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

\n

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.

\n

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

", "url": "https://projecteuler.net/problem=33", "answer": "100"} {"id": 34, "problem": "$145$ is a curious number, as $1! + 4! + 5! = 1 + 24 + 120 = 145$.\n\nFind the sum of all numbers which are equal to the sum of the factorial of their digits.\n\nNote: As $1! = 1$ and $2! = 2$ are not sums they are not included.", "raw_html": "

$145$ is a curious number, as $1! + 4! + 5! = 1 + 24 + 120 = 145$.

\n

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

\n

Note: As $1! = 1$ and $2! = 2$ are not sums they are not included.

", "url": "https://projecteuler.net/problem=34", "answer": "40730"} {"id": 35, "problem": "The number, $197$, is called a circular prime because all rotations of the digits: $197$, $971$, and $719$, are themselves prime.\n\nThere are thirteen such primes below $100$: $2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79$, and $97$.\n\nHow many circular primes are there below one million?", "raw_html": "

The number, $197$, is called a circular prime because all rotations of the digits: $197$, $971$, and $719$, are themselves prime.

\n

There are thirteen such primes below $100$: $2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79$, and $97$.

\n

How many circular primes are there below one million?

", "url": "https://projecteuler.net/problem=35", "answer": "55"} {"id": 36, "problem": "The decimal number, $585 = 1001001001_2$ (binary), is palindromic in both bases.\n\nFind the sum of all numbers, less than one million, which are palindromic in base $10$ and base $2$.\n\n(Please note that the palindromic number, in either base, may not include leading zeros.)", "raw_html": "

The decimal number, $585 = 1001001001_2$ (binary), is palindromic in both bases.

\n

Find the sum of all numbers, less than one million, which are palindromic in base $10$ and base $2$.

\n

(Please note that the palindromic number, in either base, may not include leading zeros.)

", "url": "https://projecteuler.net/problem=36", "answer": "872187"} {"id": 37, "problem": "The number $3797$ has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: $3797$, $797$, $97$, and $7$. Similarly we can work from right to left: $3797$, $379$, $37$, and $3$.\n\nFind the sum of the only eleven primes that are both truncatable from left to right and right to left.\n\nNOTE: $2$, $3$, $5$, and $7$ are not considered to be truncatable primes.", "raw_html": "

The number $3797$ has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: $3797$, $797$, $97$, and $7$. Similarly we can work from right to left: $3797$, $379$, $37$, and $3$.

\n

Find the sum of the only eleven primes that are both truncatable from left to right and right to left.

\n

NOTE: $2$, $3$, $5$, and $7$ are not considered to be truncatable primes.

", "url": "https://projecteuler.net/problem=37", "answer": "748317"} {"id": 38, "problem": "Take the number $192$ and multiply it by each of $1$, $2$, and $3$:\n\n$$\\begin{align}\n192 \\times 1 &= 192\\\\\n192 \\times 2 &= 384\\\\\n192 \\times 3 &= 576\n\\end{align}$$\nBy concatenating each product we get the $1$ to $9$ pandigital, $192384576$. We will call $192384576$ the concatenated product of $192$ and $(1,2,3)$.\n\nThe same can be achieved by starting with $9$ and multiplying by $1$, $2$, $3$, $4$, and $5$, giving the pandigital, $918273645$, which is the concatenated product of $9$ and $(1,2,3,4,5)$.\n\nWhat is the largest $1$ to $9$ pandigital $9$-digit number that can be formed as the concatenated product of an integer with $(1,2, \\dots, n)$ where $n \\gt 1$?", "raw_html": "

Take the number $192$ and multiply it by each of $1$, $2$, and $3$:

\n$$\\begin{align}\n192 \\times 1 &= 192\\\\\n192 \\times 2 &= 384\\\\\n192 \\times 3 &= 576\n\\end{align}$$\n

By concatenating each product we get the $1$ to $9$ pandigital, $192384576$. We will call $192384576$ the concatenated product of $192$ and $(1,2,3)$.

\n

The same can be achieved by starting with $9$ and multiplying by $1$, $2$, $3$, $4$, and $5$, giving the pandigital, $918273645$, which is the concatenated product of $9$ and $(1,2,3,4,5)$.

\n

What is the largest $1$ to $9$ pandigital $9$-digit number that can be formed as the concatenated product of an integer with $(1,2, \\dots, n)$ where $n \\gt 1$?

", "url": "https://projecteuler.net/problem=38", "answer": "932718654"} {"id": 39, "problem": "If $p$ is the perimeter of a right angle triangle with integral length sides, $\\{a, b, c\\}$, there are exactly three solutions for $p = 120$.\n\n$\\{20,48,52\\}$, $\\{24,45,51\\}$, $\\{30,40,50\\}$\n\nFor which value of $p \\le 1000$, is the number of solutions maximised?", "raw_html": "

If $p$ is the perimeter of a right angle triangle with integral length sides, $\\{a, b, c\\}$, there are exactly three solutions for $p = 120$.

\n

$\\{20,48,52\\}$, $\\{24,45,51\\}$, $\\{30,40,50\\}$

\n

For which value of $p \\le 1000$, is the number of solutions maximised?

", "url": "https://projecteuler.net/problem=39", "answer": "840"} {"id": 40, "problem": "An irrational decimal fraction is created by concatenating the positive integers:\n$$0.12345678910{\\color{red}\\mathbf 1}112131415161718192021\\cdots$$\n\nIt can be seen that the $12$th digit of the fractional part is $1$.\n\nIf $d_n$ represents the $n$th digit of the fractional part, find the value of the following expression.\n$$d_1 \\times d_{10} \\times d_{100} \\times d_{1000} \\times d_{10000} \\times d_{100000} \\times d_{1000000}$$", "raw_html": "

An irrational decimal fraction is created by concatenating the positive integers:\n$$0.12345678910{\\color{red}\\mathbf 1}112131415161718192021\\cdots$$

\n

It can be seen that the $12$th digit of the fractional part is $1$.

\n

If $d_n$ represents the $n$th digit of the fractional part, find the value of the following expression.\n$$d_1 \\times d_{10} \\times d_{100} \\times d_{1000} \\times d_{10000} \\times d_{100000} \\times d_{1000000}$$

", "url": "https://projecteuler.net/problem=40", "answer": "210"} {"id": 41, "problem": "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, $2143$ is a $4$-digit pandigital and is also prime.\n\nWhat is the largest $n$-digit pandigital prime that exists?", "raw_html": "

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, $2143$ is a $4$-digit pandigital and is also prime.

\n

What is the largest $n$-digit pandigital prime that exists?

", "url": "https://projecteuler.net/problem=41", "answer": "7652413"} {"id": 42, "problem": "The $n$th term of the sequence of triangle numbers is given by, $t_n = \\frac12n(n+1)$; so the first ten triangle numbers are:\n$$1, 3, 6, 10, 15, 21, 28, 36, 45, 55, \\dots$$\n\nBy converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is $19 + 11 + 25 = 55 = t_{10}$. If the word value is a triangle number then we shall call the word a triangle word.\n\nUsing words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?", "raw_html": "

The $n$th term of the sequence of triangle numbers is given by, $t_n = \\frac12n(n+1)$; so the first ten triangle numbers are:\n$$1, 3, 6, 10, 15, 21, 28, 36, 45, 55, \\dots$$

\n

By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is $19 + 11 + 25 = 55 = t_{10}$. If the word value is a triangle number then we shall call the word a triangle word.

\n

Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?

", "url": "https://projecteuler.net/problem=42", "answer": "162"} {"id": 43, "problem": "The number, $1406357289$, is a $0$ to $9$ pandigital number because it is made up of each of the digits $0$ to $9$ in some order, but it also has a rather interesting sub-string divisibility property.\n\nLet $d_1$ be the $1$st digit, $d_2$ be the $2$nd digit, and so on. In this way, we note the following:\n\n- $d_2d_3d_4=406$ is divisible by $2$\n\n- $d_3d_4d_5=063$ is divisible by $3$\n\n- $d_4d_5d_6=635$ is divisible by $5$\n\n- $d_5d_6d_7=357$ is divisible by $7$\n\n- $d_6d_7d_8=572$ is divisible by $11$\n\n- $d_7d_8d_9=728$ is divisible by $13$\n\n- $d_8d_9d_{10}=289$ is divisible by $17$\n\nFind the sum of all $0$ to $9$ pandigital numbers with this property.", "raw_html": "

The number, $1406357289$, is a $0$ to $9$ pandigital number because it is made up of each of the digits $0$ to $9$ in some order, but it also has a rather interesting sub-string divisibility property.

\n

Let $d_1$ be the $1$st digit, $d_2$ be the $2$nd digit, and so on. In this way, we note the following:

\n

Find the sum of all $0$ to $9$ pandigital numbers with this property.

", "url": "https://projecteuler.net/problem=43", "answer": "16695334890"} {"id": 44, "problem": "Pentagonal numbers are generated by the formula, $P_n=n(3n-1)/2$. The first ten pentagonal numbers are:\n$$1, 5, 12, 22, 35, 51, 70, 92, 117, 145, \\dots$$\n\nIt can be seen that $P_4 + P_7 = 22 + 70 = 92 = P_8$. However, their difference, $70 - 22 = 48$, is not pentagonal.\n\nFind the pair of pentagonal numbers, $P_j$ and $P_k$, for which their sum and difference are pentagonal and $D = |P_k - P_j|$ is minimised; what is the value of $D$?", "raw_html": "

Pentagonal numbers are generated by the formula, $P_n=n(3n-1)/2$. The first ten pentagonal numbers are:\n$$1, 5, 12, 22, 35, 51, 70, 92, 117, 145, \\dots$$

\n

It can be seen that $P_4 + P_7 = 22 + 70 = 92 = P_8$. However, their difference, $70 - 22 = 48$, is not pentagonal.

\n

Find the pair of pentagonal numbers, $P_j$ and $P_k$, for which their sum and difference are pentagonal and $D = |P_k - P_j|$ is minimised; what is the value of $D$?

", "url": "https://projecteuler.net/problem=44", "answer": "5482660"} {"id": 45, "problem": "Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:\n\n| Triangle | | $T_n=n(n+1)/2$ | | $1, 3, 6, 10, 15, \\dots$ |\n| Pentagonal | | $P_n=n(3n - 1)/2$ | | $1, 5, 12, 22, 35, \\dots$ |\n| Hexagonal | | $H_n=n(2n - 1)$ | | $1, 6, 15, 28, 45, \\dots$ |\n\nIt can be verified that $T_{285} = P_{165} = H_{143} = 40755$.\n\nFind the next triangle number that is also pentagonal and hexagonal.", "raw_html": "

Triangle, pentagonal, and hexagonal numbers are generated by the following formulae:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Triangle $T_n=n(n+1)/2$ $1, 3, 6, 10, 15, \\dots$
Pentagonal $P_n=n(3n - 1)/2$ $1, 5, 12, 22, 35, \\dots$
Hexagonal $H_n=n(2n - 1)$ $1, 6, 15, 28, 45, \\dots$

It can be verified that $T_{285} = P_{165} = H_{143} = 40755$.

\n

Find the next triangle number that is also pentagonal and hexagonal.

", "url": "https://projecteuler.net/problem=45", "answer": "1533776805"} {"id": 46, "problem": "It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.\n\n$$\\begin{align}\n9 = 7 + 2 \\times 1^2\\\\\n15 = 7 + 2 \\times 2^2\\\\\n21 = 3 + 2 \\times 3^2\\\\\n25 = 7 + 2 \\times 3^2\\\\\n27 = 19 + 2 \\times 2^2\\\\\n33 = 31 + 2 \\times 1^2\n\\end{align}$$\nIt turns out that the conjecture was false.\n\nWhat is the smallest odd composite that cannot be written as the sum of a prime and twice a square?", "raw_html": "

It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square.

\n$$\\begin{align}\n9 = 7 + 2 \\times 1^2\\\\\n15 = 7 + 2 \\times 2^2\\\\\n21 = 3 + 2 \\times 3^2\\\\\n25 = 7 + 2 \\times 3^2\\\\\n27 = 19 + 2 \\times 2^2\\\\\n33 = 31 + 2 \\times 1^2\n\\end{align}$$\n

It turns out that the conjecture was false.

\n

What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

", "url": "https://projecteuler.net/problem=46", "answer": "5777"} {"id": 47, "problem": "The first two consecutive numbers to have two distinct prime factors are:\n\n$$\\begin{align}\n14 &= 2 \\times 7\\\\\n15 &= 3 \\times 5.\n\\end{align}$$\nThe first three consecutive numbers to have three distinct prime factors are:\n\n$$\\begin{align}\n644 &= 2^2 \\times 7 \\times 23\\\\\n645 &= 3 \\times 5 \\times 43\\\\\n646 &= 2 \\times 17 \\times 19.\n\\end{align}$$\nFind the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?", "raw_html": "

The first two consecutive numbers to have two distinct prime factors are:

\n$$\\begin{align}\n14 &= 2 \\times 7\\\\\n15 &= 3 \\times 5.\n\\end{align}$$\n

The first three consecutive numbers to have three distinct prime factors are:

\n$$\\begin{align}\n644 &= 2^2 \\times 7 \\times 23\\\\\n645 &= 3 \\times 5 \\times 43\\\\\n646 &= 2 \\times 17 \\times 19.\n\\end{align}$$\n

Find the first four consecutive integers to have four distinct prime factors each. What is the first of these numbers?

", "url": "https://projecteuler.net/problem=47", "answer": "134043"} {"id": 48, "problem": "The series, $1^1 + 2^2 + 3^3 + \\cdots + 10^{10} = 10405071317$.\n\nFind the last ten digits of the series, $1^1 + 2^2 + 3^3 + \\cdots + 1000^{1000}$.", "raw_html": "

The series, $1^1 + 2^2 + 3^3 + \\cdots + 10^{10} = 10405071317$.

\n

Find the last ten digits of the series, $1^1 + 2^2 + 3^3 + \\cdots + 1000^{1000}$.

", "url": "https://projecteuler.net/problem=48", "answer": "9110846700"} {"id": 49, "problem": "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.\n\nThere 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.\n\nWhat $12$-digit number do you form by concatenating the three terms in this sequence?", "raw_html": "

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.

\n

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.

\n

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

", "url": "https://projecteuler.net/problem=49", "answer": "296962999629"} {"id": 50, "problem": "The prime $41$, can be written as the sum of six consecutive primes:\n\n$$41 = 2 + 3 + 5 + 7 + 11 + 13.$$\nThis is the longest sum of consecutive primes that adds to a prime below one-hundred.\n\nThe longest sum of consecutive primes below one-thousand that adds to a prime, contains $21$ terms, and is equal to $953$.\n\nWhich prime, below one-million, can be written as the sum of the most consecutive primes?", "raw_html": "

The prime $41$, can be written as the sum of six consecutive primes:

\n$$41 = 2 + 3 + 5 + 7 + 11 + 13.$$\n

This is the longest sum of consecutive primes that adds to a prime below one-hundred.

\n

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

\n

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

", "url": "https://projecteuler.net/problem=50", "answer": "997651"} {"id": 51, "problem": "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.\n\nBy 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.\n\nFind 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.", "raw_html": "

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.

\n

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.

\n

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.

", "url": "https://projecteuler.net/problem=51", "answer": "121313"} {"id": 52, "problem": "It can be seen that the number, $125874$, and its double, $251748$, contain exactly the same digits, but in a different order.\n\nFind the smallest positive integer, $x$, such that $2x$, $3x$, $4x$, $5x$, and $6x$, contain the same digits.", "raw_html": "

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

\n

Find the smallest positive integer, $x$, such that $2x$, $3x$, $4x$, $5x$, and $6x$, contain the same digits.

", "url": "https://projecteuler.net/problem=52", "answer": "142857"} {"id": 53, "problem": "There are exactly ten ways of selecting three from five, 12345:\n\n123, 124, 125, 134, 135, 145, 234, 235, 245, and 345\n\nIn combinatorics, we use the notation, $\\displaystyle \\binom 5 3 = 10$.\n\nIn general, $\\displaystyle \\binom n r = \\dfrac{n!}{r!(n-r)!}$, where $r \\le n$, $n! = n \\times (n-1) \\times ... \\times 3 \\times 2 \\times 1$, and $0! = 1$.\n\nIt is not until $n = 23$, that a value exceeds one-million: $\\displaystyle \\binom {23} {10} = 1144066$.\n\nHow many, not necessarily distinct, values of $\\displaystyle \\binom n r$ for $1 \\le n \\le 100$, are greater than one-million?", "raw_html": "

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

\n

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

\n

In combinatorics, we use the notation, $\\displaystyle \\binom 5 3 = 10$.

\n

In general, $\\displaystyle \\binom n r = \\dfrac{n!}{r!(n-r)!}$, where $r \\le n$, $n! = n \\times (n-1) \\times ... \\times 3 \\times 2 \\times 1$, and $0! = 1$.\n

\n

It is not until $n = 23$, that a value exceeds one-million: $\\displaystyle \\binom {23} {10} = 1144066$.

\n

How many, not necessarily distinct, values of $\\displaystyle \\binom n r$ for $1 \\le n \\le 100$, are greater than one-million?

", "url": "https://projecteuler.net/problem=53", "answer": "4075"} {"id": 54, "problem": "In the card game poker, a hand consists of five cards and are ranked, from lowest to highest, in the following way:\n\n- High Card: Highest value card.\n\n- One Pair: Two cards of the same value.\n\n- Two Pairs: Two different pairs.\n\n- Three of a Kind: Three cards of the same value.\n\n- Straight: All cards are consecutive values.\n\n- Flush: All cards of the same suit.\n\n- Full House: Three of a kind and a pair.\n\n- Four of a Kind: Four cards of the same value.\n\n- Straight Flush: All cards are consecutive values of same suit.\n\n- Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.\n\nThe cards are valued in the order:\n2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.\n\nIf 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.\n\nConsider the following five hands dealt to two players:\n\n| Hand | | Player 1 | | Player 2 | | Winner |\n| 1 | | 5H 5C 6S 7S KDPair of Fives | | 2C 3S 8S 8D TDPair of Eights | | Player 2 |\n| 2 | | 5D 8C 9S JS ACHighest card Ace | | 2C 5C 7D 8S QHHighest card Queen | | Player 1 |\n| 3 | | 2D 9C AS AH ACThree Aces | | 3D 6D 7D TD QDFlush with Diamonds | | Player 2 |\n| 4 | | 4D 6S 9H QH QCPair of QueensHighest card Nine | | 3D 6D 7H QD QSPair of QueensHighest card Seven | | Player 1 |\n| 5 | | 2H 2D 4C 4D 4SFull HouseWith Three Fours | | 3C 3D 3S 9S 9DFull Housewith Three Threes | | Player 1 |\n\nThe 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.\n\nHow many hands does Player 1 win?", "raw_html": "

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

\n

The cards are valued in the order:
2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.

\n

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.

\n

Consider the following five hands dealt to two players:

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

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.

\n

How many hands does Player 1 win?

", "url": "https://projecteuler.net/problem=54", "answer": "376"} {"id": 55, "problem": "If we take $47$, reverse and add, $47 + 74 = 121$, which is palindromic.\n\nNot all numbers produce palindromes so quickly. For example,\n\n$$\\begin{align}\n349 + 943 &= 1292\\\\\n1292 + 2921 &= 4213\\\\\n4213 + 3124 &= 7337\n\\end{align}$$\nThat is, $349$ took three iterations to arrive at a palindrome.\n\nAlthough 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).\n\nSurprisingly, there are palindromic numbers that are themselves Lychrel numbers; the first example is $4994$.\n\nHow many Lychrel numbers are there below ten-thousand?\n\nNOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers.", "raw_html": "

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

\n

Not all numbers produce palindromes so quickly. For example,

\n$$\\begin{align}\n349 + 943 &= 1292\\\\\n1292 + 2921 &= 4213\\\\\n4213 + 3124 &= 7337\n\\end{align}$$\n

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

\n

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).

\n

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

\n

How many Lychrel numbers are there below ten-thousand?

\n

NOTE: Wording was modified slightly on 24 April 2007 to emphasise the theoretical nature of Lychrel numbers.

", "url": "https://projecteuler.net/problem=55", "answer": "249"} {"id": 56, "problem": "A googol ($10^{100}$) is a massive number: one followed by one-hundred zeros; $100^{100}$ is almost unimaginably large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only $1$.\n\nConsidering natural numbers of the form, $a^b$, where $a, b \\lt 100$, what is the maximum digital sum?", "raw_html": "

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

\n

Considering natural numbers of the form, $a^b$, where $a, b \\lt 100$, what is the maximum digital sum?

", "url": "https://projecteuler.net/problem=56", "answer": "972"} {"id": 57, "problem": "It is possible to show that the square root of two can be expressed as an infinite continued fraction.\n\n$\\sqrt 2 =1+ \\frac 1 {2+ \\frac 1 {2 +\\frac 1 {2+ \\dots}}}$\n\nBy expanding this for the first four iterations, we get:\n\n$1 + \\frac 1 2 = \\frac 32 = 1.5$\n\n$1 + \\frac 1 {2 + \\frac 1 2} = \\frac 7 5 = 1.4$\n\n$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 2}} = \\frac {17}{12} = 1.41666 \\dots$\n\n$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 {2+\\frac 1 2}}} = \\frac {41}{29} = 1.41379 \\dots$\n\nThe next three expansions are $\\frac {99}{70}$, $\\frac {239}{169}$, and $\\frac {577}{408}$, but the eighth expansion, $\\frac {1393}{985}$, is the first example where the number of digits in the numerator exceeds the number of digits in the denominator.\n\nIn the first one-thousand expansions, how many fractions contain a numerator with more digits than the denominator?", "raw_html": "

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

\n

$\\sqrt 2 =1+ \\frac 1 {2+ \\frac 1 {2 +\\frac 1 {2+ \\dots}}}$

\n

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

\n

$1 + \\frac 1 2 = \\frac 32 = 1.5$
\n$1 + \\frac 1 {2 + \\frac 1 2} = \\frac 7 5 = 1.4$
\n$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 2}} = \\frac {17}{12} = 1.41666 \\dots$
\n$1 + \\frac 1 {2 + \\frac 1 {2+\\frac 1 {2+\\frac 1 2}}} = \\frac {41}{29} = 1.41379 \\dots$

\n

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

\n

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

", "url": "https://projecteuler.net/problem=57", "answer": "153"} {"id": 58, "problem": "Starting with $1$ and spiralling anticlockwise in the following way, a square spiral with side length $7$ is formed.\n\n37 36 35 34 33 32 31\n\n38 17 16 15 14 13 30\n\n39 18  5  4  3 12 29\n\n40 19  6  1  2 11 28\n\n41 20  7  8  9 10 27\n\n42 21 22 23 24 25 26\n43 44 45 46 47 48 49\n\nIt is interesting to note that the odd squares lie along the bottom right diagonal, but what is more interesting is that $8$ out of the $13$ numbers lying along both diagonals are prime; that is, a ratio of $8/13 \\approx 62\\%$.\n\nIf one complete new layer is wrapped around the spiral above, a square spiral with side length $9$ will be formed. If this process is continued, what is the side length of the square spiral for which the ratio of primes along both diagonals first falls below $10\\%$?", "raw_html": "

Starting with $1$ and spiralling anticlockwise in the following way, a square spiral with side length $7$ is formed.

\n

37 36 35 34 33 32 31
\n38 17 16 15 14 13 30
\n39 18  5  4  3 12 29
\n40 19  6  1  2 11 28
\n41 20  7  8  9 10 27
\n42 21 22 23 24 25 26
43 44 45 46 47 48 49

\n

It is interesting to note that the odd squares lie along the bottom right diagonal, but what is more interesting is that $8$ out of the $13$ numbers lying along both diagonals are prime; that is, a ratio of $8/13 \\approx 62\\%$.

\n

If one complete new layer is wrapped around the spiral above, a square spiral with side length $9$ will be formed. If this process is continued, what is the side length of the square spiral for which the ratio of primes along both diagonals first falls below $10\\%$?

", "url": "https://projecteuler.net/problem=58", "answer": "26241"} {"id": 59, "problem": "Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107.\n\nA modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte with a given value, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.\n\nFor unbreakable encryption, the key is the same length as the plain text message, and the key is made up of random bytes. The user would keep the encrypted message and the encryption key in different locations, and without both \"halves\", it is impossible to decrypt the message.\n\nUnfortunately, this method is impractical for most users, so the modified method is to use a password as a key. If the password is shorter than the message, which is likely, the key is repeated cyclically throughout the message. The balance for this method is using a sufficiently long password key for security, but short enough to be memorable.\n\nYour task has been made easy, as the encryption key consists of three lower case characters. Using 0059_cipher.txt (right click and 'Save Link/Target As...'), a file containing the encrypted ASCII codes, and the knowledge that the plain text must contain common English words, decrypt the message and find the sum of the ASCII values in the original text.", "raw_html": "

Each character on a computer is assigned a unique code and the preferred standard is ASCII (American Standard Code for Information Interchange). For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107.

\n

A modern encryption method is to take a text file, convert the bytes to ASCII, then XOR each byte with a given value, taken from a secret key. The advantage with the XOR function is that using the same encryption key on the cipher text, restores the plain text; for example, 65 XOR 42 = 107, then 107 XOR 42 = 65.

\n

For unbreakable encryption, the key is the same length as the plain text message, and the key is made up of random bytes. The user would keep the encrypted message and the encryption key in different locations, and without both \"halves\", it is impossible to decrypt the message.

\n

Unfortunately, this method is impractical for most users, so the modified method is to use a password as a key. If the password is shorter than the message, which is likely, the key is repeated cyclically throughout the message. The balance for this method is using a sufficiently long password key for security, but short enough to be memorable.

\n

Your task has been made easy, as the encryption key consists of three lower case characters. Using 0059_cipher.txt (right click and 'Save Link/Target As...'), a file containing the encrypted ASCII codes, and the knowledge that the plain text must contain common English words, decrypt the message and find the sum of the ASCII values in the original text.

", "url": "https://projecteuler.net/problem=59", "answer": "129448"} {"id": 60, "problem": "The primes $3$, $7$, $109$, and $673$, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking $7$ and $109$, both $7109$ and $1097$ are prime. The sum of these four primes, $792$, represents the lowest sum for a set of four primes with this property.\n\nFind the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.", "raw_html": "

The primes $3$, $7$, $109$, and $673$, are quite remarkable. By taking any two primes and concatenating them in any order the result will always be prime. For example, taking $7$ and $109$, both $7109$ and $1097$ are prime. The sum of these four primes, $792$, represents the lowest sum for a set of four primes with this property.

\n

Find the lowest sum for a set of five primes for which any two primes concatenate to produce another prime.

", "url": "https://projecteuler.net/problem=60", "answer": "26033"} {"id": 61, "problem": "Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae:\n\n| Triangle | | $P_{3,n}=n(n+1)/2$ | | $1, 3, 6, 10, 15, \\dots$ |\n| Square | | $P_{4,n}=n^2$ | | $1, 4, 9, 16, 25, \\dots$ |\n| Pentagonal | | $P_{5,n}=n(3n-1)/2$ | | $1, 5, 12, 22, 35, \\dots$ |\n| Hexagonal | | $P_{6,n}=n(2n-1)$ | | $1, 6, 15, 28, 45, \\dots$ |\n| Heptagonal | | $P_{7,n}=n(5n-3)/2$ | | $1, 7, 18, 34, 55, \\dots$ |\n| Octagonal | | $P_{8,n}=n(3n-2)$ | | $1, 8, 21, 40, 65, \\dots$ |\n\nThe ordered set of three $4$-digit numbers: $8128$, $2882$, $8281$, has three interesting properties.\n\n- The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first).\n\n- Each polygonal type: triangle ($P_{3,127}=8128$), square ($P_{4,91}=8281$), and pentagonal ($P_{5,44}=2882$), is represented by a different number in the set.\n\n- This is the only set of $4$-digit numbers with this property.\n\nFind the sum of the only ordered set of six cyclic $4$-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.", "raw_html": "

Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers are all figurate (polygonal) numbers and are generated by the following formulae:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Triangle $P_{3,n}=n(n+1)/2$ $1, 3, 6, 10, 15, \\dots$
Square $P_{4,n}=n^2$ $1, 4, 9, 16, 25, \\dots$
Pentagonal $P_{5,n}=n(3n-1)/2$ $1, 5, 12, 22, 35, \\dots$
Hexagonal $P_{6,n}=n(2n-1)$ $1, 6, 15, 28, 45, \\dots$
Heptagonal $P_{7,n}=n(5n-3)/2$ $1, 7, 18, 34, 55, \\dots$
Octagonal $P_{8,n}=n(3n-2)$ $1, 8, 21, 40, 65, \\dots$

The ordered set of three $4$-digit numbers: $8128$, $2882$, $8281$, has three interesting properties.

\n
  1. The set is cyclic, in that the last two digits of each number is the first two digits of the next number (including the last number with the first).
  2. \n
  3. Each polygonal type: triangle ($P_{3,127}=8128$), square ($P_{4,91}=8281$), and pentagonal ($P_{5,44}=2882$), is represented by a different number in the set.
  4. \n
  5. This is the only set of $4$-digit numbers with this property.
  6. \n

Find the sum of the only ordered set of six cyclic $4$-digit numbers for which each polygonal type: triangle, square, pentagonal, hexagonal, heptagonal, and octagonal, is represented by a different number in the set.

", "url": "https://projecteuler.net/problem=61", "answer": "28684"} {"id": 62, "problem": "The cube, $41063625$ ($345^3$), can be permuted to produce two other cubes: $56623104$ ($384^3$) and $66430125$ ($405^3$). In fact, $41063625$ is the smallest cube which has exactly three permutations of its digits which are also cube.\n\nFind the smallest cube for which exactly five permutations of its digits are cube.", "raw_html": "

The cube, $41063625$ ($345^3$), can be permuted to produce two other cubes: $56623104$ ($384^3$) and $66430125$ ($405^3$). In fact, $41063625$ is the smallest cube which has exactly three permutations of its digits which are also cube.

\n

Find the smallest cube for which exactly five permutations of its digits are cube.

", "url": "https://projecteuler.net/problem=62", "answer": "127035954683"} {"id": 63, "problem": "The $5$-digit number, $16807=7^5$, is also a fifth power. Similarly, the $9$-digit number, $134217728=8^9$, is a ninth power.\n\nHow many $n$-digit positive integers exist which are also an $n$th power?", "raw_html": "

The $5$-digit number, $16807=7^5$, is also a fifth power. Similarly, the $9$-digit number, $134217728=8^9$, is a ninth power.

\n

How many $n$-digit positive integers exist which are also an $n$th power?

", "url": "https://projecteuler.net/problem=63", "answer": "49"} {"id": 64, "problem": "All square roots are periodic when written as continued fractions and can be written in the form:\n\n$$\\sqrt{N}=a_0 + \\dfrac 1 {a_1 + \\dfrac 1 {a_2 + \\dfrac 1 {a_3 + \\dots}}}$$\n\nFor example, let us consider $\\sqrt{23}:$\n\n$$\\sqrt{23} = 4 + \\sqrt{23}-4=4 + \\dfrac 1 {\\dfrac 1 {\\sqrt{23}-4}} = 4+\\dfrac 1 {1 + \\dfrac{\\sqrt{23}-3}7}$$\n\nIf we continue we would get the following expansion:\n\n$$\\sqrt{23}=4 + \\dfrac 1 {1 + \\dfrac 1 {3+ \\dfrac 1 {1 + \\dfrac 1 {8+ \\dots}}}}$$\n\nThe process can be summarised as follows:\n\n$$\\begin{align} \\quad \\quad a_0 &= 4, \\frac 1 {\\sqrt{23}-4}=\\frac {\\sqrt{23}+4} 7=1+\\frac {\\sqrt{23}-3} 7 \\\\\n\\quad \\quad a_1 &= 1, \\frac 7 {\\sqrt{23}-3}=\\frac {7(\\sqrt{23}+3)} {14}=3+\\frac {\\sqrt{23}-3} 2 \\\\\n\\quad \\quad a_2 &= 3, \\frac 2 {\\sqrt{23}-3}=\\frac {2(\\sqrt{23}+3)} {14}=1+\\frac {\\sqrt{23}-4} 7 \\\\\n\\quad \\quad a_3 &= 1, \\frac 7 {\\sqrt{23}-4}=\\frac {7(\\sqrt{23}+4)} 7=8+\\sqrt{23}-4 \\\\\n\\quad \\quad a_4 &= 8, \\frac 1 {\\sqrt{23}-4}=\\frac {\\sqrt{23}+4} 7=1+\\frac {\\sqrt{23}-3} 7 \\\\\n\\quad \\quad a_5 &= 1, \\frac 7 {\\sqrt{23}-3}=\\frac {7 (\\sqrt{23}+3)} {14}=3+\\frac {\\sqrt{23}-3} 2 \\\\\n\\quad \\quad a_6 &= 3, \\frac 2 {\\sqrt{23}-3}=\\frac {2(\\sqrt{23}+3)} {14}=1+\\frac {\\sqrt{23}-4} 7 \\\\\n\\quad \\quad a_7 &= 1, \\frac 7 {\\sqrt{23}-4}=\\frac {7(\\sqrt{23}+4)} {7}=8+\\sqrt{23}-4 \\end{align}$$\n\nIt can be seen that the sequence is repeating. For conciseness, we use the notation $\\sqrt{23}=[4;(1,3,1,8)]$, to indicate that the block (1,3,1,8) repeats indefinitely.\n\nThe first ten continued fraction representations of (irrational) square roots are:\n\n$\\quad \\quad \\sqrt{2}=[1;(2)]$, period=$1$\n\n$\\quad \\quad \\sqrt{3}=[1;(1,2)]$, period=$2$\n\n$\\quad \\quad \\sqrt{5}=[2;(4)]$, period=$1$\n\n$\\quad \\quad \\sqrt{6}=[2;(2,4)]$, period=$2$\n\n$\\quad \\quad \\sqrt{7}=[2;(1,1,1,4)]$, period=$4$\n\n$\\quad \\quad \\sqrt{8}=[2;(1,4)]$, period=$2$\n\n$\\quad \\quad \\sqrt{10}=[3;(6)]$, period=$1$\n\n$\\quad \\quad \\sqrt{11}=[3;(3,6)]$, period=$2$\n\n$\\quad \\quad \\sqrt{12}=[3;(2,6)]$, period=$2$\n\n$\\quad \\quad \\sqrt{13}=[3;(1,1,1,1,6)]$, period=$5$\n\nExactly four continued fractions, for $N \\le 13$, have an odd period.\n\nHow many continued fractions for $N \\le 10\\,000$ have an odd period?", "raw_html": "

All square roots are periodic when written as continued fractions and can be written in the form:

\n\n$$\\sqrt{N}=a_0 + \\dfrac 1 {a_1 + \\dfrac 1 {a_2 + \\dfrac 1 {a_3 + \\dots}}}$$\n\n

For example, let us consider $\\sqrt{23}:$

\n$$\\sqrt{23} = 4 + \\sqrt{23}-4=4 + \\dfrac 1 {\\dfrac 1 {\\sqrt{23}-4}} = 4+\\dfrac 1 {1 + \\dfrac{\\sqrt{23}-3}7}$$\n\n

If we continue we would get the following expansion:

\n\n$$\\sqrt{23}=4 + \\dfrac 1 {1 + \\dfrac 1 {3+ \\dfrac 1 {1 + \\dfrac 1 {8+ \\dots}}}}$$\n\n

The process can be summarised as follows:

\n\n$$\\begin{align} \\quad \\quad a_0 &= 4, \\frac 1 {\\sqrt{23}-4}=\\frac {\\sqrt{23}+4} 7=1+\\frac {\\sqrt{23}-3} 7 \\\\\n\\quad \\quad a_1 &= 1, \\frac 7 {\\sqrt{23}-3}=\\frac {7(\\sqrt{23}+3)} {14}=3+\\frac {\\sqrt{23}-3} 2 \\\\\n\\quad \\quad a_2 &= 3, \\frac 2 {\\sqrt{23}-3}=\\frac {2(\\sqrt{23}+3)} {14}=1+\\frac {\\sqrt{23}-4} 7 \\\\\n\\quad \\quad a_3 &= 1, \\frac 7 {\\sqrt{23}-4}=\\frac {7(\\sqrt{23}+4)} 7=8+\\sqrt{23}-4 \\\\\n\\quad \\quad a_4 &= 8, \\frac 1 {\\sqrt{23}-4}=\\frac {\\sqrt{23}+4} 7=1+\\frac {\\sqrt{23}-3} 7 \\\\\n\\quad \\quad a_5 &= 1, \\frac 7 {\\sqrt{23}-3}=\\frac {7 (\\sqrt{23}+3)} {14}=3+\\frac {\\sqrt{23}-3} 2 \\\\\n\\quad \\quad a_6 &= 3, \\frac 2 {\\sqrt{23}-3}=\\frac {2(\\sqrt{23}+3)} {14}=1+\\frac {\\sqrt{23}-4} 7 \\\\\n\\quad \\quad a_7 &= 1, \\frac 7 {\\sqrt{23}-4}=\\frac {7(\\sqrt{23}+4)} {7}=8+\\sqrt{23}-4 \\end{align}$$\n\n\n

It can be seen that the sequence is repeating. For conciseness, we use the notation $\\sqrt{23}=[4;(1,3,1,8)]$, to indicate that the block (1,3,1,8) repeats indefinitely.

\n\n

The first ten continued fraction representations of (irrational) square roots are:

\n

\n$\\quad \\quad \\sqrt{2}=[1;(2)]$, period=$1$
\n$\\quad \\quad \\sqrt{3}=[1;(1,2)]$, period=$2$
\n$\\quad \\quad \\sqrt{5}=[2;(4)]$, period=$1$
\n$\\quad \\quad \\sqrt{6}=[2;(2,4)]$, period=$2$
\n$\\quad \\quad \\sqrt{7}=[2;(1,1,1,4)]$, period=$4$
\n$\\quad \\quad \\sqrt{8}=[2;(1,4)]$, period=$2$
\n$\\quad \\quad \\sqrt{10}=[3;(6)]$, period=$1$
\n$\\quad \\quad \\sqrt{11}=[3;(3,6)]$, period=$2$
\n$\\quad \\quad \\sqrt{12}=[3;(2,6)]$, period=$2$
\n$\\quad \\quad \\sqrt{13}=[3;(1,1,1,1,6)]$, period=$5$\n

\n

Exactly four continued fractions, for $N \\le 13$, have an odd period.

\n

How many continued fractions for $N \\le 10\\,000$ have an odd period?

", "url": "https://projecteuler.net/problem=64", "answer": "1322"} {"id": 65, "problem": "The square root of $2$ can be written as an infinite continued fraction.\n\n$$\\sqrt{2} = 1 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2 + ...}}}}$$\n\nThe infinite continued fraction can be written, $\\sqrt{2} = [1; (2)]$, $(2)$ indicates that $2$ repeats ad infinitum. In a similar way, $\\sqrt{23} = [4; (1, 3, 1, 8)]$.\n\nIt turns out that the sequence of partial values of continued fractions for square roots provide the best rational approximations. Let us consider the convergents for $\\sqrt{2}$.\n\n$$\\begin{align}\n&1 + \\dfrac{1}{2} &= \\dfrac{3}{2} \\\\\n&1 + \\dfrac{1}{2 + \\dfrac{1}{2}} &= \\dfrac{7}{5}\\\\\n&1 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2}}} &= \\dfrac{17}{12}\\\\\n&1 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2}}}} &= \\dfrac{41}{29}\n\\end{align}$$\n\nHence the sequence of the first ten convergents for $\\sqrt{2}$ are:\n\n$$1, \\dfrac{3}{2}, \\dfrac{7}{5}, \\dfrac{17}{12}, \\dfrac{41}{29}, \\dfrac{99}{70}, \\dfrac{239}{169}, \\dfrac{577}{408}, \\dfrac{1393}{985}, \\dfrac{3363}{2378}, ...$$\n\nWhat is most surprising is that the important mathematical constant,\n\n$$e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, ... , 1, 2k, 1, ...]$$\n\nThe first ten terms in the sequence of convergents for $e$ are:\n\n$$2, 3, \\dfrac{8}{3}, \\dfrac{11}{4}, \\dfrac{19}{7}, \\dfrac{87}{32}, \\dfrac{106}{39}, \\dfrac{193}{71}, \\dfrac{1264}{465}, \\dfrac{1457}{536}, ...$$\n\nThe sum of digits in the numerator of the $10$th convergent is $1 + 4 + 5 + 7 = 17$.\n\nFind the sum of digits in the numerator of the $100$th convergent of the continued fraction for $e$.", "raw_html": "

The square root of $2$ can be written as an infinite continued fraction.

\n

$$\\sqrt{2} = 1 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2 + ...}}}}$$

\n

The infinite continued fraction can be written, $\\sqrt{2} = [1; (2)]$, $(2)$ indicates that $2$ repeats ad infinitum. In a similar way, $\\sqrt{23} = [4; (1, 3, 1, 8)]$.

\n

It turns out that the sequence of partial values of continued fractions for square roots provide the best rational approximations. Let us consider the convergents for $\\sqrt{2}$.

\n

$$\\begin{align}\n&1 + \\dfrac{1}{2} &= \\dfrac{3}{2} \\\\\n&1 + \\dfrac{1}{2 + \\dfrac{1}{2}} &= \\dfrac{7}{5}\\\\\n&1 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2}}} &= \\dfrac{17}{12}\\\\\n&1 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2 + \\dfrac{1}{2}}}} &= \\dfrac{41}{29}\n\\end{align}$$

\n

Hence the sequence of the first ten convergents for $\\sqrt{2}$ are:

\n

$$1, \\dfrac{3}{2}, \\dfrac{7}{5}, \\dfrac{17}{12}, \\dfrac{41}{29}, \\dfrac{99}{70}, \\dfrac{239}{169}, \\dfrac{577}{408}, \\dfrac{1393}{985}, \\dfrac{3363}{2378}, ...$$

\n

What is most surprising is that the important mathematical constant,

\n

$$e = [2; 1, 2, 1, 1, 4, 1, 1, 6, 1, ... , 1, 2k, 1, ...]$$

\n

The first ten terms in the sequence of convergents for $e$ are:

\n

$$2, 3, \\dfrac{8}{3}, \\dfrac{11}{4}, \\dfrac{19}{7}, \\dfrac{87}{32}, \\dfrac{106}{39}, \\dfrac{193}{71}, \\dfrac{1264}{465}, \\dfrac{1457}{536}, ...$$

\n

The sum of digits in the numerator of the $10$th convergent is $1 + 4 + 5 + 7 = 17$.

\n

Find the sum of digits in the numerator of the $100$th convergent of the continued fraction for $e$.

", "url": "https://projecteuler.net/problem=65", "answer": "272"} {"id": 66, "problem": "Consider quadratic Diophantine equations of the form:\n$$x^2 - Dy^2 = 1$$\n\nFor example, when $D=13$, the minimal solution in $x$ is $649^2 - 13 \\times 180^2 = 1$.\n\nIt can be assumed that there are no solutions in positive integers when $D$ is square.\n\nBy finding minimal solutions in $x$ for $D = \\{2, 3, 5, 6, 7\\}$, we obtain the following:\n\n$$\\begin{align}\n3^2 - 2 \\times 2^2 &= 1\\\\\n2^2 - 3 \\times 1^2 &= 1\\\\\n{\\color{red}{\\mathbf 9}}^2 - 5 \\times 4^2 &= 1\\\\\n5^2 - 6 \\times 2^2 &= 1\\\\\n8^2 - 7 \\times 3^2 &= 1\n\\end{align}$$\nHence, by considering minimal solutions in $x$ for $D \\le 7$, the largest $x$ is obtained when $D=5$.\n\nFind the value of $D \\le 1000$ in minimal solutions of $x$ for which the largest value of $x$ is obtained.", "raw_html": "

Consider quadratic Diophantine equations of the form:\n$$x^2 - Dy^2 = 1$$

\n

For example, when $D=13$, the minimal solution in $x$ is $649^2 - 13 \\times 180^2 = 1$.

\n

It can be assumed that there are no solutions in positive integers when $D$ is square.

\n

By finding minimal solutions in $x$ for $D = \\{2, 3, 5, 6, 7\\}$, we obtain the following:

\n$$\\begin{align}\n3^2 - 2 \\times 2^2 &= 1\\\\\n2^2 - 3 \\times 1^2 &= 1\\\\\n{\\color{red}{\\mathbf 9}}^2 - 5 \\times 4^2 &= 1\\\\\n5^2 - 6 \\times 2^2 &= 1\\\\\n8^2 - 7 \\times 3^2 &= 1\n\\end{align}$$\n

Hence, by considering minimal solutions in $x$ for $D \\le 7$, the largest $x$ is obtained when $D=5$.

\n

Find the value of $D \\le 1000$ in minimal solutions of $x$ for which the largest value of $x$ is obtained.

", "url": "https://projecteuler.net/problem=66", "answer": "661"} {"id": 67, "problem": "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.\n\n3\n7 4\n\n2 4 6\n\n8 5 9 3\n\nThat is, 3 + 7 + 4 + 9 = 23.\n\nFind the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file containing a triangle with one-hundred rows.\n\nNOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, as there are $2^{99}$ altogether! If you could check one trillion ($10^{12}$) routes every second it would take over twenty billion years to check them all. There is an efficient algorithm to solve it. ;o)", "raw_html": "

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.

\n

3
7 4
\n2 4 6
\n8 5 9 3

\n

That is, 3 + 7 + 4 + 9 = 23.

\n

Find the maximum total from top to bottom in triangle.txt (right click and 'Save Link/Target As...'), a 15K text file containing a triangle with one-hundred rows.

\n

NOTE: This is a much more difficult version of Problem 18. It is not possible to try every route to solve this problem, as there are $2^{99}$ altogether! If you could check one trillion ($10^{12}$) routes every second it would take over twenty billion years to check them all. There is an efficient algorithm to solve it. ;o)

", "url": "https://projecteuler.net/problem=67", "answer": "7273"} {"id": 68, "problem": "Consider the following \"magic\" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.\n\nWorking clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be described by the set: 4,3,2; 6,2,1; 5,1,3.\n\nIt is possible to complete the ring with four different totals: 9, 10, 11, and 12. There are eight solutions in total.\n\n| Total | Solution Set |\n| 9 | 4,2,3; 5,3,1; 6,1,2 |\n| 9 | 4,3,2; 6,2,1; 5,1,3 |\n| 10 | 2,3,5; 4,5,1; 6,1,3 |\n| 10 | 2,5,3; 6,3,1; 4,1,5 |\n| 11 | 1,4,6; 3,6,2; 5,2,4 |\n| 11 | 1,6,4; 5,4,2; 3,2,6 |\n| 12 | 1,5,6; 2,6,4; 3,4,5 |\n| 12 | 1,6,5; 3,5,4; 2,4,6 |\n\nBy concatenating each group it is possible to form 9-digit strings; the maximum string for a 3-gon ring is 432621513.\n\nUsing the numbers 1 to 10, and depending on arrangements, it is possible to form 16- and 17-digit strings. What is the maximum 16-digit string for a \"magic\" 5-gon ring?", "raw_html": "

Consider the following \"magic\" 3-gon ring, filled with the numbers 1 to 6, and each line adding to nine.

\n
\n\"\"
\n

Working clockwise, and starting from the group of three with the numerically lowest external node (4,3,2 in this example), each solution can be described uniquely. For example, the above solution can be described by the set: 4,3,2; 6,2,1; 5,1,3.

\n

It is possible to complete the ring with four different totals: 9, 10, 11, and 12. There are eight solutions in total.

\n
\n\n\n\n\n\n\n\n\n\n
TotalSolution Set
94,2,3; 5,3,1; 6,1,2
94,3,2; 6,2,1; 5,1,3
102,3,5; 4,5,1; 6,1,3
102,5,3; 6,3,1; 4,1,5
111,4,6; 3,6,2; 5,2,4
111,6,4; 5,4,2; 3,2,6
121,5,6; 2,6,4; 3,4,5
121,6,5; 3,5,4; 2,4,6
\n

By concatenating each group it is possible to form 9-digit strings; the maximum string for a 3-gon ring is 432621513.

\n

Using the numbers 1 to 10, and depending on arrangements, it is possible to form 16- and 17-digit strings. What is the maximum 16-digit string for a \"magic\" 5-gon ring?

\n
\n\"\"
", "url": "https://projecteuler.net/problem=68", "answer": "6531031914842725"} {"id": 69, "problem": "Euler's totient function, $\\phi(n)$ [sometimes called the phi function], is defined as the number of positive integers not exceeding $n$ which are relatively prime to $n$. For example, as $1$, $2$, $4$, $5$, $7$, and $8$, are all less than or equal to nine and relatively prime to nine, $\\phi(9)=6$.\n\n| $n$ | Relatively Prime | $\\phi(n)$ | $n/\\phi(n)$ |\n| 2 | 1 | 1 | 2 |\n| 3 | 1,2 | 2 | 1.5 |\n| 4 | 1,3 | 2 | 2 |\n| 5 | 1,2,3,4 | 4 | 1.25 |\n| 6 | 1,5 | 2 | 3 |\n| 7 | 1,2,3,4,5,6 | 6 | 1.1666... |\n| 8 | 1,3,5,7 | 4 | 2 |\n| 9 | 1,2,4,5,7,8 | 6 | 1.5 |\n| 10 | 1,3,7,9 | 4 | 2.5 |\n\nIt can be seen that $n = 6$ produces a maximum $n/\\phi(n)$ for $n\\leq 10$.\n\nFind the value of $n\\leq 1\\,000\\,000$ for which $n/\\phi(n)$ is a maximum.", "raw_html": "

Euler's totient function, $\\phi(n)$ [sometimes called the phi function], is defined as the number of positive integers not exceeding $n$ which are relatively prime to $n$. For example, as $1$, $2$, $4$, $5$, $7$, and $8$, are all less than or equal to nine and relatively prime to nine, $\\phi(9)=6$.

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$n$Relatively Prime$\\phi(n)$$n/\\phi(n)$
2112
31,221.5
41,322
51,2,3,441.25
61,523
71,2,3,4,5,661.1666...
81,3,5,742
91,2,4,5,7,861.5
101,3,7,942.5
\n

It can be seen that $n = 6$ produces a maximum $n/\\phi(n)$ for $n\\leq 10$.

\n

Find the value of $n\\leq 1\\,000\\,000$ for which $n/\\phi(n)$ is a maximum.

", "url": "https://projecteuler.net/problem=69", "answer": "510510"} {"id": 70, "problem": "Euler's totient function, $\\phi(n)$ [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to $n$ which are relatively prime to $n$. For example, as $1, 2, 4, 5, 7$, and $8$, are all less than nine and relatively prime to nine, $\\phi(9)=6$.\nThe number $1$ is considered to be relatively prime to every positive number, so $\\phi(1)=1$.\n\nInterestingly, $\\phi(87109)=79180$, and it can be seen that $87109$ is a permutation of $79180$.\n\nFind the value of $n$, $1 \\lt n \\lt 10^7$, for which $\\phi(n)$ is a permutation of $n$ and the ratio $n/\\phi(n)$ produces a minimum.", "raw_html": "

Euler's totient function, $\\phi(n)$ [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to $n$ which are relatively prime to $n$. For example, as $1, 2, 4, 5, 7$, and $8$, are all less than nine and relatively prime to nine, $\\phi(9)=6$.
The number $1$ is considered to be relatively prime to every positive number, so $\\phi(1)=1$.

\n

Interestingly, $\\phi(87109)=79180$, and it can be seen that $87109$ is a permutation of $79180$.

\n

Find the value of $n$, $1 \\lt n \\lt 10^7$, for which $\\phi(n)$ is a permutation of $n$ and the ratio $n/\\phi(n)$ produces a minimum.

", "url": "https://projecteuler.net/problem=70", "answer": "8319823"} {"id": 71, "problem": "Consider the fraction, $\\dfrac n d$, where $n$ and $d$ are positive integers. If $n \\lt d$ and $\\operatorname{HCF}(n,d)=1$, it is called a reduced proper fraction.\n\nIf we list the set of reduced proper fractions for $d \\le 8$ in ascending order of size, we get:\n$$\\frac 1 8, \\frac 1 7, \\frac 1 6, \\frac 1 5, \\frac 1 4, \\frac 2 7, \\frac 1 3, \\frac 3 8, \\mathbf{\\frac 2 5}, \\frac 3 7, \\frac 1 2, \\frac 4 7, \\frac 3 5, \\frac 5 8, \\frac 2 3, \\frac 5 7, \\frac 3 4, \\frac 4 5, \\frac 5 6, \\frac 6 7, \\frac 7 8$$\n\nIt can be seen that $\\dfrac 2 5$ is the fraction immediately to the left of $\\dfrac 3 7$.\n\nBy listing the set of reduced proper fractions for $d \\le 1\\,000\\,000$ in ascending order of size, find the numerator of the fraction immediately to the left of $\\dfrac 3 7$.", "raw_html": "

Consider the fraction, $\\dfrac n d$, where $n$ and $d$ are positive integers. If $n \\lt d$ and $\\operatorname{HCF}(n,d)=1$, it is called a reduced proper fraction.

\n

If we list the set of reduced proper fractions for $d \\le 8$ in ascending order of size, we get:\n$$\\frac 1 8, \\frac 1 7, \\frac 1 6, \\frac 1 5, \\frac 1 4, \\frac 2 7, \\frac 1 3, \\frac 3 8, \\mathbf{\\frac 2 5}, \\frac 3 7, \\frac 1 2, \\frac 4 7, \\frac 3 5, \\frac 5 8, \\frac 2 3, \\frac 5 7, \\frac 3 4, \\frac 4 5, \\frac 5 6, \\frac 6 7, \\frac 7 8$$

\n

It can be seen that $\\dfrac 2 5$ is the fraction immediately to the left of $\\dfrac 3 7$.

\n

By listing the set of reduced proper fractions for $d \\le 1\\,000\\,000$ in ascending order of size, find the numerator of the fraction immediately to the left of $\\dfrac 3 7$.

", "url": "https://projecteuler.net/problem=71", "answer": "428570"} {"id": 72, "problem": "Consider the fraction, $\\dfrac n d$, where $n$ and $d$ are positive integers. If $n \\lt d$ and $\\operatorname{HCF}(n,d)=1$, it is called a reduced proper fraction.\n\nIf we list the set of reduced proper fractions for $d \\le 8$ in ascending order of size, we get:\n$$\\frac 1 8, \\frac 1 7, \\frac 1 6, \\frac 1 5, \\frac 1 4, \\frac 2 7, \\frac 1 3, \\frac 3 8, \\frac 2 5, \\frac 3 7, \\frac 1 2, \\frac 4 7, \\frac 3 5, \\frac 5 8, \\frac 2 3, \\frac 5 7, \\frac 3 4, \\frac 4 5, \\frac 5 6, \\frac 6 7, \\frac 7 8$$\n\nIt can be seen that there are $21$ elements in this set.\n\nHow many elements would be contained in the set of reduced proper fractions for $d \\le 1\\,000\\,000$?", "raw_html": "

Consider the fraction, $\\dfrac n d$, where $n$ and $d$ are positive integers. If $n \\lt d$ and $\\operatorname{HCF}(n,d)=1$, it is called a reduced proper fraction.

\n

If we list the set of reduced proper fractions for $d \\le 8$ in ascending order of size, we get:\n$$\\frac 1 8, \\frac 1 7, \\frac 1 6, \\frac 1 5, \\frac 1 4, \\frac 2 7, \\frac 1 3, \\frac 3 8, \\frac 2 5, \\frac 3 7, \\frac 1 2, \\frac 4 7, \\frac 3 5, \\frac 5 8, \\frac 2 3, \\frac 5 7, \\frac 3 4, \\frac 4 5, \\frac 5 6, \\frac 6 7, \\frac 7 8$$

\n

It can be seen that there are $21$ elements in this set.

\n

How many elements would be contained in the set of reduced proper fractions for $d \\le 1\\,000\\,000$?

", "url": "https://projecteuler.net/problem=72", "answer": "303963552391"} {"id": 73, "problem": "Consider the fraction, $\\dfrac n d$, where $n$ and $d$ are positive integers. If $n \\lt d$ and $\\operatorname{HCF}(n, d)=1$, it is called a reduced proper fraction.\n\nIf we list the set of reduced proper fractions for $d \\le 8$ in ascending order of size, we get:\n$$\\frac 1 8, \\frac 1 7, \\frac 1 6, \\frac 1 5, \\frac 1 4, \\frac 2 7, \\frac 1 3, \\mathbf{\\frac 3 8, \\frac 2 5, \\frac 3 7}, \\frac 1 2, \\frac 4 7, \\frac 3 5, \\frac 5 8, \\frac 2 3, \\frac 5 7, \\frac 3 4, \\frac 4 5, \\frac 5 6, \\frac 6 7, \\frac 7 8$$\n\nIt can be seen that there are $3$ fractions between $\\dfrac 1 3$ and $\\dfrac 1 2$.\n\nHow many fractions lie between $\\dfrac 1 3$ and $\\dfrac 1 2$ in the sorted set of reduced proper fractions for $d \\le 12\\,000$?", "raw_html": "

Consider the fraction, $\\dfrac n d$, where $n$ and $d$ are positive integers. If $n \\lt d$ and $\\operatorname{HCF}(n, d)=1$, it is called a reduced proper fraction.

\n

If we list the set of reduced proper fractions for $d \\le 8$ in ascending order of size, we get:\n$$\\frac 1 8, \\frac 1 7, \\frac 1 6, \\frac 1 5, \\frac 1 4, \\frac 2 7, \\frac 1 3, \\mathbf{\\frac 3 8, \\frac 2 5, \\frac 3 7}, \\frac 1 2, \\frac 4 7, \\frac 3 5, \\frac 5 8, \\frac 2 3, \\frac 5 7, \\frac 3 4, \\frac 4 5, \\frac 5 6, \\frac 6 7, \\frac 7 8$$

\n

It can be seen that there are $3$ fractions between $\\dfrac 1 3$ and $\\dfrac 1 2$.

\n

How many fractions lie between $\\dfrac 1 3$ and $\\dfrac 1 2$ in the sorted set of reduced proper fractions for $d \\le 12\\,000$?

", "url": "https://projecteuler.net/problem=73", "answer": "7295372"} {"id": 74, "problem": "The number $145$ is well known for the property that the sum of the factorial of its digits is equal to $145$:\n$$1! + 4! + 5! = 1 + 24 + 120 = 145.$$\n\nPerhaps less well known is $169$, in that it produces the longest chain of numbers that link back to $169$; it turns out that there are only three such loops that exist:\n\n$$\\begin{align}\n&169 \\to 363601 \\to 1454 \\to 169\\\\\n&871 \\to 45361 \\to 871\\\\\n&872 \\to 45362 \\to 872\n\\end{align}$$\nIt is not difficult to prove that EVERY starting number will eventually get stuck in a loop. For example,\n\n$$\\begin{align}\n&69 \\to 363600 \\to 1454 \\to 169 \\to 363601 (\\to 1454)\\\\\n&78 \\to 45360 \\to 871 \\to 45361 (\\to 871)\\\\\n&540 \\to 145 (\\to 145)\n\\end{align}$$\nStarting with $69$ produces a chain of five non-repeating terms, but the longest non-repeating chain with a starting number below one million is sixty terms.\n\nHow many chains, with a starting number below one million, contain exactly sixty non-repeating terms?", "raw_html": "

The number $145$ is well known for the property that the sum of the factorial of its digits is equal to $145$:\n$$1! + 4! + 5! = 1 + 24 + 120 = 145.$$

\n

Perhaps less well known is $169$, in that it produces the longest chain of numbers that link back to $169$; it turns out that there are only three such loops that exist:

\n$$\\begin{align}\n&169 \\to 363601 \\to 1454 \\to 169\\\\\n&871 \\to 45361 \\to 871\\\\\n&872 \\to 45362 \\to 872\n\\end{align}$$\n

It is not difficult to prove that EVERY starting number will eventually get stuck in a loop. For example,

\n$$\\begin{align}\n&69 \\to 363600 \\to 1454 \\to 169 \\to 363601 (\\to 1454)\\\\\n&78 \\to 45360 \\to 871 \\to 45361 (\\to 871)\\\\\n&540 \\to 145 (\\to 145)\n\\end{align}$$\n

Starting with $69$ produces a chain of five non-repeating terms, but the longest non-repeating chain with a starting number below one million is sixty terms.

\n

How many chains, with a starting number below one million, contain exactly sixty non-repeating terms?

", "url": "https://projecteuler.net/problem=74", "answer": "402"} {"id": 75, "problem": "It turns out that $\\pu{12 cm}$ is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.\n\n- $\\pu{\\mathbf{12} \\mathbf{cm}}$: $(3,4,5)$\n\n- $\\pu{\\mathbf{24} \\mathbf{cm}}$: $(6,8,10)$\n\n- $\\pu{\\mathbf{30} \\mathbf{cm}}$: $(5,12,13)$\n\n- $\\pu{\\mathbf{36} \\mathbf{cm}}$: $(9,12,15)$\n\n- $\\pu{\\mathbf{40} \\mathbf{cm}}$: $(8,15,17)$\n\n- $\\pu{\\mathbf{48} \\mathbf{cm}}$: $(12,16,20)$\n\nIn contrast, some lengths of wire, like $\\pu{20 cm}$, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using $\\pu{120 cm}$ it is possible to form exactly three different integer sided right angle triangles.\n\n- $\\pu{\\mathbf{120} \\mathbf{cm}}$: $(30,40,50)$, $(20,48,52)$, $(24,45,51)$\n\nGiven that $L$ is the length of the wire, for how many values of $L \\le 1\\,500\\,000$ can exactly one integer sided right angle triangle be formed?", "raw_html": "

It turns out that $\\pu{12 cm}$ is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.

\n\n

In contrast, some lengths of wire, like $\\pu{20 cm}$, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using $\\pu{120 cm}$ it is possible to form exactly three different integer sided right angle triangles.

\n\n\n

Given that $L$ is the length of the wire, for how many values of $L \\le 1\\,500\\,000$ can exactly one integer sided right angle triangle be formed?

", "url": "https://projecteuler.net/problem=75", "answer": "161667"} {"id": 76, "problem": "It is possible to write five as a sum in exactly six different ways:\n\n$$\\begin{align}\n&4 + 1\\\\\n&3 + 2\\\\\n&3 + 1 + 1\\\\\n&2 + 2 + 1\\\\\n&2 + 1 + 1 + 1\\\\\n&1 + 1 + 1 + 1 + 1\n\\end{align}$$\nHow many different ways can one hundred be written as a sum of at least two positive integers?", "raw_html": "

It is possible to write five as a sum in exactly six different ways:

\n$$\\begin{align}\n&4 + 1\\\\\n&3 + 2\\\\\n&3 + 1 + 1\\\\\n&2 + 2 + 1\\\\\n&2 + 1 + 1 + 1\\\\\n&1 + 1 + 1 + 1 + 1\n\\end{align}$$\n

How many different ways can one hundred be written as a sum of at least two positive integers?

", "url": "https://projecteuler.net/problem=76", "answer": "190569291"} {"id": 77, "problem": "It is possible to write ten as the sum of primes in exactly five different ways:\n\n$$\\begin{align}\n&7 + 3\\\\\n&5 + 5\\\\\n&5 + 3 + 2\\\\\n&3 + 3 + 2 + 2\\\\\n&2 + 2 + 2 + 2 + 2\n\\end{align}$$\nWhat is the first value which can be written as the sum of primes in over five thousand different ways?", "raw_html": "

It is possible to write ten as the sum of primes in exactly five different ways:

\n$$\\begin{align}\n&7 + 3\\\\\n&5 + 5\\\\\n&5 + 3 + 2\\\\\n&3 + 3 + 2 + 2\\\\\n&2 + 2 + 2 + 2 + 2\n\\end{align}$$\n

What is the first value which can be written as the sum of primes in over five thousand different ways?

", "url": "https://projecteuler.net/problem=77", "answer": "71"} {"id": 78, "problem": "Let $p(n)$ represent the number of different ways in which $n$ coins can be separated into piles. For example, five coins can be separated into piles in exactly seven different ways, so $p(5)=7$.\n\nOOOOO\n\nOOOO   O\n\nOOO   OO\n\nOOO   O   O\n\nOO   OO   O\n\nOO   O   O   O\n\nO   O   O   O   O\n\nFind the least value of $n$ for which $p(n)$ is divisible by one million.", "raw_html": "

Let $p(n)$ represent the number of different ways in which $n$ coins can be separated into piles. For example, five coins can be separated into piles in exactly seven different ways, so $p(5)=7$.

\n
\nOOOOO
\nOOOO   O
\nOOO   OO
\nOOO   O   O
\nOO   OO   O
\nOO   O   O   O
\nO   O   O   O   O\n
\n

Find the least value of $n$ for which $p(n)$ is divisible by one million.

", "url": "https://projecteuler.net/problem=78", "answer": "55374"} {"id": 79, "problem": "A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.\n\nThe text file, keylog.txt, contains fifty successful login attempts.\n\nGiven that the three characters are always asked for in order, analyse the file so as to determine the shortest possible secret passcode of unknown length.", "raw_html": "

A common security method used for online banking is to ask the user for three random characters from a passcode. For example, if the passcode was 531278, they may ask for the 2nd, 3rd, and 5th characters; the expected reply would be: 317.

\n

The text file, keylog.txt, contains fifty successful login attempts.

\n

Given that the three characters are always asked for in order, analyse the file so as to determine the shortest possible secret passcode of unknown length.

", "url": "https://projecteuler.net/problem=79", "answer": "73162890"} {"id": 80, "problem": "It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.\n\nThe square root of two is $1.41421356237309504880\\cdots$, and the digital sum of the first one hundred decimal digits is $475$.\n\nFor the first one hundred natural numbers, find the total of the digital sums of the first one hundred decimal digits for all the irrational square roots.", "raw_html": "

It is well known that if the square root of a natural number is not an integer, then it is irrational. The decimal expansion of such square roots is infinite without any repeating pattern at all.

\n

The square root of two is $1.41421356237309504880\\cdots$, and the digital sum of the first one hundred decimal digits is $475$.

\n

For the first one hundred natural numbers, find the total of the digital sums of the first one hundred decimal digits for all the irrational square roots.

", "url": "https://projecteuler.net/problem=80", "answer": "40886"} {"id": 81, "problem": "In the $5$ by $5$ matrix below, the minimal path sum from the top left to the bottom right, by only moving to the right and down, is indicated in bold red and is equal to $2427$.\n\n$$\n\\begin{pmatrix}\n\\color{red}{131} & 673 & 234 & 103 & 18\\\\\n\\color{red}{201} & \\color{red}{96} & \\color{red}{342} & 965 & 150\\\\\n630 & 803 & \\color{red}{746} & \\color{red}{422} & 111\\\\\n537 & 699 & 497 & \\color{red}{121} & 956\\\\\n805 & 732 & 524 & \\color{red}{37} & \\color{red}{331}\n\\end{pmatrix}\n$$\n\nFind the minimal path sum from the top left to the bottom right by only moving right and down in matrix.txt (right click and \"Save Link/Target As...\"), a 31K text file containing an $80$ by $80$ matrix.", "raw_html": "

In the $5$ by $5$ matrix below, the minimal path sum from the top left to the bottom right, by only moving to the right and down, is indicated in bold red and is equal to $2427$.

\n
\n$$\n\\begin{pmatrix}\n\\color{red}{131} & 673 & 234 & 103 & 18\\\\\n\\color{red}{201} & \\color{red}{96} & \\color{red}{342} & 965 & 150\\\\\n630 & 803 & \\color{red}{746} & \\color{red}{422} & 111\\\\\n537 & 699 & 497 & \\color{red}{121} & 956\\\\\n805 & 732 & 524 & \\color{red}{37} & \\color{red}{331}\n\\end{pmatrix}\n$$\n
\n

Find the minimal path sum from the top left to the bottom right by only moving right and down in matrix.txt (right click and \"Save Link/Target As...\"), a 31K text file containing an $80$ by $80$ matrix.

", "url": "https://projecteuler.net/problem=81", "answer": "427337"} {"id": 82, "problem": "NOTE: This problem is a more challenging version of Problem 81.\n\nThe minimal path sum in the $5$ by $5$ matrix below, by starting in any cell in the left column and finishing in any cell in the right column, and only moving up, down, and right, is indicated in red and bold; the sum is equal to $994$.\n\n$$\n\\begin{pmatrix}\n131 & 673 & \\color{red}{234} & \\color{red}{103} & \\color{red}{18}\\\\\n\\color{red}{201} & \\color{red}{96} & \\color{red}{342} & 965 & 150\\\\\n630 & 803 & 746 & 422 & 111\\\\\n537 & 699 & 497 & 121 & 956\\\\\n805 & 732 & 524 & 37 & 331\n\\end{pmatrix}\n$$\n\nFind the minimal path sum from the left column to the right column in matrix.txt (right click and \"Save Link/Target As...\"), a 31K text file containing an $80$ by $80$ matrix.", "raw_html": "

NOTE: This problem is a more challenging version of Problem 81.

\n

The minimal path sum in the $5$ by $5$ matrix below, by starting in any cell in the left column and finishing in any cell in the right column, and only moving up, down, and right, is indicated in red and bold; the sum is equal to $994$.

\n
\n$$\n\\begin{pmatrix}\n131 & 673 & \\color{red}{234} & \\color{red}{103} & \\color{red}{18}\\\\\n\\color{red}{201} & \\color{red}{96} & \\color{red}{342} & 965 & 150\\\\\n630 & 803 & 746 & 422 & 111\\\\\n537 & 699 & 497 & 121 & 956\\\\\n805 & 732 & 524 & 37 & 331\n\\end{pmatrix}\n$$\n
\n

Find the minimal path sum from the left column to the right column in matrix.txt (right click and \"Save Link/Target As...\"), a 31K text file containing an $80$ by $80$ matrix.

", "url": "https://projecteuler.net/problem=82", "answer": "260324"} {"id": 83, "problem": "NOTE: This problem is a significantly more challenging version of Problem 81.\n\nIn the $5$ by $5$ matrix below, the minimal path sum from the top left to the bottom right, by moving left, right, up, and down, is indicated in bold red and is equal to $2297$.\n\n$$\n\\begin{pmatrix}\n\\color{red}{131} & 673 & \\color{red}{234} & \\color{red}{103} & \\color{red}{18}\\\\\n\\color{red}{201} & \\color{red}{96} & \\color{red}{342} & 965 & \\color{red}{150}\\\\\n630 & 803 & 746 & \\color{red}{422} & \\color{red}{111}\\\\\n537 & 699 & 497 & \\color{red}{121} & 956\\\\\n805 & 732 & 524 & \\color{red}{37} & \\color{red}{331}\n\\end{pmatrix}\n$$\n\nFind the minimal path sum from the top left to the bottom right by moving left, right, up, and down in matrix.txt (right click and \"Save Link/Target As...\"), a 31K text file containing an $80$ by $80$ matrix.", "raw_html": "

NOTE: This problem is a significantly more challenging version of Problem 81.

\n

In the $5$ by $5$ matrix below, the minimal path sum from the top left to the bottom right, by moving left, right, up, and down, is indicated in bold red and is equal to $2297$.

\n
\n$$\n\\begin{pmatrix}\n\\color{red}{131} & 673 & \\color{red}{234} & \\color{red}{103} & \\color{red}{18}\\\\\n\\color{red}{201} & \\color{red}{96} & \\color{red}{342} & 965 & \\color{red}{150}\\\\\n630 & 803 & 746 & \\color{red}{422} & \\color{red}{111}\\\\\n537 & 699 & 497 & \\color{red}{121} & 956\\\\\n805 & 732 & 524 & \\color{red}{37} & \\color{red}{331}\n\\end{pmatrix}\n$$\n
\n

Find the minimal path sum from the top left to the bottom right by moving left, right, up, and down in matrix.txt (right click and \"Save Link/Target As...\"), a 31K text file containing an $80$ by $80$ matrix.

", "url": "https://projecteuler.net/problem=83", "answer": "425185"} {"id": 84, "problem": "In the game, Monopoly, the standard board is set up in the following way:\n\nA player starts on the GO square and adds the scores on two 6-sided dice to determine the number of squares they advance in a clockwise direction. Without any further rules we would expect to visit each square with equal probability: 2.5%. However, landing on G2J (Go To Jail), CC (community chest), and CH (chance) changes this distribution.\n\nIn addition to G2J, and one card from each of CC and CH, that orders the player to go directly to jail, if a player rolls three consecutive doubles, they do not advance the result of their 3rd roll. Instead they proceed directly to jail.\n\nAt the beginning of the game, the CC and CH cards are shuffled. When a player lands on CC or CH they take a card from the top of the respective pile and, after following the instructions, it is returned to the bottom of the pile. There are sixteen cards in each pile, but for the purpose of this problem we are only concerned with cards that order a movement; any instruction not concerned with movement will be ignored and the player will remain on the CC/CH square.\n\n- Community Chest (2/16 cards):\n\n- Advance to GO\n\n- Go to JAIL\n\n- Chance (10/16 cards):\n\n- Advance to GO\n\n- Go to JAIL\n\n- Go to C1\n\n- Go to E3\n\n- Go to H2\n\n- Go to R1\n\n- Go to next R (railway company)\n\n- Go to next R\n\n- Go to next U (utility company)\n\n- Go back 3 squares.\n\nThe heart of this problem concerns the likelihood of visiting a particular square. That is, the probability of finishing at that square after a roll. For this reason it should be clear that, with the exception of G2J for which the probability of finishing on it is zero, the CH squares will have the lowest probabilities, as 5/8 request a movement to another square, and it is the final square that the player finishes at on each roll that we are interested in. We shall make no distinction between \"Just Visiting\" and being sent to JAIL, and we shall also ignore the rule about requiring a double to \"get out of jail\", assuming that they pay to get out on their next turn.\n\nBy starting at GO and numbering the squares sequentially from 00 to 39 we can concatenate these two-digit numbers to produce strings that correspond with sets of squares.\n\nStatistically it can be shown that the three most popular squares, in order, are JAIL (6.24%) = Square 10, E3 (3.18%) = Square 24, and GO (3.09%) = Square 00. So these three most popular squares can be listed with the six-digit modal string: 102400.\n\nIf, instead of using two 6-sided dice, two 4-sided dice are used, find the six-digit modal string.", "raw_html": "

In the game, Monopoly, the standard board is set up in the following way:

\n
\n\"0084_monopoly_board.png\"\n
\n

A player starts on the GO square and adds the scores on two 6-sided dice to determine the number of squares they advance in a clockwise direction. Without any further rules we would expect to visit each square with equal probability: 2.5%. However, landing on G2J (Go To Jail), CC (community chest), and CH (chance) changes this distribution.

\n

In addition to G2J, and one card from each of CC and CH, that orders the player to go directly to jail, if a player rolls three consecutive doubles, they do not advance the result of their 3rd roll. Instead they proceed directly to jail.

\n

At the beginning of the game, the CC and CH cards are shuffled. When a player lands on CC or CH they take a card from the top of the respective pile and, after following the instructions, it is returned to the bottom of the pile. There are sixteen cards in each pile, but for the purpose of this problem we are only concerned with cards that order a movement; any instruction not concerned with movement will be ignored and the player will remain on the CC/CH square.

\n

The heart of this problem concerns the likelihood of visiting a particular square. That is, the probability of finishing at that square after a roll. For this reason it should be clear that, with the exception of G2J for which the probability of finishing on it is zero, the CH squares will have the lowest probabilities, as 5/8 request a movement to another square, and it is the final square that the player finishes at on each roll that we are interested in. We shall make no distinction between \"Just Visiting\" and being sent to JAIL, and we shall also ignore the rule about requiring a double to \"get out of jail\", assuming that they pay to get out on their next turn.

\n

By starting at GO and numbering the squares sequentially from 00 to 39 we can concatenate these two-digit numbers to produce strings that correspond with sets of squares.

\n

Statistically it can be shown that the three most popular squares, in order, are JAIL (6.24%) = Square 10, E3 (3.18%) = Square 24, and GO (3.09%) = Square 00. So these three most popular squares can be listed with the six-digit modal string: 102400.

\n

If, instead of using two 6-sided dice, two 4-sided dice are used, find the six-digit modal string.

", "url": "https://projecteuler.net/problem=84", "answer": "101524"} {"id": 85, "problem": "By counting carefully it can be seen that a rectangular grid measuring $3$ by $2$ contains eighteen rectangles:\n\nAlthough there exists no rectangular grid that contains exactly two million rectangles, find the area of the grid with the nearest solution.", "raw_html": "

By counting carefully it can be seen that a rectangular grid measuring $3$ by $2$ contains eighteen rectangles:

\n
\n\"\"
\n

Although there exists no rectangular grid that contains exactly two million rectangles, find the area of the grid with the nearest solution.

", "url": "https://projecteuler.net/problem=85", "answer": "2772"} {"id": 86, "problem": "A spider, S, sits in one corner of a cuboid room, measuring $6$ by $5$ by $3$, and a fly, F, sits in the opposite corner. By travelling on the surfaces of the room the shortest \"straight line\" distance from S to F is $10$ and the path is shown on the diagram.\n\nHowever, there are up to three \"shortest\" path candidates for any given cuboid and the shortest route doesn't always have integer length.\n\nIt can be shown that there are exactly $2060$ distinct cuboids, ignoring rotations, with integer dimensions, up to a maximum size of $M$ by $M$ by $M$, for which the shortest route has integer length when $M = 100$. This is the least value of $M$ for which the number of solutions first exceeds two thousand; the number of solutions when $M = 99$ is $1975$.\n\nFind the least value of $M$ such that the number of solutions first exceeds one million.", "raw_html": "

A spider, S, sits in one corner of a cuboid room, measuring $6$ by $5$ by $3$, and a fly, F, sits in the opposite corner. By travelling on the surfaces of the room the shortest \"straight line\" distance from S to F is $10$ and the path is shown on the diagram.

\n
\n\"\"
\n

However, there are up to three \"shortest\" path candidates for any given cuboid and the shortest route doesn't always have integer length.

\n

It can be shown that there are exactly $2060$ distinct cuboids, ignoring rotations, with integer dimensions, up to a maximum size of $M$ by $M$ by $M$, for which the shortest route has integer length when $M = 100$. This is the least value of $M$ for which the number of solutions first exceeds two thousand; the number of solutions when $M = 99$ is $1975$.

\n

Find the least value of $M$ such that the number of solutions first exceeds one million.

", "url": "https://projecteuler.net/problem=86", "answer": "1818"} {"id": 87, "problem": "The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is $28$. In fact, there are exactly four numbers below fifty that can be expressed in such a way:\n\n$$\\begin{align}\n28 &= 2^2 + 2^3 + 2^4\\\\\n33 &= 3^2 + 2^3 + 2^4\\\\\n49 &= 5^2 + 2^3 + 2^4\\\\\n47 &= 2^2 + 3^3 + 2^4\n\\end{align}$$\nHow many numbers below fifty million can be expressed as the sum of a prime square, prime cube, and prime fourth power?", "raw_html": "

The smallest number expressible as the sum of a prime square, prime cube, and prime fourth power is $28$. In fact, there are exactly four numbers below fifty that can be expressed in such a way:

\n$$\\begin{align}\n28 &= 2^2 + 2^3 + 2^4\\\\\n33 &= 3^2 + 2^3 + 2^4\\\\\n49 &= 5^2 + 2^3 + 2^4\\\\\n47 &= 2^2 + 3^3 + 2^4\n\\end{align}$$\n

How many numbers below fifty million can be expressed as the sum of a prime square, prime cube, and prime fourth power?

", "url": "https://projecteuler.net/problem=87", "answer": "1097343"} {"id": 88, "problem": "A natural number, $N$, that can be written as the sum and product of a given set of at least two natural numbers, $\\{a_1, a_2, \\dots, a_k\\}$ is called a product-sum number: $N = a_1 + a_2 + \\cdots + a_k = a_1 \\times a_2 \\times \\cdots \\times a_k$.\n\nFor example, $6 = 1 + 2 + 3 = 1 \\times 2 \\times 3$.\n\nFor a given set of size, $k$, we shall call the smallest $N$ with this property a minimal product-sum number. The minimal product-sum numbers for sets of size, $k = 2, 3, 4, 5$, and $6$ are as follows.\n\n- $k=2$: $4 = 2 \\times 2 = 2 + 2$\n\n- $k=3$: $6 = 1 \\times 2 \\times 3 = 1 + 2 + 3$\n\n- $k=4$: $8 = 1 \\times 1 \\times 2 \\times 4 = 1 + 1 + 2 + 4$\n\n- $k=5$: $8 = 1 \\times 1 \\times 2 \\times 2 \\times 2 = 1 + 1 + 2 + 2 + 2$\n- $k=6$: $12 = 1 \\times 1 \\times 1 \\times 1 \\times 2 \\times 6 = 1 + 1 + 1 + 1 + 2 + 6$\n\nHence for $2 \\le k \\le 6$, the sum of all the minimal product-sum numbers is $4+6+8+12 = 30$; note that $8$ is only counted once in the sum.\n\nIn fact, as the complete set of minimal product-sum numbers for $2 \\le k \\le 12$ is $\\{4, 6, 8, 12, 15, 16\\}$, the sum is $61$.\n\nWhat is the sum of all the minimal product-sum numbers for $2 \\le k \\le 12000$?", "raw_html": "

A natural number, $N$, that can be written as the sum and product of a given set of at least two natural numbers, $\\{a_1, a_2, \\dots, a_k\\}$ is called a product-sum number: $N = a_1 + a_2 + \\cdots + a_k = a_1 \\times a_2 \\times \\cdots \\times a_k$.

\n

For example, $6 = 1 + 2 + 3 = 1 \\times 2 \\times 3$.

\n

For a given set of size, $k$, we shall call the smallest $N$ with this property a minimal product-sum number. The minimal product-sum numbers for sets of size, $k = 2, 3, 4, 5$, and $6$ are as follows.

\n\n

Hence for $2 \\le k \\le 6$, the sum of all the minimal product-sum numbers is $4+6+8+12 = 30$; note that $8$ is only counted once in the sum.

\n

In fact, as the complete set of minimal product-sum numbers for $2 \\le k \\le 12$ is $\\{4, 6, 8, 12, 15, 16\\}$, the sum is $61$.

\n

What is the sum of all the minimal product-sum numbers for $2 \\le k \\le 12000$?

", "url": "https://projecteuler.net/problem=88", "answer": "7587457"} {"id": 89, "problem": "For a number written in Roman numerals to be considered valid there are basic rules which must be followed. Even though the rules allow some numbers to be expressed in more than one way there is always a \"best\" way of writing a particular number.\n\nFor example, it would appear that there are at least six ways of writing the number sixteen:\n\nIIIIIIIIIIIIIIII\n\nVIIIIIIIIIII\n\nVVIIIIII\n\nXIIIIII\n\nVVVI\n\nXVI\n\nHowever, according to the rules only XIIIIII and XVI are valid, and the last example is considered to be the most efficient, as it uses the least number of numerals.\n\nThe 11K text file, roman.txt (right click and 'Save Link/Target As...'), contains one thousand numbers written in valid, but not necessarily minimal, Roman numerals; see About... Roman Numerals for the definitive rules for this problem.\n\nFind the number of characters saved by writing each of these in their minimal form.\n\nNote: You can assume that all the Roman numerals in the file contain no more than four consecutive identical units.", "raw_html": "

For a number written in Roman numerals to be considered valid there are basic rules which must be followed. Even though the rules allow some numbers to be expressed in more than one way there is always a \"best\" way of writing a particular number.

\n

For example, it would appear that there are at least six ways of writing the number sixteen:

\n

IIIIIIIIIIIIIIII
\nVIIIIIIIIIII
\nVVIIIIII
\nXIIIIII
\nVVVI
\nXVI

\n

However, according to the rules only XIIIIII and XVI are valid, and the last example is considered to be the most efficient, as it uses the least number of numerals.

\n

The 11K text file, roman.txt (right click and 'Save Link/Target As...'), contains one thousand numbers written in valid, but not necessarily minimal, Roman numerals; see About... Roman Numerals for the definitive rules for this problem.

\n

Find the number of characters saved by writing each of these in their minimal form.

\n

Note: You can assume that all the Roman numerals in the file contain no more than four consecutive identical units.

", "url": "https://projecteuler.net/problem=89", "answer": "743"} {"id": 90, "problem": "Each of the six faces on a cube has a different digit ($0$ to $9$) written on it; the same is done to a second cube. By placing the two cubes side-by-side in different positions we can form a variety of $2$-digit numbers.\n\nFor example, the square number $64$ could be formed:\n\nIn fact, by carefully choosing the digits on both cubes it is possible to display all of the square numbers below one-hundred: $01$, $04$, $09$, $16$, $25$, $36$, $49$, $64$, and $81$.\n\nFor example, one way this can be achieved is by placing $\\{0, 5, 6, 7, 8, 9\\}$ on one cube and $\\{1, 2, 3, 4, 8, 9\\}$ on the other cube.\n\nHowever, for this problem we shall allow the $6$ or $9$ to be turned upside-down so that an arrangement like $\\{0, 5, 6, 7, 8, 9\\}$ and $\\{1, 2, 3, 4, 6, 7\\}$ allows for all nine square numbers to be displayed; otherwise it would be impossible to obtain $09$.\n\nIn determining a distinct arrangement we are interested in the digits on each cube, not the order.\n\n- $\\{1, 2, 3, 4, 5, 6\\}$ is equivalent to $\\{3, 6, 4, 1, 2, 5\\}$\n\n- $\\{1, 2, 3, 4, 5, 6\\}$ is distinct from $\\{1, 2, 3, 4, 5, 9\\}$\n\nBut because we are allowing $6$ and $9$ to be reversed, the two distinct sets in the last example both represent the extended set $\\{1, 2, 3, 4, 5, 6, 9\\}$ for the purpose of forming $2$-digit numbers.\n\nHow many distinct arrangements of the two cubes allow for all of the square numbers to be displayed?", "raw_html": "

Each of the six faces on a cube has a different digit ($0$ to $9$) written on it; the same is done to a second cube. By placing the two cubes side-by-side in different positions we can form a variety of $2$-digit numbers.

\n\n

For example, the square number $64$ could be formed:

\n\n
\n\"\"
\n\n

In fact, by carefully choosing the digits on both cubes it is possible to display all of the square numbers below one-hundred: $01$, $04$, $09$, $16$, $25$, $36$, $49$, $64$, and $81$.

\n\n

For example, one way this can be achieved is by placing $\\{0, 5, 6, 7, 8, 9\\}$ on one cube and $\\{1, 2, 3, 4, 8, 9\\}$ on the other cube.

\n\n

However, for this problem we shall allow the $6$ or $9$ to be turned upside-down so that an arrangement like $\\{0, 5, 6, 7, 8, 9\\}$ and $\\{1, 2, 3, 4, 6, 7\\}$ allows for all nine square numbers to be displayed; otherwise it would be impossible to obtain $09$.

\n\n

In determining a distinct arrangement we are interested in the digits on each cube, not the order.

\n\n\n\n

But because we are allowing $6$ and $9$ to be reversed, the two distinct sets in the last example both represent the extended set $\\{1, 2, 3, 4, 5, 6, 9\\}$ for the purpose of forming $2$-digit numbers.

\n\n

How many distinct arrangements of the two cubes allow for all of the square numbers to be displayed?

", "url": "https://projecteuler.net/problem=90", "answer": "1217"} {"id": 91, "problem": "The points $P(x_1, y_1)$ and $Q(x_2, y_2)$ are plotted at integer co-ordinates and are joined to the origin, $O(0,0)$, to form $\\triangle OPQ$.\n\nThere are exactly fourteen triangles containing a right angle that can be formed when each co-ordinate lies between $0$ and $2$ inclusive; that is, $0 \\le x_1, y_1, x_2, y_2 \\le 2$.\n\nGiven that $0 \\le x_1, y_1, x_2, y_2 \\le 50$, how many right triangles can be formed?", "raw_html": "

The points $P(x_1, y_1)$ and $Q(x_2, y_2)$ are plotted at integer co-ordinates and are joined to the origin, $O(0,0)$, to form $\\triangle OPQ$.

\n\n
\n\"\"
\n\n

There are exactly fourteen triangles containing a right angle that can be formed when each co-ordinate lies between $0$ and $2$ inclusive; that is, $0 \\le x_1, y_1, x_2, y_2 \\le 2$.

\n\n
\n\"\"
\n\n

Given that $0 \\le x_1, y_1, x_2, y_2 \\le 50$, how many right triangles can be formed?

", "url": "https://projecteuler.net/problem=91", "answer": "14234"} {"id": 92, "problem": "A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.\n\nFor example,\n$$\\begin{align}\n&44 \\to 32 \\to 13 \\to 10 \\to \\mathbf 1 \\to \\mathbf 1\\\\\n&85 \\to \\mathbf{89} \\to 145 \\to 42 \\to 20 \\to 4 \\to 16 \\to 37 \\to 58 \\to \\mathbf{89}\n\\end{align}$$\n\nTherefore any chain that arrives at $1$ or $89$ will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at $1$ or $89$.\n\nHow many starting numbers below ten million will arrive at $89$?", "raw_html": "

A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before.

\n

For example,\n$$\\begin{align}\n&44 \\to 32 \\to 13 \\to 10 \\to \\mathbf 1 \\to \\mathbf 1\\\\\n&85 \\to \\mathbf{89} \\to 145 \\to 42 \\to 20 \\to 4 \\to 16 \\to 37 \\to 58 \\to \\mathbf{89}\n\\end{align}$$\n

Therefore any chain that arrives at $1$ or $89$ will become stuck in an endless loop. What is most amazing is that EVERY starting number will eventually arrive at $1$ or $89$.

\n

How many starting numbers below ten million will arrive at $89$?

", "url": "https://projecteuler.net/problem=92", "answer": "8581146"} {"id": 93, "problem": "By using each of the digits from the set, $\\{1, 2, 3, 4\\}$, exactly once, and making use of the four arithmetic operations ($+, -, \\times, /$) and brackets/parentheses, it is possible to form different positive integer targets.\n\nFor example,\n\n$$\\begin{align}\n8 &= (4 \\times (1 + 3)) / 2\\\\\n14 &= 4 \\times (3 + 1 / 2)\\\\\n19 &= 4 \\times (2 + 3) - 1\\\\\n36 &= 3 \\times 4 \\times (2 + 1)\n\\end{align}$$\nNote that concatenations of the digits, like $12 + 34$, are not allowed.\n\nUsing the set, $\\{1, 2, 3, 4\\}$, it is possible to obtain thirty-one different target numbers of which $36$ is the maximum, and each of the numbers $1$ to $28$ can be obtained before encountering the first non-expressible number.\n\nFind the set of four distinct digits, $a \\lt b \\lt c \\lt d$, for which the longest set of consecutive positive integers, $1$ to $n$, can be obtained, giving your answer as a string: abcd.", "raw_html": "

By using each of the digits from the set, $\\{1, 2, 3, 4\\}$, exactly once, and making use of the four arithmetic operations ($+, -, \\times, /$) and brackets/parentheses, it is possible to form different positive integer targets.

\n

For example,

\n$$\\begin{align}\n8 &= (4 \\times (1 + 3)) / 2\\\\\n14 &= 4 \\times (3 + 1 / 2)\\\\\n19 &= 4 \\times (2 + 3) - 1\\\\\n36 &= 3 \\times 4 \\times (2 + 1)\n\\end{align}$$\n

Note that concatenations of the digits, like $12 + 34$, are not allowed.

\n

Using the set, $\\{1, 2, 3, 4\\}$, it is possible to obtain thirty-one different target numbers of which $36$ is the maximum, and each of the numbers $1$ to $28$ can be obtained before encountering the first non-expressible number.

\n

Find the set of four distinct digits, $a \\lt b \\lt c \\lt d$, for which the longest set of consecutive positive integers, $1$ to $n$, can be obtained, giving your answer as a string: abcd.

", "url": "https://projecteuler.net/problem=93", "answer": "1258"} {"id": 94, "problem": "It is easily proved that no equilateral triangle exists with integral length sides and integral area. However, the almost equilateral triangle $5$-$5$-$6$ has an area of $12$ square units.\n\nWe shall define an almost equilateral triangle to be a triangle for which two sides are equal and the third differs by no more than one unit.\n\nFind the sum of the perimeters of all almost equilateral triangles with integral side lengths and area and whose perimeters do not exceed one billion ($1\\,000\\,000\\,000$).", "raw_html": "

It is easily proved that no equilateral triangle exists with integral length sides and integral area. However, the almost equilateral triangle $5$-$5$-$6$ has an area of $12$ square units.

\n

We shall define an almost equilateral triangle to be a triangle for which two sides are equal and the third differs by no more than one unit.

\n

Find the sum of the perimeters of all almost equilateral triangles with integral side lengths and area and whose perimeters do not exceed one billion ($1\\,000\\,000\\,000$).

", "url": "https://projecteuler.net/problem=94", "answer": "518408346"} {"id": 95, "problem": "The proper divisors of a number are all the divisors excluding the number itself. For example, the proper divisors of $28$ are $1$, $2$, $4$, $7$, and $14$. As the sum of these divisors is equal to $28$, we call it a perfect number.\n\nInterestingly the sum of the proper divisors of $220$ is $284$ and the sum of the proper divisors of $284$ is $220$, forming a chain of two numbers. For this reason, $220$ and $284$ are called an amicable pair.\n\nPerhaps less well known are longer chains. For example, starting with $12496$, we form a chain of five numbers:\n$$12496 \\to 14288 \\to 15472 \\to 14536 \\to 14264 (\\to 12496 \\to \\cdots)$$\n\nSince this chain returns to its starting point, it is called an amicable chain.\n\nFind the smallest member of the longest amicable chain with no element exceeding one million.", "raw_html": "

The proper divisors of a number are all the divisors excluding the number itself. For example, the proper divisors of $28$ are $1$, $2$, $4$, $7$, and $14$. As the sum of these divisors is equal to $28$, we call it a perfect number.

\n

Interestingly the sum of the proper divisors of $220$ is $284$ and the sum of the proper divisors of $284$ is $220$, forming a chain of two numbers. For this reason, $220$ and $284$ are called an amicable pair.

\n

Perhaps less well known are longer chains. For example, starting with $12496$, we form a chain of five numbers:\n$$12496 \\to 14288 \\to 15472 \\to 14536 \\to 14264 (\\to 12496 \\to \\cdots)$$

\n

Since this chain returns to its starting point, it is called an amicable chain.

\n

Find the smallest member of the longest amicable chain with no element exceeding one million.

", "url": "https://projecteuler.net/problem=95", "answer": "14316"} {"id": 96, "problem": "Su Doku (Japanese meaning number place) is the name given to a popular puzzle concept. Its origin is unclear, but credit must be attributed to Leonhard Euler who invented a similar, and much more difficult, puzzle idea called Latin Squares. The objective of Su Doku puzzles, however, is to replace the blanks (or zeros) in a 9 by 9 grid in such that each row, column, and 3 by 3 box contains each of the digits 1 to 9. Below is an example of a typical starting puzzle grid and its solution grid.\n\n\n\nA well constructed Su Doku puzzle has a unique solution and can be solved by logic, although it may be necessary to employ \"guess and test\" methods in order to eliminate options (there is much contested opinion over this). The complexity of the search determines the difficulty of the puzzle; the example above is considered easy because it can be solved by straight forward direct deduction.\n\nThe 6K text file, sudoku.txt (right click and 'Save Link/Target As...'), contains fifty different Su Doku puzzles ranging in difficulty, but all with unique solutions (the first puzzle in the file is the example above).\n\nBy solving all fifty puzzles find the sum of the 3-digit numbers found in the top left corner of each solution grid; for example, 483 is the 3-digit number found in the top left corner of the solution grid above.", "raw_html": "

Su Doku (Japanese meaning number place) is the name given to a popular puzzle concept. Its origin is unclear, but credit must be attributed to Leonhard Euler who invented a similar, and much more difficult, puzzle idea called Latin Squares. The objective of Su Doku puzzles, however, is to replace the blanks (or zeros) in a 9 by 9 grid in such that each row, column, and 3 by 3 box contains each of the digits 1 to 9. Below is an example of a typical starting puzzle grid and its solution grid.

\n
\n\"0096_1.png\"     \"0096_2.png\"\n
\n

A well constructed Su Doku puzzle has a unique solution and can be solved by logic, although it may be necessary to employ \"guess and test\" methods in order to eliminate options (there is much contested opinion over this). The complexity of the search determines the difficulty of the puzzle; the example above is considered easy because it can be solved by straight forward direct deduction.

\n

The 6K text file, sudoku.txt (right click and 'Save Link/Target As...'), contains fifty different Su Doku puzzles ranging in difficulty, but all with unique solutions (the first puzzle in the file is the example above).

\n

By solving all fifty puzzles find the sum of the 3-digit numbers found in the top left corner of each solution grid; for example, 483 is the 3-digit number found in the top left corner of the solution grid above.

", "url": "https://projecteuler.net/problem=96", "answer": "24702"} {"id": 97, "problem": "The first known prime found to exceed one million digits was discovered in 1999, and is a Mersenne prime of the form $2^{6972593} - 1$; it contains exactly $2\\,098\\,960$ digits. Subsequently other Mersenne primes, of the form $2^p - 1$, have been found which contain more digits.\n\nHowever, in 2004 there was found a massive non-Mersenne prime which contains $2\\,357\\,207$ digits: $28433 \\times 2^{7830457} + 1$.\n\nFind the last ten digits of this prime number.", "raw_html": "

The first known prime found to exceed one million digits was discovered in 1999, and is a Mersenne prime of the form $2^{6972593} - 1$; it contains exactly $2\\,098\\,960$ digits. Subsequently other Mersenne primes, of the form $2^p - 1$, have been found which contain more digits.

\n

However, in 2004 there was found a massive non-Mersenne prime which contains $2\\,357\\,207$ digits: $28433 \\times 2^{7830457} + 1$.

\n

Find the last ten digits of this prime number.

", "url": "https://projecteuler.net/problem=97", "answer": "8739992577"} {"id": 98, "problem": "By replacing each of the letters in the word CARE with $1$, $2$, $9$, and $6$ respectively, we form a square number: $1296 = 36^2$. What is remarkable is that, by using the same digital substitutions, the anagram, RACE, also forms a square number: $9216 = 96^2$. We shall call CARE (and RACE) a square anagram word pair and specify further that leading zeroes are not permitted, neither may a different letter have the same digital value as another letter.\n\nUsing words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, find all the square anagram word pairs (a palindromic word is NOT considered to be an anagram of itself).\n\nWhat is the largest square number formed by any member of such a pair?\n\nNOTE: All anagrams formed must be contained in the given text file.", "raw_html": "

By replacing each of the letters in the word CARE with $1$, $2$, $9$, and $6$ respectively, we form a square number: $1296 = 36^2$. What is remarkable is that, by using the same digital substitutions, the anagram, RACE, also forms a square number: $9216 = 96^2$. We shall call CARE (and RACE) a square anagram word pair and specify further that leading zeroes are not permitted, neither may a different letter have the same digital value as another letter.

\n

Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, find all the square anagram word pairs (a palindromic word is NOT considered to be an anagram of itself).

\n

What is the largest square number formed by any member of such a pair?

\n

NOTE: All anagrams formed must be contained in the given text file.

", "url": "https://projecteuler.net/problem=98", "answer": "18769"} {"id": 99, "problem": "Comparing two numbers written in index form like $2^{11}$ and $3^7$ is not difficult, as any calculator would confirm that $2^{11} = 2048 \\lt 3^7 = 2187$.\n\nHowever, confirming that $632382^{518061} \\gt 519432^{525806}$ would be much more difficult, as both numbers contain over three million digits.\n\nUsing base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.\n\nNOTE: The first two lines in the file represent the numbers in the example given above.", "raw_html": "

Comparing two numbers written in index form like $2^{11}$ and $3^7$ is not difficult, as any calculator would confirm that $2^{11} = 2048 \\lt 3^7 = 2187$.

\n

However, confirming that $632382^{518061} \\gt 519432^{525806}$ would be much more difficult, as both numbers contain over three million digits.

\n

Using base_exp.txt (right click and 'Save Link/Target As...'), a 22K text file containing one thousand lines with a base/exponent pair on each line, determine which line number has the greatest numerical value.

\n

NOTE: The first two lines in the file represent the numbers in the example given above.

", "url": "https://projecteuler.net/problem=99", "answer": "709"} {"id": 100, "problem": "If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, $P(\\text{BB}) = (15/21) \\times (14/20) = 1/2$.\n\nThe next such arrangement, for which there is exactly $50\\%$ chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.\n\nBy finding the first arrangement to contain over $10^{12} = 1\\,000\\,000\\,000\\,000$ discs in total, determine the number of blue discs that the box would contain.", "raw_html": "

If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, $P(\\text{BB}) = (15/21) \\times (14/20) = 1/2$.

\n

The next such arrangement, for which there is exactly $50\\%$ chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.

\n

By finding the first arrangement to contain over $10^{12} = 1\\,000\\,000\\,000\\,000$ discs in total, determine the number of blue discs that the box would contain.

", "url": "https://projecteuler.net/problem=100", "answer": "756872327473"} {"id": 101, "problem": "If we are presented with the first $k$ terms of a sequence it is impossible to say with certainty the value of the next term, as there are infinitely many polynomial functions that can model the sequence.\n\nAs an example, let us consider the sequence of cube numbers. This is defined by the generating function,\n$u_n = n^3$: $1, 8, 27, 64, 125, 216, \\dots$\n\nSuppose we were only given the first two terms of this sequence. Working on the principle that \"simple is best\" we should assume a linear relationship and predict the next term to be $15$ (common difference $7$). Even if we were presented with the first three terms, by the same principle of simplicity, a quadratic relationship should be assumed.\n\nWe shall define $\\operatorname{OP}(k, n)$ to be the $n$th term of the optimum polynomial generating function for the first $k$ terms of a sequence. It should be clear that $\\operatorname{OP}(k, n)$ will accurately generate the terms of the sequence for $n \\le k$, and potentially the first incorrect term (FIT) will be $\\operatorname{OP}(k, k+1)$; in which case we shall call it a bad OP (BOP).\n\nAs a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for $n \\ge 2$, $\\operatorname{OP}(1, n) = u_1$.\n\nHence we obtain the following $\\operatorname{OP}$s for the cubic sequence:\n\n| $\\operatorname{OP}(1, n) = 1$ | $1, {\\color{red}\\mathbf 1}, 1, 1, \\dots$ |\n| $\\operatorname{OP}(2, n) = 7n - 6$ | $1, 8, {\\color{red}\\mathbf{15}}, \\dots$ |\n| $\\operatorname{OP}(3, n) = 6n^2 - 11n + 6$ | $1, 8, 27, {\\color{red}\\mathbf{58}}, \\dots$ |\n| $\\operatorname{OP}(4, n) = n^3$ | $1, 8, 27, 64, 125, \\dots$ |\n\nClearly no BOPs exist for $k \\ge 4$.\n\nBy considering the sum of FITs generated by the BOPs (indicated in red above), we obtain $1 + 15 + 58 = 74$.\n\nConsider the following tenth degree polynomial generating function:\n$$u_n = 1 - n + n^2 - n^3 + n^4 - n^5 + n^6 - n^7 + n^8 - n^9 + n^{10}.$$\n\nFind the sum of FITs for the BOPs.", "raw_html": "

If we are presented with the first $k$ terms of a sequence it is impossible to say with certainty the value of the next term, as there are infinitely many polynomial functions that can model the sequence.

\n

As an example, let us consider the sequence of cube numbers. This is defined by the generating function,
$u_n = n^3$: $1, 8, 27, 64, 125, 216, \\dots$

\n

Suppose we were only given the first two terms of this sequence. Working on the principle that \"simple is best\" we should assume a linear relationship and predict the next term to be $15$ (common difference $7$). Even if we were presented with the first three terms, by the same principle of simplicity, a quadratic relationship should be assumed.

\n

We shall define $\\operatorname{OP}(k, n)$ to be the $n$th term of the optimum polynomial generating function for the first $k$ terms of a sequence. It should be clear that $\\operatorname{OP}(k, n)$ will accurately generate the terms of the sequence for $n \\le k$, and potentially the first incorrect term (FIT) will be $\\operatorname{OP}(k, k+1)$; in which case we shall call it a bad OP (BOP).

\n

As a basis, if we were only given the first term of sequence, it would be most sensible to assume constancy; that is, for $n \\ge 2$, $\\operatorname{OP}(1, n) = u_1$.

\n

Hence we obtain the following $\\operatorname{OP}$s for the cubic sequence:

\n
\n\n\n\n\n\n\n\n\n
$\\operatorname{OP}(1, n) = 1$$1, {\\color{red}\\mathbf 1}, 1, 1, \\dots$
$\\operatorname{OP}(2, n) = 7n - 6$$1, 8, {\\color{red}\\mathbf{15}}, \\dots$
$\\operatorname{OP}(3, n) = 6n^2 - 11n + 6$     $1, 8, 27, {\\color{red}\\mathbf{58}}, \\dots$
$\\operatorname{OP}(4, n) = n^3$$1, 8, 27, 64, 125, \\dots$
\n

Clearly no BOPs exist for $k \\ge 4$.

\n

By considering the sum of FITs generated by the BOPs (indicated in red above), we obtain $1 + 15 + 58 = 74$.

\n

Consider the following tenth degree polynomial generating function:\n$$u_n = 1 - n + n^2 - n^3 + n^4 - n^5 + n^6 - n^7 + n^8 - n^9 + n^{10}.$$

\n

Find the sum of FITs for the BOPs.

", "url": "https://projecteuler.net/problem=101", "answer": "37076114526"} {"id": 102, "problem": "Three distinct points are plotted at random on a Cartesian plane, for which $-1000 \\le x, y \\le 1000$, such that a triangle is formed.\n\nConsider the following two triangles:\n\n$$\\begin{gather}\nA(-340,495), B(-153,-910), C(835,-947)\\\\\nX(-175,41), Y(-421,-714), Z(574,-645)\n\\end{gather}$$\nIt can be verified that triangle $ABC$ contains the origin, whereas triangle $XYZ$ does not.\n\nUsing triangles.txt (right click and 'Save Link/Target As...'), a 27K text file containing the co-ordinates of one thousand \"random\" triangles, find the number of triangles for which the interior contains the origin.\n\nNOTE: The first two examples in the file represent the triangles in the example given above.", "raw_html": "

Three distinct points are plotted at random on a Cartesian plane, for which $-1000 \\le x, y \\le 1000$, such that a triangle is formed.

\n

Consider the following two triangles:

\n$$\\begin{gather}\nA(-340,495), B(-153,-910), C(835,-947)\\\\\nX(-175,41), Y(-421,-714), Z(574,-645)\n\\end{gather}$$\n

It can be verified that triangle $ABC$ contains the origin, whereas triangle $XYZ$ does not.

\n

Using triangles.txt (right click and 'Save Link/Target As...'), a 27K text file containing the co-ordinates of one thousand \"random\" triangles, find the number of triangles for which the interior contains the origin.

\n

NOTE: The first two examples in the file represent the triangles in the example given above.

", "url": "https://projecteuler.net/problem=102", "answer": "228"} {"id": 103, "problem": "Let $S(A)$ represent the sum of elements in set $A$ of size $n$. We shall call it a special sum set if for any two non-empty disjoint subsets, $B$ and $C$, the following properties are true:\n\n- $S(B) \\ne S(C)$; that is, sums of subsets cannot be equal.\n\n- If $B$ contains more elements than $C$ then $S(B) \\gt S(C)$.\n\nIf $S(A)$ is minimised for a given $n$, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.\n\n- $n = 1$: $\\{1\\}$\n\n- $n = 2$: $\\{1, 2\\}$\n\n- $n = 3$: $\\{2, 3, 4\\}$\n\n- $n = 4$: $\\{3, 5, 6, 7\\}$\n\n- $n = 5$: $\\{6, 9, 11, 12, 13\\}$\n\nIt seems that for a given optimum set, $A = \\{a_1, a_2, \\dots, a_n\\}$, the next optimum set is of the form $B = \\{b, a_1 + b, a_2 + b, \\dots, a_n + b\\}$, where $b$ is the \"middle\" element on the previous row.\n\nBy applying this \"rule\" we would expect the optimum set for $n = 6$ to be $A = \\{11, 17, 20, 22, 23, 24\\}$, with $S(A) = 117$. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for $n = 6$ is $A = \\{11, 18, 19, 20, 22, 25\\}$, with $S(A) = 115$ and corresponding set string: 111819202225.\n\nGiven that $A$ is an optimum special sum set for $n = 7$, find its set string.\n\nNOTE: This problem is related to Problem 105 and Problem 106.", "raw_html": "

Let $S(A)$ represent the sum of elements in set $A$ of size $n$. We shall call it a special sum set if for any two non-empty disjoint subsets, $B$ and $C$, the following properties are true:

\n
  1. $S(B) \\ne S(C)$; that is, sums of subsets cannot be equal.
  2. \n
  3. If $B$ contains more elements than $C$ then $S(B) \\gt S(C)$.
  4. \n

If $S(A)$ is minimised for a given $n$, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.

\n\n

It seems that for a given optimum set, $A = \\{a_1, a_2, \\dots, a_n\\}$, the next optimum set is of the form $B = \\{b, a_1 + b, a_2 + b, \\dots, a_n + b\\}$, where $b$ is the \"middle\" element on the previous row.

\n

By applying this \"rule\" we would expect the optimum set for $n = 6$ to be $A = \\{11, 17, 20, 22, 23, 24\\}$, with $S(A) = 117$. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for $n = 6$ is $A = \\{11, 18, 19, 20, 22, 25\\}$, with $S(A) = 115$ and corresponding set string: 111819202225.

\n

Given that $A$ is an optimum special sum set for $n = 7$, find its set string.

\n

NOTE: This problem is related to Problem 105 and Problem 106.

", "url": "https://projecteuler.net/problem=103", "answer": "20313839404245"} {"id": 104, "problem": "The Fibonacci sequence is defined by the recurrence relation:\n\n$F_n = F_{n - 1} + F_{n - 2}$, where $F_1 = 1$ and $F_2 = 1$.\nIt turns out that $F_{541}$, which contains $113$ digits, is the first Fibonacci number for which the last nine digits are $1$-$9$ pandigital (contain all the digits $1$ to $9$, but not necessarily in order). And $F_{2749}$, which contains $575$ digits, is the first Fibonacci number for which the first nine digits are $1$-$9$ pandigital.\n\nGiven that $F_k$ is the first Fibonacci number for which the first nine digits AND the last nine digits are $1$-$9$ pandigital, find $k$.", "raw_html": "

The Fibonacci sequence is defined by the recurrence relation:

\n
$F_n = F_{n - 1} + F_{n - 2}$, where $F_1 = 1$ and $F_2 = 1$.
\n

It turns out that $F_{541}$, which contains $113$ digits, is the first Fibonacci number for which the last nine digits are $1$-$9$ pandigital (contain all the digits $1$ to $9$, but not necessarily in order). And $F_{2749}$, which contains $575$ digits, is the first Fibonacci number for which the first nine digits are $1$-$9$ pandigital.

\n

Given that $F_k$ is the first Fibonacci number for which the first nine digits AND the last nine digits are $1$-$9$ pandigital, find $k$.

", "url": "https://projecteuler.net/problem=104", "answer": "329468"} {"id": 105, "problem": "Let $S(A)$ represent the sum of elements in set $A$ of size $n$. We shall call it a special sum set if for any two non-empty disjoint subsets, $B$ and $C$, the following properties are true:\n\n- $S(B) \\ne S(C)$; that is, sums of subsets cannot be equal.\n\n- If $B$ contains more elements than $C$ then $S(B) \\gt S(C)$.\n\nFor example, $\\{81, 88, 75, 42, 87, 84, 86, 65\\}$ is not a special sum set because $65 + 87 + 88 = 75 + 81 + 84$, whereas $\\{157, 150, 164, 119, 79, 159, 161, 139, 158\\}$ satisfies both rules for all possible subset pair combinations and $S(A) = 1286$.\n\nUsing sets.txt (right click and \"Save Link/Target As...\"), a 4K text file with one-hundred sets containing seven to twelve elements (the two examples given above are the first two sets in the file), identify all the special sum sets, $A_1, A_2, \\dots, A_k$, and find the value of $S(A_1) + S(A_2) + \\cdots + S(A_k)$.\n\nNOTE: This problem is related to Problem 103 and Problem 106.", "raw_html": "

Let $S(A)$ represent the sum of elements in set $A$ of size $n$. We shall call it a special sum set if for any two non-empty disjoint subsets, $B$ and $C$, the following properties are true:

\n
  1. $S(B) \\ne S(C)$; that is, sums of subsets cannot be equal.
  2. \n
  3. If $B$ contains more elements than $C$ then $S(B) \\gt S(C)$.
  4. \n

For example, $\\{81, 88, 75, 42, 87, 84, 86, 65\\}$ is not a special sum set because $65 + 87 + 88 = 75 + 81 + 84$, whereas $\\{157, 150, 164, 119, 79, 159, 161, 139, 158\\}$ satisfies both rules for all possible subset pair combinations and $S(A) = 1286$.

\n

Using sets.txt (right click and \"Save Link/Target As...\"), a 4K text file with one-hundred sets containing seven to twelve elements (the two examples given above are the first two sets in the file), identify all the special sum sets, $A_1, A_2, \\dots, A_k$, and find the value of $S(A_1) + S(A_2) + \\cdots + S(A_k)$.

\n

NOTE: This problem is related to Problem 103 and Problem 106.

", "url": "https://projecteuler.net/problem=105", "answer": "73702"} {"id": 106, "problem": "Let $S(A)$ represent the sum of elements in set $A$ of size $n$. We shall call it a special sum set if for any two non-empty disjoint subsets, $B$ and $C$, the following properties are true:\n\n- $S(B) \\ne S(C)$; that is, sums of subsets cannot be equal.\n\n- If $B$ contains more elements than $C$ then $S(B) \\gt S(C)$.\n\nFor this problem we shall assume that a given set contains $n$ strictly increasing elements and it already satisfies the second rule.\n\nSurprisingly, out of the $25$ possible subset pairs that can be obtained from a set for which $n = 4$, only $1$ of these pairs need to be tested for equality (first rule). Similarly, when $n = 7$, only $70$ out of the $966$ subset pairs need to be tested.\n\nFor $n = 12$, how many of the $261625$ subset pairs that can be obtained need to be tested for equality?\n\nNOTE: This problem is related to Problem 103 and Problem 105.", "raw_html": "

Let $S(A)$ represent the sum of elements in set $A$ of size $n$. We shall call it a special sum set if for any two non-empty disjoint subsets, $B$ and $C$, the following properties are true:

\n
  1. $S(B) \\ne S(C)$; that is, sums of subsets cannot be equal.
  2. \n
  3. If $B$ contains more elements than $C$ then $S(B) \\gt S(C)$.
  4. \n

For this problem we shall assume that a given set contains $n$ strictly increasing elements and it already satisfies the second rule.

\n

Surprisingly, out of the $25$ possible subset pairs that can be obtained from a set for which $n = 4$, only $1$ of these pairs need to be tested for equality (first rule). Similarly, when $n = 7$, only $70$ out of the $966$ subset pairs need to be tested.

\n

For $n = 12$, how many of the $261625$ subset pairs that can be obtained need to be tested for equality?

\n

NOTE: This problem is related to Problem 103 and Problem 105.

", "url": "https://projecteuler.net/problem=106", "answer": "21384"} {"id": 107, "problem": "The following undirected network consists of seven vertices and twelve edges with a total weight of 243.\n\nThe same network can be represented by the matrix below.\n\n| | A | B | C | D | E | F | G |\n| A | - | 16 | 12 | 21 | - | - | - |\n| B | 16 | - | - | 17 | 20 | - | - |\n| C | 12 | - | - | 28 | - | 31 | - |\n| D | 21 | 17 | 28 | - | 18 | 19 | 23 |\n| E | - | 20 | - | 18 | - | - | 11 |\n| F | - | - | 31 | 19 | - | - | 27 |\n| G | - | - | - | 23 | 11 | 27 | - |\n\nHowever, it is possible to optimise the network by removing some edges and still ensure that all points on the network remain connected. The network which achieves the maximum saving is shown below. It has a weight of 93, representing a saving of 243 − 93 = 150 from the original network.\n\nUsing network.txt (right click and 'Save Link/Target As...'), a 6K text file containing a network with forty vertices, and given in matrix form, find the maximum saving which can be achieved by removing redundant edges whilst ensuring that the network remains connected.", "raw_html": "

The following undirected network consists of seven vertices and twelve edges with a total weight of 243.

\n
\n\"\"
\n

The same network can be represented by the matrix below.

\n\n\n\n\n\n\n\n\n
    ABCDEFG
A-161221---
B16--1720--
C12--28-31-
D211728-181923
E-20-18--11
F--3119--27
G---231127-

However, it is possible to optimise the network by removing some edges and still ensure that all points on the network remain connected. The network which achieves the maximum saving is shown below. It has a weight of 93, representing a saving of 243 − 93 = 150 from the original network.

\n
\n\"\"
\n

Using network.txt (right click and 'Save Link/Target As...'), a 6K text file containing a network with forty vertices, and given in matrix form, find the maximum saving which can be achieved by removing redundant edges whilst ensuring that the network remains connected.

", "url": "https://projecteuler.net/problem=107", "answer": "259679"} {"id": 108, "problem": "In the following equation $x$, $y$, and $n$ are positive integers.\n\n$$\\dfrac{1}{x} + \\dfrac{1}{y} = \\dfrac{1}{n}$$\nFor $n = 4$ there are exactly three distinct solutions:\n\n$$\\begin{align}\n\\dfrac{1}{5} + \\dfrac{1}{20} &= \\dfrac{1}{4}\\\\\n\\dfrac{1}{6} + \\dfrac{1}{12} &= \\dfrac{1}{4}\\\\\n\\dfrac{1}{8} + \\dfrac{1}{8} &= \\dfrac{1}{4}\n\\end{align}\n$$\n\nWhat is the least value of $n$ for which the number of distinct solutions exceeds one-thousand?\n\nNOTE: This problem is an easier version of Problem 110; it is strongly advised that you solve this one first.", "raw_html": "

In the following equation $x$, $y$, and $n$ are positive integers.

\n$$\\dfrac{1}{x} + \\dfrac{1}{y} = \\dfrac{1}{n}$$\n

For $n = 4$ there are exactly three distinct solutions:

\n$$\\begin{align}\n\\dfrac{1}{5} + \\dfrac{1}{20} &= \\dfrac{1}{4}\\\\\n\\dfrac{1}{6} + \\dfrac{1}{12} &= \\dfrac{1}{4}\\\\\n\\dfrac{1}{8} + \\dfrac{1}{8} &= \\dfrac{1}{4}\n\\end{align}\n$$\n\n

What is the least value of $n$ for which the number of distinct solutions exceeds one-thousand?

\n

NOTE: This problem is an easier version of Problem 110; it is strongly advised that you solve this one first.

", "url": "https://projecteuler.net/problem=108", "answer": "180180"} {"id": 109, "problem": "In the game of darts a player throws three darts at a target board which is split into twenty equal sized sections numbered one to twenty.\n\nThe score of a dart is determined by the number of the region that the dart lands in. A dart landing outside the red/green outer ring scores zero. The black and cream regions inside this ring represent single scores. However, the red/green outer ring and middle ring score double and treble scores respectively.\n\nAt the centre of the board are two concentric circles called the bull region, or bulls-eye. The outer bull is worth 25 points and the inner bull is a double, worth 50 points.\n\nThere are many variations of rules but in the most popular game the players will begin with a score 301 or 501 and the first player to reduce their running total to zero is a winner. However, it is normal to play a \"doubles out\" system, which means that the player must land a double (including the double bulls-eye at the centre of the board) on their final dart to win; any other dart that would reduce their running total to one or lower means the score for that set of three darts is \"bust\".\n\nWhen a player is able to finish on their current score it is called a \"checkout\" and the highest checkout is 170: T20 T20 D25 (two treble 20s and double bull).\n\nThere are exactly eleven distinct ways to checkout on a score of 6:\n\n| | | |\n| D3 | | |\n| D1 | D2 | |\n| S2 | D2 | |\n| D2 | D1 | |\n| S4 | D1 | |\n| S1 | S1 | D2 |\n| S1 | T1 | D1 |\n| S1 | S3 | D1 |\n| D1 | D1 | D1 |\n| D1 | S2 | D1 |\n| S2 | S2 | D1 |\n\nNote that D1 D2 is considered different to D2 D1 as they finish on different doubles. However, the combination S1 T1 D1 is considered the same as T1 S1 D1.\n\nIn addition we shall not include misses in considering combinations; for example, D3 is the same as 0 D3 and 0 0 D3.\n\nIncredibly there are 42336 distinct ways of checking out in total.\n\nHow many distinct ways can a player checkout with a score less than 100?", "raw_html": "

In the game of darts a player throws three darts at a target board which is split into twenty equal sized sections numbered one to twenty.

\n
\n\"\"
\n

The score of a dart is determined by the number of the region that the dart lands in. A dart landing outside the red/green outer ring scores zero. The black and cream regions inside this ring represent single scores. However, the red/green outer ring and middle ring score double and treble scores respectively.

\n

At the centre of the board are two concentric circles called the bull region, or bulls-eye. The outer bull is worth 25 points and the inner bull is a double, worth 50 points.

\n

There are many variations of rules but in the most popular game the players will begin with a score 301 or 501 and the first player to reduce their running total to zero is a winner. However, it is normal to play a \"doubles out\" system, which means that the player must land a double (including the double bulls-eye at the centre of the board) on their final dart to win; any other dart that would reduce their running total to one or lower means the score for that set of three darts is \"bust\".

\n

When a player is able to finish on their current score it is called a \"checkout\" and the highest checkout is 170: T20 T20 D25 (two treble 20s and double bull).

\n

There are exactly eleven distinct ways to checkout on a score of 6:

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
               
D3
D1D2
S2D2
D2D1
S4D1
S1S1D2
S1T1D1
S1S3D1
D1D1D1
D1S2D1
S2S2D1
\n
\n

Note that D1 D2 is considered different to D2 D1 as they finish on different doubles. However, the combination S1 T1 D1 is considered the same as T1 S1 D1.

\n

In addition we shall not include misses in considering combinations; for example, D3 is the same as 0 D3 and 0 0 D3.

\n

Incredibly there are 42336 distinct ways of checking out in total.

\n

How many distinct ways can a player checkout with a score less than 100?

", "url": "https://projecteuler.net/problem=109", "answer": "38182"} {"id": 110, "problem": "In the following equation $x$, $y$, and $n$ are positive integers.\n\n$$\\dfrac{1}{x} + \\dfrac{1}{y} = \\dfrac{1}{n}$$\n\nIt can be verified that when $n = 1260$ there are $113$ distinct solutions and this is the least value of $n$ for which the total number of distinct solutions exceeds one hundred.\n\nWhat is the least value of $n$ for which the number of distinct solutions exceeds four million?\n\nNOTE: This problem is a much more difficult version of Problem 108 and as it is well beyond the limitations of a brute force approach it requires a clever implementation.", "raw_html": "

In the following equation $x$, $y$, and $n$ are positive integers.

\n

$$\\dfrac{1}{x} + \\dfrac{1}{y} = \\dfrac{1}{n}$$

\n\n

It can be verified that when $n = 1260$ there are $113$ distinct solutions and this is the least value of $n$ for which the total number of distinct solutions exceeds one hundred.

\n

What is the least value of $n$ for which the number of distinct solutions exceeds four million?

\n\n

NOTE: This problem is a much more difficult version of Problem 108 and as it is well beyond the limitations of a brute force approach it requires a clever implementation.

", "url": "https://projecteuler.net/problem=110", "answer": "9350130049860600"} {"id": 111, "problem": "Considering $4$-digit primes containing repeated digits it is clear that they cannot all be the same: $1111$ is divisible by $11$, $2222$ is divisible by $22$, and so on. But there are nine $4$-digit primes containing three ones:\n$$1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111.$$\n\nWe shall say that $M(n, d)$ represents the maximum number of repeated digits for an $n$-digit prime where $d$ is the repeated digit, $N(n, d)$ represents the number of such primes, and $S(n, d)$ represents the sum of these primes.\n\nSo $M(4, 1) = 3$ is the maximum number of repeated digits for a $4$-digit prime where one is the repeated digit, there are $N(4, 1) = 9$ such primes, and the sum of these primes is $S(4, 1) = 22275$. It turns out that for $d = 0$, it is only possible to have $M(4, 0) = 2$ repeated digits, but there are $N(4, 0) = 13$ such cases.\n\nIn the same way we obtain the following results for $4$-digit primes.\n\n| Digit, d | M(4, d) | N(4, d) | S(4, d) |\n| 0 | 2 | 13 | 67061 |\n| 1 | 3 | 9 | 22275 |\n| 2 | 3 | 1 | 2221 |\n| 3 | 3 | 12 | 46214 |\n| 4 | 3 | 2 | 8888 |\n| 5 | 3 | 1 | 5557 |\n| 6 | 3 | 1 | 6661 |\n| 7 | 3 | 9 | 57863 |\n| 8 | 3 | 1 | 8887 |\n| 9 | 3 | 7 | 48073 |\n\nFor $d = 0$ to $9$, the sum of all $S(4, d)$ is $273700$.\n\nFind the sum of all $S(10, d)$.", "raw_html": "

Considering $4$-digit primes containing repeated digits it is clear that they cannot all be the same: $1111$ is divisible by $11$, $2222$ is divisible by $22$, and so on. But there are nine $4$-digit primes containing three ones:\n$$1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111.$$

\n

We shall say that $M(n, d)$ represents the maximum number of repeated digits for an $n$-digit prime where $d$ is the repeated digit, $N(n, d)$ represents the number of such primes, and $S(n, d)$ represents the sum of these primes.

\n

So $M(4, 1) = 3$ is the maximum number of repeated digits for a $4$-digit prime where one is the repeated digit, there are $N(4, 1) = 9$ such primes, and the sum of these primes is $S(4, 1) = 22275$. It turns out that for $d = 0$, it is only possible to have $M(4, 0) = 2$ repeated digits, but there are $N(4, 0) = 13$ such cases.

\n

In the same way we obtain the following results for $4$-digit primes.

\n
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Digit, dM(4, d)N(4, d)S(4, d)
021367061
13922275
2312221
331246214
4328888
5315557
6316661
73957863
8318887
93748073
\n

For $d = 0$ to $9$, the sum of all $S(4, d)$ is $273700$.

\n

Find the sum of all $S(10, d)$.

", "url": "https://projecteuler.net/problem=111", "answer": "612407567715"} {"id": 112, "problem": "Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, $134468$.\n\nSimilarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, $66420$.\n\nWe shall call a positive integer that is neither increasing nor decreasing a \"bouncy\" number; for example, $155349$.\n\nClearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand ($525$) are bouncy. In fact, the least number for which the proportion of bouncy numbers first reaches $50\\%$ is $538$.\n\nSurprisingly, bouncy numbers become more and more common and by the time we reach $21780$ the proportion of bouncy numbers is equal to $90\\%$.\n\nFind the least number for which the proportion of bouncy numbers is exactly $99\\%$.", "raw_html": "

Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, $134468$.

\n

Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, $66420$.

\n

We shall call a positive integer that is neither increasing nor decreasing a \"bouncy\" number; for example, $155349$.

\n

Clearly there cannot be any bouncy numbers below one-hundred, but just over half of the numbers below one-thousand ($525$) are bouncy. In fact, the least number for which the proportion of bouncy numbers first reaches $50\\%$ is $538$.

\n

Surprisingly, bouncy numbers become more and more common and by the time we reach $21780$ the proportion of bouncy numbers is equal to $90\\%$.

\n

Find the least number for which the proportion of bouncy numbers is exactly $99\\%$.

", "url": "https://projecteuler.net/problem=112", "answer": "1587000"} {"id": 113, "problem": "Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, $134468$.\n\nSimilarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, $66420$.\n\nWe shall call a positive integer that is neither increasing nor decreasing a \"bouncy\" number; for example, $155349$.\n\nAs $n$ increases, the proportion of bouncy numbers below $n$ increases such that there are only $12951$ numbers below one-million that are not bouncy and only $277032$ non-bouncy numbers below $10^{10}$.\n\nHow many numbers below a googol ($10^{100}$) are not bouncy?", "raw_html": "

Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, $134468$.

\n

Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, $66420$.

\n

We shall call a positive integer that is neither increasing nor decreasing a \"bouncy\" number; for example, $155349$.

\n

As $n$ increases, the proportion of bouncy numbers below $n$ increases such that there are only $12951$ numbers below one-million that are not bouncy and only $277032$ non-bouncy numbers below $10^{10}$.

\n

How many numbers below a googol ($10^{100}$) are not bouncy?

", "url": "https://projecteuler.net/problem=113", "answer": "51161058134250"} {"id": 114, "problem": "A row measuring seven units in length has red blocks with a minimum length of three units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one grey square. There are exactly seventeen ways of doing this.\n\nHow many ways can a row measuring fifty units in length be filled?\n\nNOTE: Although the example above does not lend itself to the possibility, in general it is permitted to mix block sizes. For example, on a row measuring eight units in length you could use red (3), grey (1), and red (4).", "raw_html": "

A row measuring seven units in length has red blocks with a minimum length of three units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one grey square. There are exactly seventeen ways of doing this.

\n\n
\n\"0114.png\"\n
\n\n

How many ways can a row measuring fifty units in length be filled?

\n

NOTE: Although the example above does not lend itself to the possibility, in general it is permitted to mix block sizes. For example, on a row measuring eight units in length you could use red (3), grey (1), and red (4).

", "url": "https://projecteuler.net/problem=114", "answer": "16475640049"} {"id": 115, "problem": "NOTE: This is a more difficult version of Problem 114.\n\nA row measuring $n$ units in length has red blocks with a minimum length of $m$ units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.\n\nLet the fill-count function, $F(m, n)$, represent the number of ways that a row can be filled.\n\nFor example, $F(3, 29) = 673135$ and $F(3, 30) = 1089155$.\n\nThat is, for $m = 3$, it can be seen that $n = 30$ is the smallest value for which the fill-count function first exceeds one million.\n\nIn the same way, for $m = 10$, it can be verified that $F(10, 56) = 880711$ and $F(10, 57) = 1148904$, so $n = 57$ is the least value for which the fill-count function first exceeds one million.\n\nFor $m = 50$, find the least value of $n$ for which the fill-count function first exceeds one million.", "raw_html": "

NOTE: This is a more difficult version of Problem 114.

\n

A row measuring $n$ units in length has red blocks with a minimum length of $m$ units placed on it, such that any two red blocks (which are allowed to be different lengths) are separated by at least one black square.

\n

Let the fill-count function, $F(m, n)$, represent the number of ways that a row can be filled.

\n

For example, $F(3, 29) = 673135$ and $F(3, 30) = 1089155$.

\n

That is, for $m = 3$, it can be seen that $n = 30$ is the smallest value for which the fill-count function first exceeds one million.

\n

In the same way, for $m = 10$, it can be verified that $F(10, 56) = 880711$ and $F(10, 57) = 1148904$, so $n = 57$ is the least value for which the fill-count function first exceeds one million.

\n

For $m = 50$, find the least value of $n$ for which the fill-count function first exceeds one million.

", "url": "https://projecteuler.net/problem=115", "answer": "168"} {"id": 116, "problem": "A row of five grey square tiles is to have a number of its tiles replaced with coloured oblong tiles chosen from red (length two), green (length three), or blue (length four).\n\nIf red tiles are chosen there are exactly seven ways this can be done.\n\nIf green tiles are chosen there are three ways.\n\nAnd if blue tiles are chosen there are two ways.\n\nAssuming that colours cannot be mixed there are $7 + 3 + 2 = 12$ ways of replacing the grey tiles in a row measuring five units in length.\n\nHow many different ways can the grey tiles in a row measuring fifty units in length be replaced if colours cannot be mixed and at least one coloured tile must be used?\n\nNOTE: This is related to Problem 117.", "raw_html": "

A row of five grey square tiles is to have a number of its tiles replaced with coloured oblong tiles chosen from red (length two), green (length three), or blue (length four).

\n

If red tiles are chosen there are exactly seven ways this can be done.

\n\n
\n\"png116_1.png\"\n
\n\n

If green tiles are chosen there are three ways.

\n\n
\n\"png116_2.png\"\n
\n\n

And if blue tiles are chosen there are two ways.

\n\n
\n\"png116_3.png\"\n
\n\n

Assuming that colours cannot be mixed there are $7 + 3 + 2 = 12$ ways of replacing the grey tiles in a row measuring five units in length.

\n

How many different ways can the grey tiles in a row measuring fifty units in length be replaced if colours cannot be mixed and at least one coloured tile must be used?

\n

NOTE: This is related to Problem 117.

", "url": "https://projecteuler.net/problem=116", "answer": "20492570929"} {"id": 117, "problem": "Using a combination of grey square tiles and oblong tiles chosen from: red tiles (measuring two units), green tiles (measuring three units), and blue tiles (measuring four units), it is possible to tile a row measuring five units in length in exactly fifteen different ways.\n\nHow many ways can a row measuring fifty units in length be tiled?\n\nNOTE: This is related to Problem 116.", "raw_html": "

Using a combination of grey square tiles and oblong tiles chosen from: red tiles (measuring two units), green tiles (measuring three units), and blue tiles (measuring four units), it is possible to tile a row measuring five units in length in exactly fifteen different ways.

\n\n
\n\"png117.png\"\n
\n\n

How many ways can a row measuring fifty units in length be tiled?

\n

NOTE: This is related to Problem 116.

", "url": "https://projecteuler.net/problem=117", "answer": "100808458960497"} {"id": 118, "problem": "Using all of the digits $1$ through $9$ and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set $\\{2,5,47,89,631\\}$, all of the elements belonging to it are prime.\n\nHow many distinct sets containing each of the digits one through nine exactly once contain only prime elements?", "raw_html": "

Using all of the digits $1$ through $9$ and concatenating them freely to form decimal integers, different sets can be formed. Interestingly with the set $\\{2,5,47,89,631\\}$, all of the elements belonging to it are prime.

\n

How many distinct sets containing each of the digits one through nine exactly once contain only prime elements?

", "url": "https://projecteuler.net/problem=118", "answer": "44680"} {"id": 119, "problem": "The number $512$ is interesting because it is equal to the sum of its digits raised to some power: $5 + 1 + 2 = 8$, and $8^3 = 512$. Another example of a number with this property is $614656 = 28^4$.\n\nWe shall define $a_n$ to be the $n$th term of this sequence and insist that a number must contain at least two digits to have a sum.\n\nYou are given that $a_2 = 512$ and $a_{10} = 614656$.\n\nFind $a_{30}$.", "raw_html": "

The number $512$ is interesting because it is equal to the sum of its digits raised to some power: $5 + 1 + 2 = 8$, and $8^3 = 512$. Another example of a number with this property is $614656 = 28^4$.

\n

We shall define $a_n$ to be the $n$th term of this sequence and insist that a number must contain at least two digits to have a sum.

\n

You are given that $a_2 = 512$ and $a_{10} = 614656$.

\n

Find $a_{30}$.

", "url": "https://projecteuler.net/problem=119", "answer": "248155780267521"} {"id": 120, "problem": "Let $r$ be the remainder when $(a - 1)^n + (a + 1)^n$ is divided by $a^2$.\n\nFor example, if $a = 7$ and $n = 3$, then $r = 42$: $6^3 + 8^3 = 728 \\equiv 42 \\mod 49$. And as $n$ varies, so too will $r$, but for $a = 7$ it turns out that $r_{\\mathrm{max}} = 42$.\n\nFor $3 \\le a \\le 1000$, find $\\sum r_{\\mathrm{max}}$.", "raw_html": "

Let $r$ be the remainder when $(a - 1)^n + (a + 1)^n$ is divided by $a^2$.

\n

For example, if $a = 7$ and $n = 3$, then $r = 42$: $6^3 + 8^3 = 728 \\equiv 42 \\mod 49$. And as $n$ varies, so too will $r$, but for $a = 7$ it turns out that $r_{\\mathrm{max}} = 42$.

\n

For $3 \\le a \\le 1000$, find $\\sum r_{\\mathrm{max}}$.

", "url": "https://projecteuler.net/problem=120", "answer": "333082500"} {"id": 121, "problem": "A bag contains one red disc and one blue disc. In a game of chance a player takes a disc at random and its colour is noted. After each turn the disc is returned to the bag, an extra red disc is added, and another disc is taken at random.\n\nThe player pays £1 to play and wins if they have taken more blue discs than red discs at the end of the game.\n\nIf the game is played for four turns, the probability of a player winning is exactly 11/120, and so the maximum prize fund the banker should allocate for winning in this game would be £10 before they would expect to incur a loss. Note that any payout will be a whole number of pounds and also includes the original £1 paid to play the game, so in the example given the player actually wins £9.\n\nFind the maximum prize fund that should be allocated to a single game in which fifteen turns are played.", "raw_html": "

A bag contains one red disc and one blue disc. In a game of chance a player takes a disc at random and its colour is noted. After each turn the disc is returned to the bag, an extra red disc is added, and another disc is taken at random.

\n

The player pays £1 to play and wins if they have taken more blue discs than red discs at the end of the game.

\n

If the game is played for four turns, the probability of a player winning is exactly 11/120, and so the maximum prize fund the banker should allocate for winning in this game would be £10 before they would expect to incur a loss. Note that any payout will be a whole number of pounds and also includes the original £1 paid to play the game, so in the example given the player actually wins £9.

\n

Find the maximum prize fund that should be allocated to a single game in which fifteen turns are played.

", "url": "https://projecteuler.net/problem=121", "answer": "2269"} {"id": 122, "problem": "The most naive way of computing $n^{15}$ requires fourteen multiplications:\n$$n \\times n \\times \\cdots \\times n = n^{15}.$$\n\nBut using a \"binary\" method you can compute it in six multiplications:\n\n$$\\begin{align}\nn \\times n &= n^2\\\\\nn^2 \\times n^2 &= n^4\\\\\nn^4 \\times n^4 &= n^8\\\\\nn^8 \\times n^4 &= n^{12}\\\\\nn^{12} \\times n^2 &= n^{14}\\\\\nn^{14} \\times n &= n^{15}\n\\end{align}$$\nHowever it is yet possible to compute it in only five multiplications:\n\n$$\\begin{align}\nn \\times n &= n^2\\\\\nn^2 \\times n &= n^3\\\\\nn^3 \\times n^3 &= n^6\\\\\nn^6 \\times n^6 &= n^{12}\\\\\nn^{12} \\times n^3 &= n^{15}\n\\end{align}$$\nWe shall define $m(k)$ to be the minimum number of multiplications to compute $n^k$; for example $m(15) = 5$.\n\nFind $\\sum\\limits_{k = 1}^{200} m(k)$.", "raw_html": "

The most naive way of computing $n^{15}$ requires fourteen multiplications:\n$$n \\times n \\times \\cdots \\times n = n^{15}.$$

\n

But using a \"binary\" method you can compute it in six multiplications:

\n$$\\begin{align}\nn \\times n &= n^2\\\\\nn^2 \\times n^2 &= n^4\\\\\nn^4 \\times n^4 &= n^8\\\\\nn^8 \\times n^4 &= n^{12}\\\\\nn^{12} \\times n^2 &= n^{14}\\\\\nn^{14} \\times n &= n^{15}\n\\end{align}$$\n

However it is yet possible to compute it in only five multiplications:

\n$$\\begin{align}\nn \\times n &= n^2\\\\\nn^2 \\times n &= n^3\\\\\nn^3 \\times n^3 &= n^6\\\\\nn^6 \\times n^6 &= n^{12}\\\\\nn^{12} \\times n^3 &= n^{15}\n\\end{align}$$\n

We shall define $m(k)$ to be the minimum number of multiplications to compute $n^k$; for example $m(15) = 5$.

\n

Find $\\sum\\limits_{k = 1}^{200} m(k)$.

", "url": "https://projecteuler.net/problem=122", "answer": "1582"} {"id": 123, "problem": "Let $p_n$ be the $n$th prime: $2, 3, 5, 7, 11, \\dots$, and let $r$ be the remainder when $(p_n - 1)^n + (p_n + 1)^n$ is divided by $p_n^2$.\n\nFor example, when $n = 3$, $p_3 = 5$, and $4^3 + 6^3 = 280 \\equiv 5 \\mod 25$.\n\nThe least value of $n$ for which the remainder first exceeds $10^9$ is $7037$.\n\nFind the least value of $n$ for which the remainder first exceeds $10^{10}$.", "raw_html": "

Let $p_n$ be the $n$th prime: $2, 3, 5, 7, 11, \\dots$, and let $r$ be the remainder when $(p_n - 1)^n + (p_n + 1)^n$ is divided by $p_n^2$.

\n

For example, when $n = 3$, $p_3 = 5$, and $4^3 + 6^3 = 280 \\equiv 5 \\mod 25$.

\n

The least value of $n$ for which the remainder first exceeds $10^9$ is $7037$.

\n

Find the least value of $n$ for which the remainder first exceeds $10^{10}$.

", "url": "https://projecteuler.net/problem=123", "answer": "21035"} {"id": 124, "problem": "The radical of $n$, $\\operatorname{rad}(n)$, is the product of the distinct prime factors of $n$. For example, $504 = 2^3 \\times 3^2 \\times 7$, so $\\operatorname{rad}(504) = 2 \\times 3 \\times 7 = 42$.\n\nIf we calculate $\\operatorname{rad}(n)$ for $1 \\le n \\le 10$, then sort them on $\\operatorname{rad}(n)$, and sorting on $n$ if the radical values are equal, we get:\n\n| Unsorted | | Sorted |\n| --- | --- | --- |\n| n | rad(n) | | n | rad(n) | k |\n| 1 | 1 | | 1 | 1 | 1 |\n| 2 | 2 | | 2 | 2 | 2 |\n| 3 | 3 | | 4 | 2 | 3 |\n| 4 | 2 | | 8 | 2 | 4 |\n| 5 | 5 | | 3 | 3 | 5 |\n| 6 | 6 | | 9 | 3 | 6 |\n| 7 | 7 | | 5 | 5 | 7 |\n| 8 | 2 | | 6 | 6 | 8 |\n| 9 | 3 | | 7 | 7 | 9 |\n| 10 | 10 | | 10 | 10 | 10 |\n\nLet $E(k)$ be the $k$-th element in the sorted $n$ column; for example, $E(4) = 8$ and $E(6) = 9$.\n\nIf $\\operatorname{rad}(n)$ is sorted for $1 \\le n \\le 100000$, find $E(10000)$.", "raw_html": "

The radical of $n$, $\\operatorname{rad}(n)$, is the product of the distinct prime factors of $n$. For example, $504 = 2^3 \\times 3^2 \\times 7$, so $\\operatorname{rad}(504) = 2 \\times 3 \\times 7 = 42$.

\n

If we calculate $\\operatorname{rad}(n)$ for $1 \\le n \\le 10$, then sort them on $\\operatorname{rad}(n)$, and sorting on $n$ if the radical values are equal, we get:

\n\n\n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n\n \n \n \n\n
Unsorted Sorted
nrad(n) nrad(n)k
11 111
22 222
33 423
42 824
55 335
66 936
77 557
82 668
93 779
1010 101010
\n

Let $E(k)$ be the $k$-th element in the sorted $n$ column; for example, $E(4) = 8$ and $E(6) = 9$.

\n

If $\\operatorname{rad}(n)$ is sorted for $1 \\le n \\le 100000$, find $E(10000)$.

", "url": "https://projecteuler.net/problem=124", "answer": "21417"} {"id": 125, "problem": "The palindromic number $595$ is interesting because it can be written as the sum of consecutive squares: $6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2$.\n\nThere are exactly eleven palindromes below one-thousand that can be written as consecutive square sums, and the sum of these palindromes is $4164$. Note that $1 = 0^2 + 1^2$ has not been included as this problem is concerned with the squares of positive integers.\n\nFind the sum of all the numbers less than $10^8$ that are both palindromic and can be written as the sum of consecutive squares.", "raw_html": "

The palindromic number $595$ is interesting because it can be written as the sum of consecutive squares: $6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2$.

\n

There are exactly eleven palindromes below one-thousand that can be written as consecutive square sums, and the sum of these palindromes is $4164$. Note that $1 = 0^2 + 1^2$ has not been included as this problem is concerned with the squares of positive integers.

\n

Find the sum of all the numbers less than $10^8$ that are both palindromic and can be written as the sum of consecutive squares.

", "url": "https://projecteuler.net/problem=125", "answer": "2906969179"} {"id": 126, "problem": "The minimum number of cubes to cover every visible face on a cuboid measuring $3 \\times 2 \\times 1$ is twenty-two.\n\nIf we then add a second layer to this solid it would require forty-six cubes to cover every visible face, the third layer would require seventy-eight cubes, and the fourth layer would require one-hundred and eighteen cubes to cover every visible face.\n\nHowever, the first layer on a cuboid measuring $5 \\times 1 \\times 1$ also requires twenty-two cubes; similarly the first layer on cuboids measuring $5 \\times 3 \\times 1$, $7 \\times 2 \\times 1$, and $11 \\times 1 \\times 1$ all contain forty-six cubes.\n\nWe shall define $C(n)$ to represent the number of cuboids that contain $n$ cubes in one of its layers. So $C(22) = 2$, $C(46) = 4$, $C(78) = 5$, and $C(118) = 8$.\n\nIt turns out that $154$ is the least value of $n$ for which $C(n) = 10$.\n\nFind the least value of $n$ for which $C(n) = 1000$.", "raw_html": "

The minimum number of cubes to cover every visible face on a cuboid measuring $3 \\times 2 \\times 1$ is twenty-two.

\n
\n\"\"
\n

If we then add a second layer to this solid it would require forty-six cubes to cover every visible face, the third layer would require seventy-eight cubes, and the fourth layer would require one-hundred and eighteen cubes to cover every visible face.

\n

However, the first layer on a cuboid measuring $5 \\times 1 \\times 1$ also requires twenty-two cubes; similarly the first layer on cuboids measuring $5 \\times 3 \\times 1$, $7 \\times 2 \\times 1$, and $11 \\times 1 \\times 1$ all contain forty-six cubes.

\n

We shall define $C(n)$ to represent the number of cuboids that contain $n$ cubes in one of its layers. So $C(22) = 2$, $C(46) = 4$, $C(78) = 5$, and $C(118) = 8$.

\n

It turns out that $154$ is the least value of $n$ for which $C(n) = 10$.

\n

Find the least value of $n$ for which $C(n) = 1000$.

", "url": "https://projecteuler.net/problem=126", "answer": "18522"} {"id": 127, "problem": "The radical of $n$, $\\operatorname{rad}(n)$, is the product of distinct prime factors of $n$. For example, $504 = 2^3 \\times 3^2 \\times 7$, so $\\operatorname{rad}(504) = 2 \\times 3 \\times 7 = 42$.\n\nWe shall define the triplet of positive integers $(a, b, c)$ to be an abc-hit if:\n\n- $\\gcd(a, b) = \\gcd(a, c) = \\gcd(b, c) = 1$\n\n- $a \\lt b$\n\n- $a + b = c$\n\n- $\\operatorname{rad}(abc) \\lt c$\n\nFor example, $(5, 27, 32)$ is an abc-hit, because:\n\n- $\\gcd(5, 27) = \\gcd(5, 32) = \\gcd(27, 32) = 1$\n\n- $5 \\lt 27$\n\n- $5 + 27 = 32$\n\n- $\\operatorname{rad}(4320) = 30 \\lt 32$\n\nIt turns out that abc-hits are quite rare and there are only thirty-one abc-hits for $c \\lt 1000$, with $\\sum c = 12523$.\n\nFind $\\sum c$ for $c \\lt 120000$.", "raw_html": "

The radical of $n$, $\\operatorname{rad}(n)$, is the product of distinct prime factors of $n$. For example, $504 = 2^3 \\times 3^2 \\times 7$, so $\\operatorname{rad}(504) = 2 \\times 3 \\times 7 = 42$.

\n

We shall define the triplet of positive integers $(a, b, c)$ to be an abc-hit if:

\n
  1. $\\gcd(a, b) = \\gcd(a, c) = \\gcd(b, c) = 1$
  2. \n
  3. $a \\lt b$
  4. \n
  5. $a + b = c$
  6. \n
  7. $\\operatorname{rad}(abc) \\lt c$
  8. \n

For example, $(5, 27, 32)$ is an abc-hit, because:

\n
  1. $\\gcd(5, 27) = \\gcd(5, 32) = \\gcd(27, 32) = 1$
  2. \n
  3. $5 \\lt 27$
  4. \n
  5. $5 + 27 = 32$
  6. \n
  7. $\\operatorname{rad}(4320) = 30 \\lt 32$
  8. \n

It turns out that abc-hits are quite rare and there are only thirty-one abc-hits for $c \\lt 1000$, with $\\sum c = 12523$.

\n

Find $\\sum c$ for $c \\lt 120000$.

", "url": "https://projecteuler.net/problem=127", "answer": "18407904"} {"id": 128, "problem": "A hexagonal tile with number $1$ is surrounded by a ring of six hexagonal tiles, starting at \"12 o'clock\" and numbering the tiles $2$ to $7$ in an anti-clockwise direction.\n\nNew rings are added in the same fashion, with the next rings being numbered $8$ to $19$, $20$ to $37$, $38$ to $61$, and so on. The diagram below shows the first three rings.\n\nBy finding the difference between tile $n$ and each of its six neighbours we shall define $\\operatorname{PD}(n)$ to be the number of those differences which are prime.\n\nFor example, working clockwise around tile $8$ the differences are $12, 29, 11, 6, 1$, and $13$. So $\\operatorname{PD}(8) = 3$.\n\nIn the same way, the differences around tile $17$ are $1, 17, 16, 1, 11$, and $10$, hence $\\operatorname{PD}(17) = 2$.\n\nIt can be shown that the maximum value of $\\operatorname{PD}(n)$ is $3$.\n\nIf all of the tiles for which $\\operatorname{PD}(n) = 3$ are listed in ascending order to form a sequence, the $10$th tile would be $271$.\n\nFind the $2000$th tile in this sequence.", "raw_html": "

A hexagonal tile with number $1$ is surrounded by a ring of six hexagonal tiles, starting at \"12 o'clock\" and numbering the tiles $2$ to $7$ in an anti-clockwise direction.

\n

New rings are added in the same fashion, with the next rings being numbered $8$ to $19$, $20$ to $37$, $38$ to $61$, and so on. The diagram below shows the first three rings.

\n
\n\"\"
\n

By finding the difference between tile $n$ and each of its six neighbours we shall define $\\operatorname{PD}(n)$ to be the number of those differences which are prime.

\n

For example, working clockwise around tile $8$ the differences are $12, 29, 11, 6, 1$, and $13$. So $\\operatorname{PD}(8) = 3$.

\n

In the same way, the differences around tile $17$ are $1, 17, 16, 1, 11$, and $10$, hence $\\operatorname{PD}(17) = 2$.

\n

It can be shown that the maximum value of $\\operatorname{PD}(n)$ is $3$.

\n

If all of the tiles for which $\\operatorname{PD}(n) = 3$ are listed in ascending order to form a sequence, the $10$th tile would be $271$.

\n

Find the $2000$th tile in this sequence.

", "url": "https://projecteuler.net/problem=128", "answer": "14516824220"} {"id": 129, "problem": "A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$; for example, $R(6) = 111111$.\n\nGiven that $n$ is a positive integer and $\\gcd(n, 10) = 1$, it can be shown that there always exists a value, $k$, for which $R(k)$ is divisible by $n$, and let $A(n)$ be the least such value of $k$; for example, $A(7) = 6$ and $A(41) = 5$.\n\nThe least value of $n$ for which $A(n)$ first exceeds ten is $17$.\n\nFind the least value of $n$ for which $A(n)$ first exceeds one-million.", "raw_html": "

A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$; for example, $R(6) = 111111$.

\n

Given that $n$ is a positive integer and $\\gcd(n, 10) = 1$, it can be shown that there always exists a value, $k$, for which $R(k)$ is divisible by $n$, and let $A(n)$ be the least such value of $k$; for example, $A(7) = 6$ and $A(41) = 5$.

\n

The least value of $n$ for which $A(n)$ first exceeds ten is $17$.

\n

Find the least value of $n$ for which $A(n)$ first exceeds one-million.

", "url": "https://projecteuler.net/problem=129", "answer": "1000023"} {"id": 130, "problem": "A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$; for example, $R(6) = 111111$.\n\nGiven that $n$ is a positive integer and $\\gcd(n, 10) = 1$, it can be shown that there always exists a value, $k$, for which $R(k)$ is divisible by $n$, and let $A(n)$ be the least such value of $k$; for example, $A(7) = 6$ and $A(41) = 5$.\n\nYou are given that for all primes, $p \\gt 5$, that $p - 1$ is divisible by $A(p)$. For example, when $p = 41$, $A(41) = 5$, and $40$ is divisible by $5$.\n\nHowever, there are rare composite values for which this is also true; the first five examples being $91$, $259$, $451$, $481$, and $703$.\n\nFind the sum of the first twenty-five composite values of $n$ for which $\\gcd(n, 10) = 1$ and $n - 1$ is divisible by $A(n)$.", "raw_html": "

A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$; for example, $R(6) = 111111$.

\n

Given that $n$ is a positive integer and $\\gcd(n, 10) = 1$, it can be shown that there always exists a value, $k$, for which $R(k)$ is divisible by $n$, and let $A(n)$ be the least such value of $k$; for example, $A(7) = 6$ and $A(41) = 5$.

\n

You are given that for all primes, $p \\gt 5$, that $p - 1$ is divisible by $A(p)$. For example, when $p = 41$, $A(41) = 5$, and $40$ is divisible by $5$.

\n

However, there are rare composite values for which this is also true; the first five examples being $91$, $259$, $451$, $481$, and $703$.

\n

Find the sum of the first twenty-five composite values of $n$ for which $\\gcd(n, 10) = 1$ and $n - 1$ is divisible by $A(n)$.

", "url": "https://projecteuler.net/problem=130", "answer": "149253"} {"id": 131, "problem": "There are some prime values, $p$, for which there exists a positive integer, $n$, such that the expression $n^3 + n^2p$ is a perfect cube.\n\nFor example, when $p = 19$, $8^3 + 8^2 \\times 19 = 12^3$.\n\nWhat is perhaps most surprising is that for each prime with this property the value of $n$ is unique, and there are only four such primes below one-hundred.\n\nHow many primes below one million have this remarkable property?", "raw_html": "

There are some prime values, $p$, for which there exists a positive integer, $n$, such that the expression $n^3 + n^2p$ is a perfect cube.

\n

For example, when $p = 19$, $8^3 + 8^2 \\times 19 = 12^3$.

\n

What is perhaps most surprising is that for each prime with this property the value of $n$ is unique, and there are only four such primes below one-hundred.

\n

How many primes below one million have this remarkable property?

", "url": "https://projecteuler.net/problem=131", "answer": "173"} {"id": 132, "problem": "A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$.\n\nFor example, $R(10) = 1111111111 = 11 \\times 41 \\times 271 \\times 9091$, and the sum of these prime factors is $9414$.\n\nFind the sum of the first forty prime factors of $R(10^9)$.", "raw_html": "

A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$.

\n

For example, $R(10) = 1111111111 = 11 \\times 41 \\times 271 \\times 9091$, and the sum of these prime factors is $9414$.

\n

Find the sum of the first forty prime factors of $R(10^9)$.

", "url": "https://projecteuler.net/problem=132", "answer": "843296"} {"id": 133, "problem": "A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$; for example, $R(6) = 111111$.\n\nLet us consider repunits of the form $R(10^n)$.\n\nAlthough $R(10)$, $R(100)$, or $R(1000)$ are not divisible by $17$, $R(10000)$ is divisible by $17$. Yet there is no value of $n$ for which $R(10^n)$ will divide by $19$. In fact, it is remarkable that $11$, $17$, $41$, and $73$ are the only four primes below one-hundred that can be a factor of $R(10^n)$.\n\nFind the sum of all the primes below one-hundred thousand that will never be a factor of $R(10^n)$.", "raw_html": "

A number consisting entirely of ones is called a repunit. We shall define $R(k)$ to be a repunit of length $k$; for example, $R(6) = 111111$.

\n

Let us consider repunits of the form $R(10^n)$.

\n

Although $R(10)$, $R(100)$, or $R(1000)$ are not divisible by $17$, $R(10000)$ is divisible by $17$. Yet there is no value of $n$ for which $R(10^n)$ will divide by $19$. In fact, it is remarkable that $11$, $17$, $41$, and $73$ are the only four primes below one-hundred that can be a factor of $R(10^n)$.

\n

Find the sum of all the primes below one-hundred thousand that will never be a factor of $R(10^n)$.

", "url": "https://projecteuler.net/problem=133", "answer": "453647705"} {"id": 134, "problem": "Consider the consecutive primes $p_1 = 19$ and $p_2 = 23$. It can be verified that $1219$ is the smallest number such that the last digits are formed by $p_1$ whilst also being divisible by $p_2$.\n\nIn fact, with the exception of $p_1 = 3$ and $p_2 = 5$, for every pair of consecutive primes, $p_2 \\gt p_1$, there exist values of $n$ for which the last digits are formed by $p_1$ and $n$ is divisible by $p_2$. Let $S$ be the smallest of these values of $n$.\n\nFind $\\sum S$ for every pair of consecutive primes with $5 \\le p_1 \\le 1000000$.", "raw_html": "

Consider the consecutive primes $p_1 = 19$ and $p_2 = 23$. It can be verified that $1219$ is the smallest number such that the last digits are formed by $p_1$ whilst also being divisible by $p_2$.

\n

In fact, with the exception of $p_1 = 3$ and $p_2 = 5$, for every pair of consecutive primes, $p_2 \\gt p_1$, there exist values of $n$ for which the last digits are formed by $p_1$ and $n$ is divisible by $p_2$. Let $S$ be the smallest of these values of $n$.

\n

Find $\\sum S$ for every pair of consecutive primes with $5 \\le p_1 \\le 1000000$.

", "url": "https://projecteuler.net/problem=134", "answer": "18613426663617118"} {"id": 135, "problem": "Given the positive integers, $x$, $y$, and $z$, are consecutive terms of an arithmetic progression, the least value of the positive integer, $n$, for which the equation, $x^2 - y^2 - z^2 = n$, has exactly two solutions is $n = 27$:\n$$34^2 - 27^2 - 20^2 = 12^2 - 9^2 - 6^2 = 27.$$\n\nIt turns out that $n = 1155$ is the least value which has exactly ten solutions.\n\nHow many values of $n$ less than one million have exactly ten distinct solutions?", "raw_html": "

Given the positive integers, $x$, $y$, and $z$, are consecutive terms of an arithmetic progression, the least value of the positive integer, $n$, for which the equation, $x^2 - y^2 - z^2 = n$, has exactly two solutions is $n = 27$:\n$$34^2 - 27^2 - 20^2 = 12^2 - 9^2 - 6^2 = 27.$$

\n

It turns out that $n = 1155$ is the least value which has exactly ten solutions.

\n

How many values of $n$ less than one million have exactly ten distinct solutions?

", "url": "https://projecteuler.net/problem=135", "answer": "4989"} {"id": 136, "problem": "The positive integers, $x$, $y$, and $z$, are consecutive terms of an arithmetic progression. Given that $n$ is a positive integer, the equation, $x^2 - y^2 - z^2 = n$, has exactly one solution when $n = 20$:\n$$13^2 - 10^2 - 7^2 = 20.$$\n\nIn fact there are twenty-five values of $n$ below one hundred for which the equation has a unique solution.\n\nHow many values of $n$ less than fifty million have exactly one solution?", "raw_html": "

The positive integers, $x$, $y$, and $z$, are consecutive terms of an arithmetic progression. Given that $n$ is a positive integer, the equation, $x^2 - y^2 - z^2 = n$, has exactly one solution when $n = 20$:\n$$13^2 - 10^2 - 7^2 = 20.$$

\n

In fact there are twenty-five values of $n$ below one hundred for which the equation has a unique solution.

\n

How many values of $n$ less than fifty million have exactly one solution?

", "url": "https://projecteuler.net/problem=136", "answer": "2544559"} {"id": 137, "problem": "Consider the infinite polynomial series $A_F(x) = x F_1 + x^2 F_2 + x^3 F_3 + \\dots$, where $F_k$ is the $k$th term in the Fibonacci sequence: $1, 1, 2, 3, 5, 8, \\dots$; that is, $F_k = F_{k-1} + F_{k-2}$, $F_1 = 1$ and $F_2 = 1$.\n\nFor this problem we shall be interested in values of $x$ for which $A_F(x)$ is a positive integer.\n\n| Surprisingly | $\\begin{align*}\nA_F(\\tfrac{1}{2})\n&= (\\tfrac{1}{2})\\times 1 + (\\tfrac{1}{2})^2\\times 1 + (\\tfrac{1}{2})^3\\times 2 + (\\tfrac{1}{2})^4\\times 3 + (\\tfrac{1}{2})^5\\times 5 + \\cdots \\\\\n&= \\tfrac{1}{2} + \\tfrac{1}{4} + \\tfrac{2}{8} + \\tfrac{3}{16} + \\tfrac{5}{32} + \\cdots \\\\\n&= 2\n\\end{align*}$ |\n\nThe corresponding values of $x$ for the first five natural numbers are shown below.\n\n| $x$ | $A_F(x)$ |\n| --- | --- |\n| $\\sqrt{2}-1$ | $1$ |\n| $\\tfrac{1}{2}$ | $2$ |\n| $\\frac{\\sqrt{13}-2}{3}$ | $3$ |\n| $\\frac{\\sqrt{89}-5}{8}$ | $4$ |\n| $\\frac{\\sqrt{34}-3}{5}$ | $5$ |\n\nWe shall call $A_F(x)$ a golden nugget if $x$ is rational, because they become increasingly rarer; for example, the $10$th golden nugget is $74049690$.\n\nFind the $15$th golden nugget.", "raw_html": "

Consider the infinite polynomial series $A_F(x) = x F_1 + x^2 F_2 + x^3 F_3 + \\dots$, where $F_k$ is the $k$th term in the Fibonacci sequence: $1, 1, 2, 3, 5, 8, \\dots$; that is, $F_k = F_{k-1} + F_{k-2}$, $F_1 = 1$ and $F_2 = 1$.

\n

For this problem we shall be interested in values of $x$ for which $A_F(x)$ is a positive integer.

\n\n\n
Surprisingly$\\begin{align*} \nA_F(\\tfrac{1}{2})\n &= (\\tfrac{1}{2})\\times 1 + (\\tfrac{1}{2})^2\\times 1 + (\\tfrac{1}{2})^3\\times 2 + (\\tfrac{1}{2})^4\\times 3 + (\\tfrac{1}{2})^5\\times 5 + \\cdots \\\\ \n &= \\tfrac{1}{2} + \\tfrac{1}{4} + \\tfrac{2}{8} + \\tfrac{3}{16} + \\tfrac{5}{32} + \\cdots \\\\\n &= 2\n\\end{align*}$
\n\n

The corresponding values of $x$ for the first five natural numbers are shown below.

\n
\n\n\n\n\n\n\n
$x$$A_F(x)$
$\\sqrt{2}-1$$1$
$\\tfrac{1}{2}$$2$
$\\frac{\\sqrt{13}-2}{3}$$3$
$\\frac{\\sqrt{89}-5}{8}$$4$
$\\frac{\\sqrt{34}-3}{5}$$5$
\n

We shall call $A_F(x)$ a golden nugget if $x$ is rational, because they become increasingly rarer; for example, the $10$th golden nugget is $74049690$.

\n

Find the $15$th golden nugget.

", "url": "https://projecteuler.net/problem=137", "answer": "1120149658760"} {"id": 138, "problem": "Consider the isosceles triangle with base length, $b = 16$, and legs, $L = 17$.\n\nBy using the Pythagorean theorem it can be seen that the height of the triangle, $h = \\sqrt{17^2 - 8^2} = 15$, which is one less than the base length.\n\nWith $b = 272$ and $L = 305$, we get $h = 273$, which is one more than the base length, and this is the second smallest isosceles triangle with the property that $h = b \\pm 1$.\n\nFind $\\sum L$ for the twelve smallest isosceles triangles for which $h = b \\pm 1$ and $b$, $L$ are positive integers.", "raw_html": "

Consider the isosceles triangle with base length, $b = 16$, and legs, $L = 17$.

\n
\n\"\"
\n

By using the Pythagorean theorem it can be seen that the height of the triangle, $h = \\sqrt{17^2 - 8^2} = 15$, which is one less than the base length.

\n

With $b = 272$ and $L = 305$, we get $h = 273$, which is one more than the base length, and this is the second smallest isosceles triangle with the property that $h = b \\pm 1$.

\n

Find $\\sum L$ for the twelve smallest isosceles triangles for which $h = b \\pm 1$ and $b$, $L$ are positive integers.

", "url": "https://projecteuler.net/problem=138", "answer": "1118049290473932"} {"id": 139, "problem": "Let $(a, b, c)$ represent the three sides of a right angle triangle with integral length sides. It is possible to place four such triangles together to form a square with length $c$.\n\nFor example, $(3, 4, 5)$ triangles can be placed together to form a $5$ by $5$ square with a $1$ by $1$ hole in the middle and it can be seen that the $5$ by $5$ square can be tiled with twenty-five $1$ by $1$ squares.\n\nHowever, if $(5, 12, 13)$ triangles were used then the hole would measure $7$ by $7$ and these could not be used to tile the $13$ by $13$ square.\n\nGiven that the perimeter of the right triangle is less than one-hundred million, how many Pythagorean triangles would allow such a tiling to take place?", "raw_html": "

Let $(a, b, c)$ represent the three sides of a right angle triangle with integral length sides. It is possible to place four such triangles together to form a square with length $c$.

\n

For example, $(3, 4, 5)$ triangles can be placed together to form a $5$ by $5$ square with a $1$ by $1$ hole in the middle and it can be seen that the $5$ by $5$ square can be tiled with twenty-five $1$ by $1$ squares.

\n
\n\"\"
\n

However, if $(5, 12, 13)$ triangles were used then the hole would measure $7$ by $7$ and these could not be used to tile the $13$ by $13$ square.

\n

Given that the perimeter of the right triangle is less than one-hundred million, how many Pythagorean triangles would allow such a tiling to take place?

", "url": "https://projecteuler.net/problem=139", "answer": "10057761"} {"id": 140, "problem": "Consider the infinite polynomial series $A_G(x) = x G_1 + x^2 G_2 + x^3 G_3 + \\cdots$, where $G_k$ is the $k$th term of the second order recurrence relation $G_k = G_{k-1} + G_{k-2}$, $G_1 = 1$ and $G_2 = 4$; that is, $1, 4, 5, 9, 14, 23, \\dots$.\n\nFor this problem we shall be concerned with values of $x$ for which $A_G(x)$ is a positive integer.\n\nThe corresponding values of $x$ for the first five natural numbers are shown below.\n\n| $x$ | $A_G(x)$ |\n| --- | --- |\n| $\\frac{\\sqrt{5}-1}{4}$ | $1$ |\n| $\\tfrac{2}{5}$ | $2$ |\n| $\\frac{\\sqrt{22}-2}{6}$ | $3$ |\n| $\\frac{\\sqrt{137}-5}{14}$ | $4$ |\n| $\\tfrac{1}{2}$ | $5$ |\n\nWe shall call $A_G(x)$ a golden nugget if $x$ is rational, because they become increasingly rarer; for example, the $20$th golden nugget is $211345365$.\n\nFind the sum of the first thirty golden nuggets.", "raw_html": "

Consider the infinite polynomial series $A_G(x) = x G_1 + x^2 G_2 + x^3 G_3 + \\cdots$, where $G_k$ is the $k$th term of the second order recurrence relation $G_k = G_{k-1} + G_{k-2}$, $G_1 = 1$ and $G_2 = 4$; that is, $1, 4, 5, 9, 14, 23, \\dots$.

\n

For this problem we shall be concerned with values of $x$ for which $A_G(x)$ is a positive integer.

\n

The corresponding values of $x$ for the first five natural numbers are shown below.

\n
\n\n\n\n\n\n\n
$x$$A_G(x)$
$\\frac{\\sqrt{5}-1}{4}$$1$
$\\tfrac{2}{5}$$2$
$\\frac{\\sqrt{22}-2}{6}$$3$
$\\frac{\\sqrt{137}-5}{14}$$4$
$\\tfrac{1}{2}$$5$
\n

We shall call $A_G(x)$ a golden nugget if $x$ is rational, because they become increasingly rarer; for example, the $20$th golden nugget is $211345365$.

\n

Find the sum of the first thirty golden nuggets.

", "url": "https://projecteuler.net/problem=140", "answer": "5673835352990"} {"id": 141, "problem": "A positive integer, $n$, is divided by $d$ and the quotient and remainder are $q$ and $r$ respectively. In addition $d$, $q$, and $r$ are consecutive positive integer terms in a geometric sequence, but not necessarily in that order.\n\nFor example, $58$ divided by $6$ has quotient $9$ and remainder $4$. It can also be seen that $4, 6, 9$ are consecutive terms in a geometric sequence (common ratio $3/2$).\n\nWe will call such numbers, $n$, progressive.\n\nSome progressive numbers, such as $9$ and $10404 = 102^2$, happen to also be perfect squares.\nThe sum of all progressive perfect squares below one hundred thousand is $124657$.\n\nFind the sum of all progressive perfect squares below one trillion ($10^{12}$).", "raw_html": "

A positive integer, $n$, is divided by $d$ and the quotient and remainder are $q$ and $r$ respectively. In addition $d$, $q$, and $r$ are consecutive positive integer terms in a geometric sequence, but not necessarily in that order.

\n

For example, $58$ divided by $6$ has quotient $9$ and remainder $4$. It can also be seen that $4, 6, 9$ are consecutive terms in a geometric sequence (common ratio $3/2$).
\nWe will call such numbers, $n$, progressive.

\n

Some progressive numbers, such as $9$ and $10404 = 102^2$, happen to also be perfect squares.
The sum of all progressive perfect squares below one hundred thousand is $124657$.

\n

Find the sum of all progressive perfect squares below one trillion ($10^{12}$).

", "url": "https://projecteuler.net/problem=141", "answer": "878454337159"} {"id": 142, "problem": "Find the smallest $x + y + z$ with integers $x \\gt y \\gt z \\gt 0$ such that $x + y$, $x - y$, $x + z$, $x - z$, $y + z$, $y - z$ are all perfect squares.", "raw_html": "

Find the smallest $x + y + z$ with integers $x \\gt y \\gt z \\gt 0$ such that $x + y$, $x - y$, $x + z$, $x - z$, $y + z$, $y - z$ are all perfect squares.

", "url": "https://projecteuler.net/problem=142", "answer": "1006193"} {"id": 143, "problem": "Let $ABC$ be a triangle with all interior angles being less than $120$ degrees. Let $X$ be any point inside the triangle and let $XA = p$, $XC = q$, and $XB = r$.\n\nFermat challenged Torricelli to find the position of $X$ such that $p + q + r$ was minimised.\n\nTorricelli was able to prove that if equilateral triangles $AOB$, $BNC$ and $AMC$ are constructed on each side of triangle $ABC$, the circumscribed circles of $AOB$, $BNC$, and $AMC$ will intersect at a single point, $T$, inside the triangle. Moreover he proved that $T$, called the Torricelli/Fermat point, minimises $p + q + r$. Even more remarkable, it can be shown that when the sum is minimised, $AN = BM = CO = p + q + r$ and that $AN$, $BM$ and $CO$ also intersect at $T$.\n\nIf the sum is minimised and $a, b, c, p, q$ and $r$ are all positive integers we shall call triangle $ABC$ a Torricelli triangle. For example, $a = 399$, $b = 455$, $c = 511$ is an example of a Torricelli triangle, with $p + q + r = 784$.\n\nFind the sum of all distinct values of $p + q + r \\le 120000$ for Torricelli triangles.", "raw_html": "

Let $ABC$ be a triangle with all interior angles being less than $120$ degrees. Let $X$ be any point inside the triangle and let $XA = p$, $XC = q$, and $XB = r$.

\n

Fermat challenged Torricelli to find the position of $X$ such that $p + q + r$ was minimised.

\n

Torricelli was able to prove that if equilateral triangles $AOB$, $BNC$ and $AMC$ are constructed on each side of triangle $ABC$, the circumscribed circles of $AOB$, $BNC$, and $AMC$ will intersect at a single point, $T$, inside the triangle. Moreover he proved that $T$, called the Torricelli/Fermat point, minimises $p + q + r$. Even more remarkable, it can be shown that when the sum is minimised, $AN = BM = CO = p + q + r$ and that $AN$, $BM$ and $CO$ also intersect at $T$.

\n
\"\"
\n

If the sum is minimised and $a, b, c, p, q$ and $r$ are all positive integers we shall call triangle $ABC$ a Torricelli triangle. For example, $a = 399$, $b = 455$, $c = 511$ is an example of a Torricelli triangle, with $p + q + r = 784$.

\n

Find the sum of all distinct values of $p + q + r \\le 120000$ for Torricelli triangles.

", "url": "https://projecteuler.net/problem=143", "answer": "30758397"} {"id": 144, "problem": "In laser physics, a \"white cell\" is a mirror system that acts as a delay line for the laser beam. The beam enters the cell, bounces around on the mirrors, and eventually works its way back out.\n\nThe specific white cell we will be considering is an ellipse with the equation $4x^2 + y^2 = 100$.\n\nThe section corresponding to $-0.01 \\le x \\le +0.01$ at the top is missing, allowing the light to enter and exit through the hole.\n\nThe light beam in this problem starts at the point $(0.0,10.1)$ just outside the white cell, and the beam first impacts the mirror at $(1.4,-9.6)$.\n\nEach time the laser beam hits the surface of the ellipse, it follows the usual law of reflection \"angle of incidence equals angle of reflection.\" That is, both the incident and reflected beams make the same angle with the normal line at the point of incidence.\n\nIn the figure on the left, the red line shows the first two points of contact between the laser beam and the wall of the white cell; the blue line shows the line tangent to the ellipse at the point of incidence of the first bounce.\n\nThe slope $m$ of the tangent line at any point $(x,y)$ of the given ellipse is: $m = -4x/y$.\n\nThe normal line is perpendicular to this tangent line at the point of incidence.\n\nThe animation on the right shows the first $10$ reflections of the beam.\n\nHow many times does the beam hit the internal surface of the white cell before exiting?", "raw_html": "

In laser physics, a \"white cell\" is a mirror system that acts as a delay line for the laser beam. The beam enters the cell, bounces around on the mirrors, and eventually works its way back out.

\n

The specific white cell we will be considering is an ellipse with the equation $4x^2 + y^2 = 100$.

\n

The section corresponding to $-0.01 \\le x \\le +0.01$ at the top is missing, allowing the light to enter and exit through the hole.

\n
\"\"\"\"
\n

The light beam in this problem starts at the point $(0.0,10.1)$ just outside the white cell, and the beam first impacts the mirror at $(1.4,-9.6)$.

\n

Each time the laser beam hits the surface of the ellipse, it follows the usual law of reflection \"angle of incidence equals angle of reflection.\" That is, both the incident and reflected beams make the same angle with the normal line at the point of incidence.

\n

In the figure on the left, the red line shows the first two points of contact between the laser beam and the wall of the white cell; the blue line shows the line tangent to the ellipse at the point of incidence of the first bounce.

\n

The slope $m$ of the tangent line at any point $(x,y)$ of the given ellipse is: $m = -4x/y$.

The normal line is perpendicular to this tangent line at the point of incidence.

\n

The animation on the right shows the first $10$ reflections of the beam.

\n\n

How many times does the beam hit the internal surface of the white cell before exiting?

", "url": "https://projecteuler.net/problem=144", "answer": "354"} {"id": 145, "problem": "Some positive integers $n$ have the property that the sum $[n + \\operatorname{reverse}(n)]$ consists entirely of odd (decimal) digits. For instance, $36 + 63 = 99$ and $409 + 904 = 1313$. We will call such numbers reversible; so $36$, $63$, $409$, and $904$ are reversible. Leading zeroes are not allowed in either $n$ or $\\operatorname{reverse}(n)$.\n\nThere are $120$ reversible numbers below one-thousand.\n\nHow many reversible numbers are there below one-billion ($10^9$)?", "raw_html": "

Some positive integers $n$ have the property that the sum $[n + \\operatorname{reverse}(n)]$ consists entirely of odd (decimal) digits. For instance, $36 + 63 = 99$ and $409 + 904 = 1313$. We will call such numbers reversible; so $36$, $63$, $409$, and $904$ are reversible. Leading zeroes are not allowed in either $n$ or $\\operatorname{reverse}(n)$.

\n\n

There are $120$ reversible numbers below one-thousand.

\n\n

How many reversible numbers are there below one-billion ($10^9$)?

", "url": "https://projecteuler.net/problem=145", "answer": "608720"} {"id": 146, "problem": "The smallest positive integer $n$ for which the numbers $n^2 + 1$, $n^2 + 3$, $n^2 + 7$, $n^2 + 9$, $n^2 + 13$, and $n^2 + 27$ are consecutive primes is $10$. The sum of all such integers $n$ below one-million is $1242490$.\n\nWhat is the sum of all such integers $n$ below $150$ million?", "raw_html": "

The smallest positive integer $n$ for which the numbers $n^2 + 1$, $n^2 + 3$, $n^2 + 7$, $n^2 + 9$, $n^2 + 13$, and $n^2 + 27$ are consecutive primes is $10$. The sum of all such integers $n$ below one-million is $1242490$.

\n\n

What is the sum of all such integers $n$ below $150$ million?

", "url": "https://projecteuler.net/problem=146", "answer": "676333270"} {"id": 147, "problem": "In a $3 \\times 2$ cross-hatched grid, a total of $37$ different rectangles could be situated within that grid as indicated in the sketch.\n\nThere are $5$ grids smaller than $3 \\times 2$, vertical and horizontal dimensions being important, i.e. $1 \\times 1$, $2 \\times 1$, $3 \\times 1$, $1 \\times 2$ and $2 \\times 2$. If each of them is cross-hatched, the following number of different rectangles could be situated within those smaller grids:\n\n| $1 \\times 1$ | $1$ |\n| $2 \\times 1$ | $4$ |\n| $3 \\times 1$ | $8$ |\n| $1 \\times 2$ | $4$ |\n| $2 \\times 2$ | $18$ |\n\nAdding those to the $37$ of the $3 \\times 2$ grid, a total of $72$ different rectangles could be situated within $3 \\times 2$ and smaller grids.\n\nHow many different rectangles could be situated within $47 \\times 43$ and smaller grids?", "raw_html": "

In a $3 \\times 2$ cross-hatched grid, a total of $37$ different rectangles could be situated within that grid as indicated in the sketch.

\n
\"\"
\n

There are $5$ grids smaller than $3 \\times 2$, vertical and horizontal dimensions being important, i.e. $1 \\times 1$, $2 \\times 1$, $3 \\times 1$, $1 \\times 2$ and $2 \\times 2$. If each of them is cross-hatched, the following number of different rectangles could be situated within those smaller grids:

\n\n\n\n\n\n\n
$1 \\times 1$$1$
$2 \\times 1$$4$
$3 \\times 1$$8$
$1 \\times 2$$4$
$2 \\times 2$$18$
\n\n

Adding those to the $37$ of the $3 \\times 2$ grid, a total of $72$ different rectangles could be situated within $3 \\times 2$ and smaller grids.

\n\n

How many different rectangles could be situated within $47 \\times 43$ and smaller grids?

", "url": "https://projecteuler.net/problem=147", "answer": "846910284"} {"id": 148, "problem": "We can easily verify that none of the entries in the first seven rows of Pascal's triangle are divisible by $7$:\n\n| | | | | | | $1$ | | | | | | |\n| | | | | | $1$ | | $1$ | | | | | |\n| | | | | $1$ | | $2$ | | $1$ | | | | |\n| | | | $1$ | | $3$ | | $3$ | | $1$ | | | |\n| | | $1$ | | $4$ | | $6$ | | $4$ | | $1$ | | |\n| | $1$ | | $5$ | | $10$ | | $10$ | | $5$ | | $1$ | |\n| $1$ | | $6$ | | $15$ | | $20$ | | $15$ | | $6$ | | $1$ |\n\nHowever, if we check the first one hundred rows, we will find that only $2361$ of the $5050$ entries are not divisible by $7$.\n\nFind the number of entries which are not divisible by $7$ in the first one billion ($10^9$) rows of Pascal's triangle.", "raw_html": "

We can easily verify that none of the entries in the first seven rows of Pascal's triangle are divisible by $7$:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$1$
$1$$1$
$1$$2$$1$
$1$$3$$3$$1$
$1$$4$$6$$4$$1$
$1$$5$$10$$10$$5$$1$
$1$$6$$15$$20$$15$$6$$1$
\n\n\n

However, if we check the first one hundred rows, we will find that only $2361$ of the $5050$ entries are not divisible by $7$.

\n\n

Find the number of entries which are not divisible by $7$ in the first one billion ($10^9$) rows of Pascal's triangle.

", "url": "https://projecteuler.net/problem=148", "answer": "2129970655314432"} {"id": 149, "problem": "Looking at the table below, it is easy to verify that the maximum possible sum of adjacent numbers in any direction (horizontal, vertical, diagonal or anti-diagonal) is $16$ ($= 8 + 7 + 1$).\n\n| $-2$ | $5$ | $3$ | $2$ |\n| $9$ | $-6$ | $5$ | $1$ |\n| $3$ | $2$ | $7$ | $3$ |\n| $-1$ | $8$ | $-4$ | $8$ |\n\nNow, let us repeat the search, but on a much larger scale:\n\nFirst, generate four million pseudo-random numbers using a specific form of what is known as a \"Lagged Fibonacci Generator\":\n\nFor $1 \\le k \\le 55$, $s_k = [100003 - 200003 k + 300007 k^3] \\pmod{1000000} - 500000$.\n\nFor $56 \\le k \\le 4000000$, $s_k = [s_{k-24} + s_{k - 55} + 1000000] \\pmod{1000000} - 500000$.\n\nThus, $s_{10} = -393027$ and $s_{100} = 86613$.\n\nThe terms of $s$ are then arranged in a $2000 \\times 2000$ table, using the first $2000$ numbers to fill the first row (sequentially), the next $2000$ numbers to fill the second row, and so on.\n\nFinally, find the greatest sum of (any number of) adjacent entries in any direction (horizontal, vertical, diagonal or anti-diagonal).", "raw_html": "

Looking at the table below, it is easy to verify that the maximum possible sum of adjacent numbers in any direction (horizontal, vertical, diagonal or anti-diagonal) is $16$ ($= 8 + 7 + 1$).

\n\n
\n
$-2$$5$$3$$2$
$9$$-6$$5$$1$
$3$$2$$7$$3$
$-1$$8$$-4$$8$
\n\n

Now, let us repeat the search, but on a much larger scale:

\n\n

First, generate four million pseudo-random numbers using a specific form of what is known as a \"Lagged Fibonacci Generator\":

\n\n

For $1 \\le k \\le 55$, $s_k = [100003 - 200003 k + 300007 k^3] \\pmod{1000000} - 500000$.
\nFor $56 \\le k \\le 4000000$, $s_k = [s_{k-24} + s_{k - 55} + 1000000] \\pmod{1000000} - 500000$.

\n\n

Thus, $s_{10} = -393027$ and $s_{100} = 86613$.

\n\n

The terms of $s$ are then arranged in a $2000 \\times 2000$ table, using the first $2000$ numbers to fill the first row (sequentially), the next $2000$ numbers to fill the second row, and so on.

\n\n

Finally, find the greatest sum of (any number of) adjacent entries in any direction (horizontal, vertical, diagonal or anti-diagonal).

", "url": "https://projecteuler.net/problem=149", "answer": "52852124"} {"id": 150, "problem": "In a triangular array of positive and negative integers, we wish to find a sub-triangle such that the sum of the numbers it contains is the smallest possible.\n\nIn the example below, it can be easily verified that the marked triangle satisfies this condition having a sum of −42.\n\nWe wish to make such a triangular array with one thousand rows, so we generate 500500 pseudo-random numbers sk in the range ±219, using a type of random number generator (known as a Linear Congruential Generator) as follows:\n\nt := 0\n\nfor k = 1 up to k = 500500:\n\nt := (615949*t + 797807) modulo 220\n\nsk := t−219\n\nThus: s1 = 273519, s2 = −153582, s3 = 450905 etc\n\nOur triangular array is then formed using the pseudo-random numbers thus:\n\ns1\n\ns2  s3\n\ns4  s5  s6\n\ns7  s8  s9  s10\n\n...\n\nSub-triangles can start at any element of the array and extend down as far as we like (taking-in the two elements directly below it from the next row, the three elements directly below from the row after that, and so on).\n\nThe \"sum of a sub-triangle\" is defined as the sum of all the elements it contains.\n\nFind the smallest possible sub-triangle sum.", "raw_html": "

In a triangular array of positive and negative integers, we wish to find a sub-triangle such that the sum of the numbers it contains is the smallest possible.

\n

In the example below, it can be easily verified that the marked triangle satisfies this condition having a sum of −42.

\n
\n\"\"
\n

We wish to make such a triangular array with one thousand rows, so we generate 500500 pseudo-random numbers sk in the range ±219, using a type of random number generator (known as a Linear Congruential Generator) as follows:

\n

t := 0\n
\nfor k = 1 up to k = 500500:\n
\n    t := (615949*t + 797807) modulo 220
\n    sk := t−219

\n

Thus: s1 = 273519, s2 = −153582, s3 = 450905 etc

\n

Our triangular array is then formed using the pseudo-random numbers thus:

\n
\ns1
\ns2  s3
\ns4  s5  s6  \n
\ns7  s8  s9  s10
\n...\n
\n

Sub-triangles can start at any element of the array and extend down as far as we like (taking-in the two elements directly below it from the next row, the three elements directly below from the row after that, and so on).\n
\nThe \"sum of a sub-triangle\" is defined as the sum of all the elements it contains.\n
\nFind the smallest possible sub-triangle sum.

", "url": "https://projecteuler.net/problem=150", "answer": "-271248680"} {"id": 151, "problem": "A printing shop runs 16 batches (jobs) every week and each batch requires a sheet of special colour-proofing paper of size A5.\n\nEvery Monday morning, the supervisor opens a new envelope, containing a large sheet of the special paper with size A1.\n\nThe supervisor proceeds to cut it in half, thus getting two sheets of size A2. Then one of the sheets is cut in half to get two sheets of size A3 and so on until an A5-size sheet is obtained, which is needed for the first batch of the week.\n\nAll the unused sheets are placed back in the envelope.\n\nAt the beginning of each subsequent batch, the supervisor takes from the envelope one sheet of paper at random. If it is of size A5, then it is used. If it is larger, then the 'cut-in-half' procedure is repeated until an A5-size sheet is obtained, and any remaining sheets are always placed back in the envelope.\n\nExcluding the first and last batch of the week, find the expected number of times (during each week) that the supervisor finds a single sheet of paper in the envelope.\n\nGive your answer rounded to six decimal places using the format x.xxxxxx .", "raw_html": "

A printing shop runs 16 batches (jobs) every week and each batch requires a sheet of special colour-proofing paper of size A5.

\n\n

Every Monday morning, the supervisor opens a new envelope, containing a large sheet of the special paper with size A1.

\n\n

The supervisor proceeds to cut it in half, thus getting two sheets of size A2. Then one of the sheets is cut in half to get two sheets of size A3 and so on until an A5-size sheet is obtained, which is needed for the first batch of the week.

\n\n

All the unused sheets are placed back in the envelope.

\n\n
\"\"
\n\n

At the beginning of each subsequent batch, the supervisor takes from the envelope one sheet of paper at random. If it is of size A5, then it is used. If it is larger, then the 'cut-in-half' procedure is repeated until an A5-size sheet is obtained, and any remaining sheets are always placed back in the envelope.

\n\n

Excluding the first and last batch of the week, find the expected number of times (during each week) that the supervisor finds a single sheet of paper in the envelope.

\n\n

Give your answer rounded to six decimal places using the format x.xxxxxx .

", "url": "https://projecteuler.net/problem=151", "answer": "0.464399"} {"id": 152, "problem": "There are several ways to write the number $\\dfrac{1}{2}$ as a sum of square reciprocals using distinct integers.\n\nFor instance, the numbers $\\{2,3,4,5,7,12,15,20,28,35\\}$ can be used:\n\n$$\\begin{align}\\dfrac{1}{2} &= \\dfrac{1}{2^2} + \\dfrac{1}{3^2} + \\dfrac{1}{4^2} + \\dfrac{1}{5^2} +\\\\\n&\\quad \\dfrac{1}{7^2} + \\dfrac{1}{12^2} + \\dfrac{1}{15^2} + \\dfrac{1}{20^2} +\\\\\n&\\quad \\dfrac{1}{28^2} + \\dfrac{1}{35^2}\\end{align}$$\n\nIn fact, only using integers between $2$ and $45$ inclusive, there are exactly three ways to do it, the remaining two being: $\\{2,3,4,6,7,9,10,20,28,35,36,45\\}$ and $\\{2,3,4,6,7,9,12,15,28,30,35,36,45\\}$.\n\nHow many ways are there to write $\\dfrac{1}{2}$ as a sum of reciprocals of squares using distinct integers between $2$ and $80$ inclusive?", "raw_html": "

There are several ways to write the number $\\dfrac{1}{2}$ as a sum of square reciprocals using distinct integers.

\n

For instance, the numbers $\\{2,3,4,5,7,12,15,20,28,35\\}$ can be used:

\n

$$\\begin{align}\\dfrac{1}{2} &= \\dfrac{1}{2^2} + \\dfrac{1}{3^2} + \\dfrac{1}{4^2} + \\dfrac{1}{5^2} +\\\\\n&\\quad \\dfrac{1}{7^2} + \\dfrac{1}{12^2} + \\dfrac{1}{15^2} + \\dfrac{1}{20^2} +\\\\\n&\\quad \\dfrac{1}{28^2} + \\dfrac{1}{35^2}\\end{align}$$

\n

In fact, only using integers between $2$ and $45$ inclusive, there are exactly three ways to do it, the remaining two being: $\\{2,3,4,6,7,9,10,20,28,35,36,45\\}$ and $\\{2,3,4,6,7,9,12,15,28,30,35,36,45\\}$.

\n

How many ways are there to write $\\dfrac{1}{2}$ as a sum of reciprocals of squares using distinct integers between $2$ and $80$ inclusive?

", "url": "https://projecteuler.net/problem=152", "answer": "301"} {"id": 153, "problem": "As we all know the equation $x^2=-1$ has no solutions for real $x$.\n\nIf we however introduce the imaginary number $i$ this equation has two solutions: $x=i$ and $x=-i$.\n\nIf we go a step further the equation $(x-3)^2=-4$ has two complex solutions: $x=3+2i$ and $x=3-2i$.\n\n$x=3+2i$ and $x=3-2i$ are called each others' complex conjugate.\n\nNumbers of the form $a+bi$ are called complex numbers.\n\nIn general $a+bi$ and $a-bi$ are each other's complex conjugate.\n\nA Gaussian Integer is a complex number $a+bi$ such that both $a$ and $b$ are integers.\n\nThe regular integers are also Gaussian integers (with $b=0$).\n\nTo distinguish them from Gaussian integers with $b \\ne 0$ we call such integers \"rational integers.\"\n\nA Gaussian integer $a+bi$ is called a divisor of a rational integer $n$ if the result $\\dfrac n {a + bi}$ is also a Gaussian integer.\n\nIf for example we divide $5$ by $1+2i$ we can simplify $\\dfrac{5}{1 + 2i}$ in the following manner:\n\nMultiply numerator and denominator by the complex conjugate of $1+2i$: $1-2i$.\n\nThe result is $\\dfrac{5}{1 + 2i} = \\dfrac{5}{1 + 2i}\\dfrac{1 - 2i}{1 - 2i} = \\dfrac{5(1 - 2i)}{1 - (2i)^2} = \\dfrac{5(1 - 2i)}{1 - (-4)} = \\dfrac{5(1 - 2i)}{5} = 1 - 2i$.\n\nSo $1+2i$ is a divisor of $5$.\n\nNote that $1+i$ is not a divisor of $5$ because $\\dfrac{5}{1 + i} = \\dfrac{5}{2} - \\dfrac{5}{2}i$.\n\nNote also that if the Gaussian Integer $(a+bi)$ is a divisor of a rational integer $n$, then its complex conjugate $(a-bi)$ is also a divisor of $n$.\n\nIn fact, $5$ has six divisors such that the real part is positive: $\\{1, 1 + 2i, 1 - 2i, 2 + i, 2 - i, 5\\}$.\n\nThe following is a table of all of the divisors for the first five positive rational integers:\n\n| $n$ | Gaussian integer divisors\nwith positive real part | Sum $s(n)$ of these\ndivisors |\n| $1$ | $1$ | $1$ |\n| $2$ | $1, 1+i, 1-i, 2$ | $5$ |\n| $3$ | $1, 3$ | $4$ |\n| $4$ | $1, 1+i, 1-i, 2, 2+2i, 2-2i,4$ | $13$ |\n| $5$ | $1, 1+2i, 1-2i, 2+i, 2-i, 5$ | $12$ |\n\nFor divisors with positive real parts, then, we have: $\\sum \\limits_{n = 1}^{5} {s(n)} = 35$.\n\n$\\sum \\limits_{n = 1}^{10^5} {s(n)} = 17924657155$.\n\nWhat is $\\sum \\limits_{n = 1}^{10^8} {s(n)}$?", "raw_html": "

As we all know the equation $x^2=-1$ has no solutions for real $x$.\n
\nIf we however introduce the imaginary number $i$ this equation has two solutions: $x=i$ and $x=-i$.\n
\nIf we go a step further the equation $(x-3)^2=-4$ has two complex solutions: $x=3+2i$ and $x=3-2i$.\n
$x=3+2i$ and $x=3-2i$ are called each others' complex conjugate.\n
\nNumbers of the form $a+bi$ are called complex numbers.\n
\nIn general $a+bi$ and $a-bi$ are each other's complex conjugate.

\n

A Gaussian Integer is a complex number $a+bi$ such that both $a$ and $b$ are integers.\n
\nThe regular integers are also Gaussian integers (with $b=0$).\n
\nTo distinguish them from Gaussian integers with $b \\ne 0$ we call such integers \"rational integers.\"\n
\nA Gaussian integer $a+bi$ is called a divisor of a rational integer $n$ if the result $\\dfrac n {a + bi}$ is also a Gaussian integer.\n
\nIf for example we divide $5$ by $1+2i$ we can simplify $\\dfrac{5}{1 + 2i}$ in the following manner:\n
\nMultiply numerator and denominator by the complex conjugate of $1+2i$: $1-2i$.\n
\nThe result is $\\dfrac{5}{1 + 2i} = \\dfrac{5}{1 + 2i}\\dfrac{1 - 2i}{1 - 2i} = \\dfrac{5(1 - 2i)}{1 - (2i)^2} = \\dfrac{5(1 - 2i)}{1 - (-4)} = \\dfrac{5(1 - 2i)}{5} = 1 - 2i$.\n
\nSo $1+2i$ is a divisor of $5$.\n
\nNote that $1+i$ is not a divisor of $5$ because $\\dfrac{5}{1 + i} = \\dfrac{5}{2} - \\dfrac{5}{2}i$.\n
\nNote also that if the Gaussian Integer $(a+bi)$ is a divisor of a rational integer $n$, then its complex conjugate $(a-bi)$ is also a divisor of $n$.

\n

In fact, $5$ has six divisors such that the real part is positive: $\\{1, 1 + 2i, 1 - 2i, 2 + i, 2 - i, 5\\}$.\n
\nThe following is a table of all of the divisors for the first five positive rational integers:

\n\n\n\n\n\n
\n$n$ Gaussian integer divisors
\nwith positive real part
Sum $s(n)$ of
these\ndivisors
$1$$1$$1$
$2$$1, 1+i, 1-i, 2$$5$
$3$$1, 3$$4$
$4$$1, 1+i, 1-i, 2, 2+2i, 2-2i,4$$13$
$5$$1, 1+2i, 1-2i, 2+i, 2-i, 5$$12$

For divisors with positive real parts, then, we have: $\\sum \\limits_{n = 1}^{5} {s(n)} = 35$.

\n

$\\sum \\limits_{n = 1}^{10^5} {s(n)} = 17924657155$.

\n

What is $\\sum \\limits_{n = 1}^{10^8} {s(n)}$?

", "url": "https://projecteuler.net/problem=153", "answer": "17971254122360635"} {"id": 154, "problem": "A triangular pyramid is constructed using spherical balls so that each ball rests on exactly three balls of the next lower level.\n\nThen, we calculate the number of paths leading from the apex to each position:\n\nA path starts at the apex and progresses downwards to any of the three spheres directly below the current position.\n\nConsequently, the number of paths to reach a certain position is the sum of the numbers immediately above it (depending on the position, there are up to three numbers above it).\n\nThe result is Pascal's pyramid and the numbers at each level $n$ are the coefficients of the trinomial expansion\n$(x + y + z)^n$.\n\nHow many coefficients in the expansion of $(x + y + z)^{200000}$ are multiples of $10^{12}$?", "raw_html": "

A triangular pyramid is constructed using spherical balls so that each ball rests on exactly three balls of the next lower level.

\n
\"\"
\n

Then, we calculate the number of paths leading from the apex to each position:

\n

A path starts at the apex and progresses downwards to any of the three spheres directly below the current position.

\n

Consequently, the number of paths to reach a certain position is the sum of the numbers immediately above it (depending on the position, there are up to three numbers above it).

\n

The result is Pascal's pyramid and the numbers at each level $n$ are the coefficients of the trinomial expansion \n$(x + y + z)^n$.

\n

How many coefficients in the expansion of $(x + y + z)^{200000}$ are multiples of $10^{12}$?

", "url": "https://projecteuler.net/problem=154", "answer": "479742450"} {"id": 155, "problem": "An electric circuit uses exclusively identical capacitors of the same value $C$.\n\nThe capacitors can be connected in series or in parallel to form sub-units, which can then be connected in series or in parallel with other capacitors or other sub-units to form larger sub-units, and so on up to a final circuit.\n\nUsing this simple procedure and up to $n$ identical capacitors, we can make circuits having a range of different total capacitances. For example, using up to $n=3$ capacitors of $\\pu{60 \\mu F}$ each, we can obtain the following $7$ distinct total capacitance values:\n\nIf we denote by $D(n)$ the number of distinct total capacitance values we can obtain when using up to $n$ equal-valued capacitors and the simple procedure described above, we have: $D(1)=1$, $D(2)=3$, $D(3)=7$, $\\dots$\n\nFind $D(18)$.\n\nReminder: When connecting capacitors $C_1, C_2$ etc in parallel, the total capacitance is $C_T = C_1 + C_2 + \\cdots$,\n\nwhereas when connecting them in series, the overall capacitance is given by: $\\dfrac{1}{C_T} = \\dfrac{1}{C_1} + \\dfrac{1}{C_2} + \\cdots$", "raw_html": "

An electric circuit uses exclusively identical capacitors of the same value $C$.\n
\nThe capacitors can be connected in series or in parallel to form sub-units, which can then be connected in series or in parallel with other capacitors or other sub-units to form larger sub-units, and so on up to a final circuit.

\n

Using this simple procedure and up to $n$ identical capacitors, we can make circuits having a range of different total capacitances. For example, using up to $n=3$ capacitors of $\\pu{60 \\mu F}$ each, we can obtain the following $7$ distinct total capacitance values:

\n
\"\"
\n

If we denote by $D(n)$ the number of distinct total capacitance values we can obtain when using up to $n$ equal-valued capacitors and the simple procedure described above, we have: $D(1)=1$, $D(2)=3$, $D(3)=7$, $\\dots$

\n

Find $D(18)$.

\n

Reminder: When connecting capacitors $C_1, C_2$ etc in parallel, the total capacitance is $C_T = C_1 + C_2 + \\cdots$,\n
\nwhereas when connecting them in series, the overall capacitance is given by: $\\dfrac{1}{C_T} = \\dfrac{1}{C_1} + \\dfrac{1}{C_2} + \\cdots$

", "url": "https://projecteuler.net/problem=155", "answer": "3857447"} {"id": 156, "problem": "Starting from zero the natural numbers are written down in base $10$ like this:\n\n$$0\\,1\\,2\\,3\\,4\\,5\\,6\\,7\\,8\\,9\\,10\\,11\\,12\\cdots$$\n\nConsider the digit $d=1$. After we write down each number $n$, we will update the number of ones that have occurred and call this number $f(n,1)$. The first values for $f(n,1)$, then, are as follows:\n\n$$\\begin{array}{cc}\nn & f(n, 1)\\\\\n\\hline\n0 & 0\\\\\n1 & 1\\\\\n2 & 1\\\\\n3 & 1\\\\\n4 & 1\\\\\n5 & 1\\\\\n6 & 1\\\\\n7 & 1\\\\\n8 & 1\\\\\n9 & 1\\\\\n10 & 2\\\\\n11 & 4\\\\\n12 & 5\n\\end{array}$$\n\nNote that $f(n,1)$ never equals $3$.\n\nSo the first two solutions of the equation $f(n,1)=n$ are $n=0$ and $n=1$. The next solution is $n=199981$.\n\nIn the same manner the function $f(n,d)$ gives the total number of digits $d$ that have been written down after the number $n$ has been written.\n\nIn fact, for every digit $d \\ne 0$, $0$ is the first solution of the equation $f(n,d)=n$.\n\nLet $s(d)$ be the sum of all the solutions for which $f(n,d)=n$.\n\nYou are given that $s(1)=22786974071$.\n\nFind $\\sum s(d)$ for $1 \\le d \\le 9$.\n\nNote: if, for some $n$, $f(n,d)=n$ for more than one value of $d$ this value of $n$ is counted again for every value of $d$ for which $f(n,d)=n$.", "raw_html": "

Starting from zero the natural numbers are written down in base $10$ like this:\n
\n$$0\\,1\\,2\\,3\\,4\\,5\\,6\\,7\\,8\\,9\\,10\\,11\\,12\\cdots$$\n

\n

Consider the digit $d=1$. After we write down each number $n$, we will update the number of ones that have occurred and call this number $f(n,1)$. The first values for $f(n,1)$, then, are as follows:

\n$$\\begin{array}{cc}\nn & f(n, 1)\\\\\n\\hline\n0 & 0\\\\\n1 & 1\\\\\n2 & 1\\\\\n3 & 1\\\\\n4 & 1\\\\\n5 & 1\\\\\n6 & 1\\\\\n7 & 1\\\\\n8 & 1\\\\\n9 & 1\\\\\n10 & 2\\\\\n11 & 4\\\\\n12 & 5\n\\end{array}$$\n\n

Note that $f(n,1)$ never equals $3$.\n
\nSo the first two solutions of the equation $f(n,1)=n$ are $n=0$ and $n=1$. The next solution is $n=199981$.

\n

In the same manner the function $f(n,d)$ gives the total number of digits $d$ that have been written down after the number $n$ has been written.\n
\nIn fact, for every digit $d \\ne 0$, $0$ is the first solution of the equation $f(n,d)=n$.

\n

Let $s(d)$ be the sum of all the solutions for which $f(n,d)=n$.\n
\nYou are given that $s(1)=22786974071$.

\n

Find $\\sum s(d)$ for $1 \\le d \\le 9$.

\n

Note: if, for some $n$, $f(n,d)=n$ for more than one value of $d$ this value of $n$ is counted again for every value of $d$ for which $f(n,d)=n$.

", "url": "https://projecteuler.net/problem=156", "answer": "21295121502550"} {"id": 157, "problem": "Consider the diophantine equation $\\frac 1 a + \\frac 1 b = \\frac p {10^n}$ with $a, b, p, n$ positive integers and $a \\le b$.\n\nFor $n=1$ this equation has $20$ solutions that are listed below:\n$$\\begin{matrix}\n\\frac 1 1 + \\frac 1 1 = \\frac{20}{10} & \\frac 1 1 + \\frac 1 2 = \\frac{15}{10} & \\frac 1 1 + \\frac 1 5 = \\frac{12}{10} & \\frac 1 1 + \\frac 1 {10} = \\frac{11}{10} & \\frac 1 2 + \\frac 1 2 = \\frac{10}{10}\\\\\n\\frac 1 2 + \\frac 1 5 = \\frac 7 {10} & \\frac 1 2 + \\frac 1 {10} = \\frac 6 {10} & \\frac 1 3 + \\frac 1 6 = \\frac 5 {10} & \\frac 1 3 + \\frac 1 {15} = \\frac 4 {10} & \\frac 1 4 + \\frac 1 4 = \\frac 5 {10}\\\\\n\\frac 1 4 + \\frac 1 {20} = \\frac 3 {10} & \\frac 1 5 + \\frac 1 5 = \\frac 4 {10} & \\frac 1 5 + \\frac 1 {10} = \\frac 3 {10} & \\frac 1 6 + \\frac 1 {30} = \\frac 2 {10} & \\frac 1 {10} + \\frac 1 {10} = \\frac 2 {10}\\\\\n\\frac 1 {11} + \\frac 1 {110} = \\frac 1 {10} & \\frac 1 {12} + \\frac 1 {60} = \\frac 1 {10} & \\frac 1 {14} + \\frac 1 {35} = \\frac 1 {10} & \\frac 1 {15} + \\frac 1 {30} = \\frac 1 {10} & \\frac 1 {20} + \\frac 1 {20} = \\frac 1 {10}\n\\end{matrix}$$\n\nHow many solutions has this equation for $1 \\le n \\le 9$?", "raw_html": "

Consider the diophantine equation $\\frac 1 a + \\frac 1 b = \\frac p {10^n}$ with $a, b, p, n$ positive integers and $a \\le b$.
\nFor $n=1$ this equation has $20$ solutions that are listed below:\n$$\\begin{matrix}\n\\frac 1 1 + \\frac 1 1 = \\frac{20}{10} & \\frac 1 1 + \\frac 1 2 = \\frac{15}{10} & \\frac 1 1 + \\frac 1 5 = \\frac{12}{10} & \\frac 1 1 + \\frac 1 {10} = \\frac{11}{10} & \\frac 1 2 + \\frac 1 2 = \\frac{10}{10}\\\\\n\\frac 1 2 + \\frac 1 5 = \\frac 7 {10} & \\frac 1 2 + \\frac 1 {10} = \\frac 6 {10} & \\frac 1 3 + \\frac 1 6 = \\frac 5 {10} & \\frac 1 3 + \\frac 1 {15} = \\frac 4 {10} & \\frac 1 4 + \\frac 1 4 = \\frac 5 {10}\\\\\n\\frac 1 4 + \\frac 1 {20} = \\frac 3 {10} & \\frac 1 5 + \\frac 1 5 = \\frac 4 {10} & \\frac 1 5 + \\frac 1 {10} = \\frac 3 {10} & \\frac 1 6 + \\frac 1 {30} = \\frac 2 {10} & \\frac 1 {10} + \\frac 1 {10} = \\frac 2 {10}\\\\\n\\frac 1 {11} + \\frac 1 {110} = \\frac 1 {10} & \\frac 1 {12} + \\frac 1 {60} = \\frac 1 {10} & \\frac 1 {14} + \\frac 1 {35} = \\frac 1 {10} & \\frac 1 {15} + \\frac 1 {30} = \\frac 1 {10} & \\frac 1 {20} + \\frac 1 {20} = \\frac 1 {10}\n\\end{matrix}$$\n

\n

How many solutions has this equation for $1 \\le n \\le 9$?

", "url": "https://projecteuler.net/problem=157", "answer": "53490"} {"id": 158, "problem": "Taking three different letters from the $26$ letters of the alphabet, character strings of length three can be formed.\n\nExamples are 'abc', 'hat' and 'zyx'.\n\nWhen we study these three examples we see that for 'abc' two characters come lexicographically after its neighbour to the left.\n\nFor 'hat' there is exactly one character that comes lexicographically after its neighbour to the left. For 'zyx' there are zero characters that come lexicographically after its neighbour to the left.\n\nIn all there are $10400$ strings of length $3$ for which exactly one character comes lexicographically after its neighbour to the left.\n\nWe now consider strings of $n \\le 26$ different characters from the alphabet.\n\nFor every $n$, $p(n)$ is the number of strings of length $n$ for which exactly one character comes lexicographically after its neighbour to the left.\n\n\nWhat is the maximum value of $p(n)$?", "raw_html": "

Taking three different letters from the $26$ letters of the alphabet, character strings of length three can be formed.
\nExamples are 'abc', 'hat' and 'zyx'.
\nWhen we study these three examples we see that for 'abc' two characters come lexicographically after its neighbour to the left.
\nFor 'hat' there is exactly one character that comes lexicographically after its neighbour to the left. For 'zyx' there are zero characters that come lexicographically after its neighbour to the left.
\nIn all there are $10400$ strings of length $3$ for which exactly one character comes lexicographically after its neighbour to the left.

\n

We now consider strings of $n \\le 26$ different characters from the alphabet.
\nFor every $n$, $p(n)$ is the number of strings of length $n$ for which exactly one character comes lexicographically after its neighbour to the left.

\n

What is the maximum value of $p(n)$?

", "url": "https://projecteuler.net/problem=158", "answer": "409511334375"} {"id": 159, "problem": "A composite number can be factored many different ways.\nFor instance, not including multiplication by one, $24$ can be factored in $7$ distinct ways:\n\n$$\\begin{align}\n24 &= 2 \\times 2 \\times 2 \\times 3\\\\\n24 &= 2 \\times 3 \\times 4\\\\\n24 &= 2 \\times 2 \\times 6\\\\\n24 &= 4 \\times 6\\\\\n24 &= 3 \\times 8\\\\\n24 &= 2 \\times 12\\\\\n24 &= 24\n\\end{align}$$\n\nRecall that the digital root of a number, in base $10$, is found by adding together the digits of that number,\nand repeating that process until a number is arrived at that is less than $10$.\nThus the digital root of $467$ is $8$.\n\nWe shall call a Digital Root Sum (DRS) the sum of the digital roots of the individual factors of our number.\n\nThe chart below demonstrates all of the DRS values for $24$.\n\n| Factorisation | Digital Root Sum |\n| --- | --- |\n| $2 \\times 2 \\times 2 \\times 3$ | $9$ |\n| $2 \\times 3 \\times 4$ | $9$ |\n| $2 \\times 2 \\times 6$ | $10$ |\n| $4 \\times 6$ | $10$ |\n| $3 \\times 8$ | $11$ |\n| $2 \\times 12$ | $5$ |\n| $24$ | $6$ |\n\nThe maximum Digital Root Sum of $24$ is $11$.\n\nThe function $\\operatorname{mdrs}(n)$ gives the maximum Digital Root Sum of $n$. So $\\operatorname{mdrs}(24)=11$.\n\nFind $\\sum \\operatorname{mdrs}(n)$ for $1 \\lt n \\lt 1\\,000\\,000$.", "raw_html": "

A composite number can be factored many different ways. \nFor instance, not including multiplication by one, $24$ can be factored in $7$ distinct ways:

\n$$\\begin{align}\n24 &= 2 \\times 2 \\times 2 \\times 3\\\\\n24 &= 2 \\times 3 \\times 4\\\\\n24 &= 2 \\times 2 \\times 6\\\\\n24 &= 4 \\times 6\\\\\n24 &= 3 \\times 8\\\\\n24 &= 2 \\times 12\\\\\n24 &= 24\n\\end{align}$$\n\n

Recall that the digital root of a number, in base $10$, is found by adding together the digits of that number, \nand repeating that process until a number is arrived at that is less than $10$. \nThus the digital root of $467$ is $8$.

\n

We shall call a Digital Root Sum (DRS) the sum of the digital roots of the individual factors of our number.
\nThe chart below demonstrates all of the DRS values for $24$.

\n\n\n\n\n\n\n\n\n\n
FactorisationDigital Root Sum
$2 \\times 2 \\times 2 \\times 3$$9$
$2 \\times 3 \\times 4$$9$
$2 \\times 2 \\times 6$$10$
$4 \\times 6$$10$
$3 \\times 8$$11$
$2 \\times 12$$5$
$24$$6$
\n

The maximum Digital Root Sum of $24$ is $11$.
\nThe function $\\operatorname{mdrs}(n)$ gives the maximum Digital Root Sum of $n$. So $\\operatorname{mdrs}(24)=11$.
\nFind $\\sum \\operatorname{mdrs}(n)$ for $1 \\lt n \\lt 1\\,000\\,000$.

", "url": "https://projecteuler.net/problem=159", "answer": "14489159"} {"id": 160, "problem": "For any $N$, let $f(N)$ be the last five digits before the trailing zeroes in $N!$.\n\nFor example,\n\n- $9! = 362880$ so $f(9)=36288$\n\n- $10! = 3628800$ so $f(10)=36288$\n\n- $20! = 2432902008176640000$ so $f(20)=17664$\n\nFind $f(1\\,000\\,000\\,000\\,000)$.", "raw_html": "

For any $N$, let $f(N)$ be the last five digits before the trailing zeroes in $N!$.
\nFor example,

\n\n

Find $f(1\\,000\\,000\\,000\\,000)$.

", "url": "https://projecteuler.net/problem=160", "answer": "16576"} {"id": 161, "problem": "A triomino is a shape consisting of three squares joined via the edges.\nThere are two basic forms:\n\nIf all possible orientations are taken into account there are six:\n\nAny $n$ by $m$ grid for which $n \\times m$ is divisible by $3$ can be tiled with triominoes.\n\nIf we consider tilings that can be obtained by reflection or rotation from another tiling as different there are $41$ ways a $2$ by $9$ grid can be tiled with triominoes:\n\nIn how many ways can a $9$ by $12$ grid be tiled in this way by triominoes?", "raw_html": "

A triomino is a shape consisting of three squares joined via the edges.\nThere are two basic forms:

\n\n

\"\"

\n\n

If all possible orientations are taken into account there are six:

\n\n

\"\"

\n\n

Any $n$ by $m$ grid for which $n \\times m$ is divisible by $3$ can be tiled with triominoes.
\nIf we consider tilings that can be obtained by reflection or rotation from another tiling as different there are $41$ ways a $2$ by $9$ grid can be tiled with triominoes:

\n\n

\"\"

\n\n

In how many ways can a $9$ by $12$ grid be tiled in this way by triominoes?

", "url": "https://projecteuler.net/problem=161", "answer": "20574308184277971"} {"id": 162, "problem": "In the hexadecimal number system numbers are represented using $16$ different digits:\n$$0,1,2,3,4,5,6,7,8,9,\\mathrm A,\\mathrm B,\\mathrm C,\\mathrm D,\\mathrm E,\\mathrm F.$$\n\nThe hexadecimal number $\\mathrm{AF}$ when written in the decimal number system equals $10 \\times 16 + 15 = 175$.\n\nIn the $3$-digit hexadecimal numbers $10\\mathrm A$, $1\\mathrm A0$, $\\mathrm A10$, and $\\mathrm A01$ the digits $0$, $1$ and $\\mathrm A$ are all present.\n\nLike numbers written in base ten we write hexadecimal numbers without leading zeroes.\n\nHow many hexadecimal numbers containing at most sixteen hexadecimal digits exist with all of the digits $0$, $1$, and $\\mathrm A$ present at least once?\n\nGive your answer as a hexadecimal number.\n\n(A, B, C, D, E and F in upper case, without any leading or trailing code that marks the number as hexadecimal and without leading zeroes, e.g. 1A3F and not: 1a3f and not 0x1a3f and not $1A3F and not #1A3F and not 0000001A3F)", "raw_html": "

In the hexadecimal number system numbers are represented using $16$ different digits:\n$$0,1,2,3,4,5,6,7,8,9,\\mathrm A,\\mathrm B,\\mathrm C,\\mathrm D,\\mathrm E,\\mathrm F.$$

\n

The hexadecimal number $\\mathrm{AF}$ when written in the decimal number system equals $10 \\times 16 + 15 = 175$.

\n

In the $3$-digit hexadecimal numbers $10\\mathrm A$, $1\\mathrm A0$, $\\mathrm A10$, and $\\mathrm A01$ the digits $0$, $1$ and $\\mathrm A$ are all present.
\nLike numbers written in base ten we write hexadecimal numbers without leading zeroes.

\n

How many hexadecimal numbers containing at most sixteen hexadecimal digits exist with all of the digits $0$, $1$, and $\\mathrm A$ present at least once?
\nGive your answer as a hexadecimal number.

\n

(A, B, C, D, E and F in upper case, without any leading or trailing code that marks the number as hexadecimal and without leading zeroes, e.g. 1A3F and not: 1a3f and not 0x1a3f and not $1A3F and not #1A3F and not 0000001A3F)

", "url": "https://projecteuler.net/problem=162", "answer": "3D58725572C62302"} {"id": 163, "problem": "Consider an equilateral triangle in which straight lines are drawn from each vertex to the middle of the opposite side, such as in the size $1$ triangle in the sketch below.\n\nSixteen triangles of either different shape or size or orientation or location can now be observed in that triangle. Using size $1$ triangles as building blocks, larger triangles can be formed, such as the size $2$ triangle in the above sketch. One-hundred and four triangles of either different shape or size or orientation or location can now be observed in that size $2$ triangle.\n\nIt can be observed that the size $2$ triangle contains $4$ size $1$ triangle building blocks. A size $3$ triangle would contain $9$ size $1$ triangle building blocks and a size $n$ triangle would thus contain $n^2$ size $1$ triangle building blocks.\n\nIf we denote $T(n)$ as the number of triangles present in a triangle of size $n$, then\n\n$$\\begin{align}\nT(1) &= 16\\\\\nT(2) &= 104\n\\end{align}$$\nFind $T(36)$.", "raw_html": "

Consider an equilateral triangle in which straight lines are drawn from each vertex to the middle of the opposite side, such as in the size $1$ triangle in the sketch below.

\n
\"\"
\n

Sixteen triangles of either different shape or size or orientation or location can now be observed in that triangle. Using size $1$ triangles as building blocks, larger triangles can be formed, such as the size $2$ triangle in the above sketch. One-hundred and four triangles of either different shape or size or orientation or location can now be observed in that size $2$ triangle.

\n

It can be observed that the size $2$ triangle contains $4$ size $1$ triangle building blocks. A size $3$ triangle would contain $9$ size $1$ triangle building blocks and a size $n$ triangle would thus contain $n^2$ size $1$ triangle building blocks.

\n

If we denote $T(n)$ as the number of triangles present in a triangle of size $n$, then

\n$$\\begin{align}\nT(1) &= 16\\\\\nT(2) &= 104\n\\end{align}$$\n

Find $T(36)$.

", "url": "https://projecteuler.net/problem=163", "answer": "343047"} {"id": 164, "problem": "How many $20$ digit numbers $n$ (without any leading zero) exist such that no three consecutive digits of $n$ have a sum greater than $9$?", "raw_html": "

How many $20$ digit numbers $n$ (without any leading zero) exist such that no three consecutive digits of $n$ have a sum greater than $9$?

", "url": "https://projecteuler.net/problem=164", "answer": "378158756814587"} {"id": 165, "problem": "A segment is uniquely defined by its two endpoints.\nBy considering two line segments in plane geometry there are three possibilities:\n\nthe segments have zero points, one point, or infinitely many points in common.\n\nMoreover when two segments have exactly one point in common it might be the case that that common point is an endpoint of either one of the segments or of both. If a common point of two segments is not an endpoint of either of the segments it is an interior point of both segments.\n\nWe will call a common point $T$ of two segments $L_1$ and $L_2$ a true intersection point of $L_1$ and $L_2$ if $T$ is the only common point of $L_1$ and $L_2$ and $T$ is an interior point of both segments.\n\nConsider the three segments $L_1$, $L_2$, and $L_3$:\n\n- $L_1$: $(27, 44)$ to $(12, 32)$\n\n- $L_2$: $(46, 53)$ to $(17, 62)$\n\n- $L_3$: $(46, 70)$ to $(22, 40)$\n\nIt can be verified that line segments $L_2$ and $L_3$ have a true intersection point. We note that as the one of the end points of $L_3$: $(22,40)$ lies on $L_1$ this is not considered to be a true point of intersection. $L_1$ and $L_2$ have no common point. So among the three line segments, we find one true intersection point.\n\nNow let us do the same for $5000$ line segments. To this end, we generate $20000$ numbers using the so-called \"Blum Blum Shub\" pseudo-random number generator.\n\n$$\\begin{align}\ns_0 &= 290797\\\\\ns_{n + 1} &= s_n \\times s_n \\pmod{50515093}\\\\\nt_n &= s_n \\pmod{500}\n\\end{align}$$\nTo create each line segment, we use four consecutive numbers $t_n$. That is, the first line segment is given by:\n\n$(t_1, t_2)$ to $(t_3, t_4)$.\n\nThe first four numbers computed according to the above generator should be: $27$, $144$, $12$ and $232$. The first segment would thus be $(27,144)$ to $(12,232)$.\n\nHow many distinct true intersection points are found among the $5000$ line segments?", "raw_html": "

A segment is uniquely defined by its two endpoints.
By considering two line segments in plane geometry there are three possibilities:
\nthe segments have zero points, one point, or infinitely many points in common.

\n

Moreover when two segments have exactly one point in common it might be the case that that common point is an endpoint of either one of the segments or of both. If a common point of two segments is not an endpoint of either of the segments it is an interior point of both segments.
\nWe will call a common point $T$ of two segments $L_1$ and $L_2$ a true intersection point of $L_1$ and $L_2$ if $T$ is the only common point of $L_1$ and $L_2$ and $T$ is an interior point of both segments.\n

\n

Consider the three segments $L_1$, $L_2$, and $L_3$:

\n\n

It can be verified that line segments $L_2$ and $L_3$ have a true intersection point. We note that as the one of the end points of $L_3$: $(22,40)$ lies on $L_1$ this is not considered to be a true point of intersection. $L_1$ and $L_2$ have no common point. So among the three line segments, we find one true intersection point.

\n

Now let us do the same for $5000$ line segments. To this end, we generate $20000$ numbers using the so-called \"Blum Blum Shub\" pseudo-random number generator.

\n$$\\begin{align}\ns_0 &= 290797\\\\\ns_{n + 1} &= s_n \\times s_n \\pmod{50515093}\\\\\nt_n &= s_n \\pmod{500}\n\\end{align}$$\n

To create each line segment, we use four consecutive numbers $t_n$. That is, the first line segment is given by:

\n

$(t_1, t_2)$ to $(t_3, t_4)$.

\n

The first four numbers computed according to the above generator should be: $27$, $144$, $12$ and $232$. The first segment would thus be $(27,144)$ to $(12,232)$.

\n

How many distinct true intersection points are found among the $5000$ line segments?

", "url": "https://projecteuler.net/problem=165", "answer": "2868868"} {"id": 166, "problem": "A $4 \\times 4$ grid is filled with digits $d$, $0 \\le d \\le 9$.\n\nIt can be seen that in the grid\n$$\\begin{matrix}\n6 & 3 & 3 & 0\\\\\n5 & 0 & 4 & 3\\\\\n0 & 7 & 1 & 4\\\\\n1 & 2 & 4 & 5\n\\end{matrix}$$\nthe sum of each row and each column has the value $12$. Moreover the sum of each diagonal is also $12$.\n\nIn how many ways can you fill a $4 \\times 4$ grid with the digits $d$, $0 \\le d \\le 9$ so that each row, each column, and both diagonals have the same sum?", "raw_html": "

A $4 \\times 4$ grid is filled with digits $d$, $0 \\le d \\le 9$.

\n\n

It can be seen that in the grid\n$$\\begin{matrix}\n6 & 3 & 3 & 0\\\\\n5 & 0 & 4 & 3\\\\\n0 & 7 & 1 & 4\\\\\n1 & 2 & 4 & 5\n\\end{matrix}$$\nthe sum of each row and each column has the value $12$. Moreover the sum of each diagonal is also $12$.

\n\n

In how many ways can you fill a $4 \\times 4$ grid with the digits $d$, $0 \\le d \\le 9$ so that each row, each column, and both diagonals have the same sum?

", "url": "https://projecteuler.net/problem=166", "answer": "7130034"} {"id": 167, "problem": "For two positive integers $a$ and $b$, the Ulam sequence $U(a,b)$ is defined by $U(a,b)_1 = a$, $U(a,b)_2 = b$ and for $k \\gt 2$,\n$U(a,b)_k$ is the smallest integer greater than $U(a,b)_{k - 1}$ which can be written in exactly one way as the sum of two distinct previous members of $U(a,b)$.\n\nFor example, the sequence $U(1,2)$ begins with\n\n$1$, $2$, $3 = 1 + 2$, $4 = 1 + 3$, $6 = 2 + 4$, $8 = 2 + 6$, $11 = 3 + 8$;\n\n$5$ does not belong to it because $5 = 1 + 4 = 2 + 3$ has two representations as the sum of two previous members, likewise $7 = 1 + 6 = 3 + 4$.\n\nFind $\\sum\\limits_{n = 2}^{10} U(2,2n+1)_k$, where $k = 10^{11}$.", "raw_html": "

For two positive integers $a$ and $b$, the Ulam sequence $U(a,b)$ is defined by $U(a,b)_1 = a$, $U(a,b)_2 = b$ and for $k \\gt 2$,\n$U(a,b)_k$ is the smallest integer greater than $U(a,b)_{k - 1}$ which can be written in exactly one way as the sum of two distinct previous members of $U(a,b)$.

\n

For example, the sequence $U(1,2)$ begins with
\n$1$, $2$, $3 = 1 + 2$, $4 = 1 + 3$, $6 = 2 + 4$, $8 = 2 + 6$, $11 = 3 + 8$;
\n$5$ does not belong to it because $5 = 1 + 4 = 2 + 3$ has two representations as the sum of two previous members, likewise $7 = 1 + 6 = 3 + 4$.

\n

Find $\\sum\\limits_{n = 2}^{10} U(2,2n+1)_k$, where $k = 10^{11}$.

", "url": "https://projecteuler.net/problem=167", "answer": "3916160068885"} {"id": 168, "problem": "Consider the number $142857$. We can right-rotate this number by moving the last digit ($7$) to the front of it, giving us $714285$.\n\nIt can be verified that $714285 = 5 \\times 142857$.\n\nThis demonstrates an unusual property of $142857$: it is a divisor of its right-rotation.\n\nFind the last $5$ digits of the sum of all integers $n$, $10 \\lt n \\lt 10^{100}$, that have this property.", "raw_html": "

Consider the number $142857$. We can right-rotate this number by moving the last digit ($7$) to the front of it, giving us $714285$.
\nIt can be verified that $714285 = 5 \\times 142857$.
\nThis demonstrates an unusual property of $142857$: it is a divisor of its right-rotation.

\n

Find the last $5$ digits of the sum of all integers $n$, $10 \\lt n \\lt 10^{100}$, that have this property.

", "url": "https://projecteuler.net/problem=168", "answer": "59206"} {"id": 169, "problem": "Define $f(0)=1$ and $f(n)$ to be the number of different ways $n$ can be expressed as a sum of integer powers of $2$ using each power no more than twice.\n\nFor example, $f(10)=5$ since there are five different ways to express $10$:\n\n$$\\begin{align}\n& 1 + 1 + 8\\\\\n& 1 + 1 + 4 + 4\\\\\n& 1 + 1 + 2 + 2 + 4\\\\\n& 2 + 4 + 4\\\\\n& 2 + 8\n\\end{align}$$\nWhat is $f(10^{25})$?", "raw_html": "

Define $f(0)=1$ and $f(n)$ to be the number of different ways $n$ can be expressed as a sum of integer powers of $2$ using each power no more than twice.

\n

For example, $f(10)=5$ since there are five different ways to express $10$:

\n$$\\begin{align}\n& 1 + 1 + 8\\\\\n& 1 + 1 + 4 + 4\\\\\n& 1 + 1 + 2 + 2 + 4\\\\\n& 2 + 4 + 4\\\\\n& 2 + 8\n\\end{align}$$\n

What is $f(10^{25})$?

", "url": "https://projecteuler.net/problem=169", "answer": "178653872807"} {"id": 170, "problem": "Take the number $6$ and multiply it by each of $1273$ and $9854$:\n\n$$\\begin{align}\n6 \\times 1273 &= 7638\\\\\n6 \\times 9854 &= 59124\n\\end{align}$$\n\nBy concatenating these products we get the $1$ to $9$ pandigital $763859124$. We will call $763859124$ the \"concatenated product of $6$ and $(1273,9854)$\". Notice too, that the concatenation of the input numbers, $612739854$, is also $1$ to $9$ pandigital.\n\nThe same can be done for $0$ to $9$ pandigital numbers.\n\nWhat is the largest $0$ to $9$ pandigital $10$-digit concatenated product of an integer with two or more other integers, such that the concatenation of the input numbers is also a $0$ to $9$ pandigital $10$-digit number?", "raw_html": "

Take the number $6$ and multiply it by each of $1273$ and $9854$:

\n\n$$\\begin{align}\n6 \\times 1273 &= 7638\\\\\n6 \\times 9854 &= 59124\n\\end{align}$$\n\n

By concatenating these products we get the $1$ to $9$ pandigital $763859124$. We will call $763859124$ the \"concatenated product of $6$ and $(1273,9854)$\". Notice too, that the concatenation of the input numbers, $612739854$, is also $1$ to $9$ pandigital.

\n\n

The same can be done for $0$ to $9$ pandigital numbers.

\n\n

What is the largest $0$ to $9$ pandigital $10$-digit concatenated product of an integer with two or more other integers, such that the concatenation of the input numbers is also a $0$ to $9$ pandigital $10$-digit number?

", "url": "https://projecteuler.net/problem=170", "answer": "9857164023"} {"id": 171, "problem": "For a positive integer $n$, let $f(n)$ be the sum of the squares of the digits (in base $10$) of $n$, e.g.\n\n$$\\begin{align}\nf(3) &= 3^2 = 9,\\\\\nf(25) &= 2^2 + 5^2 = 4 + 25 = 29,\\\\\nf(442) &= 4^2 + 4^2 + 2^2 = 16 + 16 + 4 = 36\\\\\n\\end{align}$$\nFind the last nine digits of the sum of all $n$, $0 \\lt n \\lt 10^{20}$, such that $f(n)$ is a perfect square.", "raw_html": "

For a positive integer $n$, let $f(n)$ be the sum of the squares of the digits (in base $10$) of $n$, e.g.

\n$$\\begin{align}\nf(3) &= 3^2 = 9,\\\\\nf(25) &= 2^2 + 5^2 = 4 + 25 = 29,\\\\\nf(442) &= 4^2 + 4^2 + 2^2 = 16 + 16 + 4 = 36\\\\\n\\end{align}$$\n

Find the last nine digits of the sum of all $n$, $0 \\lt n \\lt 10^{20}$, such that $f(n)$ is a perfect square.

", "url": "https://projecteuler.net/problem=171", "answer": "142989277"} {"id": 172, "problem": "How many $18$-digit numbers $n$ (without leading zeros) are there such that no digit occurs more than three times in $n$?", "raw_html": "

How many $18$-digit numbers $n$ (without leading zeros) are there such that no digit occurs more than three times in $n$?

", "url": "https://projecteuler.net/problem=172", "answer": "227485267000992000"} {"id": 173, "problem": "We shall define a square lamina to be a square outline with a square \"hole\" so that the shape possesses vertical and horizontal symmetry. For example, using exactly thirty-two square tiles we can form two different square laminae:\n\nWith one-hundred tiles, and not necessarily using all of the tiles at one time, it is possible to form forty-one different square laminae.\n\nUsing up to one million tiles how many different square laminae can be formed?", "raw_html": "

We shall define a square lamina to be a square outline with a square \"hole\" so that the shape possesses vertical and horizontal symmetry. For example, using exactly thirty-two square tiles we can form two different square laminae:

\n
\n\"\"
\n

With one-hundred tiles, and not necessarily using all of the tiles at one time, it is possible to form forty-one different square laminae.

\n

Using up to one million tiles how many different square laminae can be formed?

", "url": "https://projecteuler.net/problem=173", "answer": "1572729"} {"id": 174, "problem": "We shall define a square lamina to be a square outline with a square \"hole\" so that the shape possesses vertical and horizontal symmetry.\n\nGiven eight tiles it is possible to form a lamina in only one way: $3 \\times 3$ square with a $1 \\times 1$ hole in the middle. However, using thirty-two tiles it is possible to form two distinct laminae.\n\nIf t represents the number of tiles used, we shall say that $t = 8$ is type $L(1)$ and $t = 32$ is type $L(2)$.\n\nLet $N(n)$ be the number of $t \\le 1000000$ such that $t$ is type $L(n)$; for example, $N(15) = 832$.\n\nWhat is $\\sum\\limits_{n = 1}^{10} N(n)$?", "raw_html": "

We shall define a square lamina to be a square outline with a square \"hole\" so that the shape possesses vertical and horizontal symmetry.

\n

Given eight tiles it is possible to form a lamina in only one way: $3 \\times 3$ square with a $1 \\times 1$ hole in the middle. However, using thirty-two tiles it is possible to form two distinct laminae.

\n
\n\"\"
\n

If t represents the number of tiles used, we shall say that $t = 8$ is type $L(1)$ and $t = 32$ is type $L(2)$.

\n

Let $N(n)$ be the number of $t \\le 1000000$ such that $t$ is type $L(n)$; for example, $N(15) = 832$.

\n

What is $\\sum\\limits_{n = 1}^{10} N(n)$?

", "url": "https://projecteuler.net/problem=174", "answer": "209566"} {"id": 175, "problem": "Define $f(0)=1$ and $f(n)$ to be the number of ways to write $n$ as a sum of powers of $2$ where no power occurs more than twice.\n\nFor example, $f(10)=5$ since there are five different ways to express $10$:\n$10 = 8+2 = 8+1+1 = 4+4+2 = 4+2+2+1+1 = 4+4+1+1.$\n\nIt can be shown that for every fraction $p / q$ ($p \\gt 0$, $q \\gt 0$) there exists at least one integer $n$ such that $f(n)/f(n-1)=p/q$.\n\nFor instance, the smallest $n$ for which $f(n)/f(n-1)=13/17$ is $241$.\n\nThe binary expansion of $241$ is $11110001$.\n\nReading this binary number from the most significant bit to the least significant bit there are $4$ one's, $3$ zeroes and $1$ one. We shall call the string $4,3,1$ the Shortened Binary Expansion of $241$.\n\nFind the Shortened Binary Expansion of the smallest $n$ for which $f(n)/f(n-1)=123456789/987654321$.\n\nGive your answer as comma separated integers, without any whitespaces.", "raw_html": "

Define $f(0)=1$ and $f(n)$ to be the number of ways to write $n$ as a sum of powers of $2$ where no power occurs more than twice.

\n\n

\nFor example, $f(10)=5$ since there are five different ways to express $10$:
$10 = 8+2 = 8+1+1 = 4+4+2 = 4+2+2+1+1 = 4+4+1+1.$

\n\n

\nIt can be shown that for every fraction $p / q$ ($p \\gt 0$, $q \\gt 0$) there exists at least one integer $n$ such that $f(n)/f(n-1)=p/q$.

\n\n

\nFor instance, the smallest $n$ for which $f(n)/f(n-1)=13/17$ is $241$.
\nThe binary expansion of $241$ is $11110001$.
\nReading this binary number from the most significant bit to the least significant bit there are $4$ one's, $3$ zeroes and $1$ one. We shall call the string $4,3,1$ the Shortened Binary Expansion of $241$.

\n\n

\nFind the Shortened Binary Expansion of the smallest $n$ for which $f(n)/f(n-1)=123456789/987654321$.

\n\n

\nGive your answer as comma separated integers, without any whitespaces.

", "url": "https://projecteuler.net/problem=175", "answer": "1,13717420,8"} {"id": 176, "problem": "The four right-angled triangles with sides $(9,12,15)$, $(12,16,20)$, $(5,12,13)$ and $(12,35,37)$ all have one of the shorter sides (catheti) equal to $12$. It can be shown that no other integer sided right-angled triangle exists with one of the catheti equal to $12$.\n\nFind the smallest integer that can be the length of a cathetus of exactly $47547$ different integer sided right-angled triangles.", "raw_html": "

The four right-angled triangles with sides $(9,12,15)$, $(12,16,20)$, $(5,12,13)$ and $(12,35,37)$ all have one of the shorter sides (catheti) equal to $12$. It can be shown that no other integer sided right-angled triangle exists with one of the catheti equal to $12$.

\n

Find the smallest integer that can be the length of a cathetus of exactly $47547$ different integer sided right-angled triangles.

", "url": "https://projecteuler.net/problem=176", "answer": "96818198400000"} {"id": 177, "problem": "Let $ABCD$ be a convex quadrilateral, with diagonals $AC$ and $BD$. At each vertex the diagonal makes an angle with each of the two sides, creating eight corner angles.\n\nFor example, at vertex $A$, the two angles are $CAD$, $CAB$.\n\nWe call such a quadrilateral for which all eight corner angles have integer values when measured in degrees an \"integer angled quadrilateral\". An example of an integer angled quadrilateral is a square, where all eight corner angles are $45^\\circ$. Another example is given by $DAC = 20^\\circ$, $BAC = 60^\\circ$, $ABD = 50^\\circ$, $CBD = 30^\\circ$, $BCA = 40^\\circ$, $DCA = 30^\\circ$, $CDB = 80^\\circ$, $ADB = 50^\\circ$.\n\nWhat is the total number of non-similar integer angled quadrilaterals?\n\nNote: In your calculations you may assume that a calculated angle is integral if it is within a tolerance of $10^{-9}$ of an integer value.", "raw_html": "

Let $ABCD$ be a convex quadrilateral, with diagonals $AC$ and $BD$. At each vertex the diagonal makes an angle with each of the two sides, creating eight corner angles.

\n

\"\"

\n

For example, at vertex $A$, the two angles are $CAD$, $CAB$.

\n

We call such a quadrilateral for which all eight corner angles have integer values when measured in degrees an \"integer angled quadrilateral\". An example of an integer angled quadrilateral is a square, where all eight corner angles are $45^\\circ$. Another example is given by $DAC = 20^\\circ$, $BAC = 60^\\circ$, $ABD = 50^\\circ$, $CBD = 30^\\circ$, $BCA = 40^\\circ$, $DCA = 30^\\circ$, $CDB = 80^\\circ$, $ADB = 50^\\circ$.

\n

What is the total number of non-similar integer angled quadrilaterals?

\n

Note: In your calculations you may assume that a calculated angle is integral if it is within a tolerance of $10^{-9}$ of an integer value.

", "url": "https://projecteuler.net/problem=177", "answer": "129325"} {"id": 178, "problem": "Consider the number $45656$.\n\nIt can be seen that each pair of consecutive digits of $45656$ has a difference of one.\n\nA number for which every pair of consecutive digits has a difference of one is called a step number.\n\nA pandigital number contains every decimal digit from $0$ to $9$ at least once.\n\nHow many pandigital step numbers less than $10^{40}$ are there?", "raw_html": "Consider the number $45656$.
\nIt can be seen that each pair of consecutive digits of $45656$ has a difference of one.
\nA number for which every pair of consecutive digits has a difference of one is called a step number.
\nA pandigital number contains every decimal digit from $0$ to $9$ at least once.
\n\nHow many pandigital step numbers less than $10^{40}$ are there?", "url": "https://projecteuler.net/problem=178", "answer": "126461847755"} {"id": 179, "problem": "Find the number of integers $1 \\lt n \\lt 10^7$, for which $n$ and $n + 1$ have the same number of positive divisors. For example, $14$ has the positive divisors $1, 2, 7, 14$ while $15$ has $1, 3, 5, 15$.", "raw_html": "

Find the number of integers $1 \\lt n \\lt 10^7$, for which $n$ and $n + 1$ have the same number of positive divisors. For example, $14$ has the positive divisors $1, 2, 7, 14$ while $15$ has $1, 3, 5, 15$.

", "url": "https://projecteuler.net/problem=179", "answer": "986262"} {"id": 180, "problem": "For any integer $n$, consider the three functions\n\n$$\\begin{align}\nf_{1, n}(x, y, z) &= x^{n + 1} + y^{n + 1} - z^{n + 1}\\\\\nf_{2, n}(x, y, z) &= (xy + yz + zx) \\cdot (x^{n - 1} + y^{n - 1} - z^{n - 1})\\\\\nf_{3, n}(x, y, z) &= xyz \\cdot (x^{n - 2} + y^{n - 2} - z^{n - 2})\n\\end{align}$$\n\nand their combination\n$$f_n(x, y, z) = f_{1, n}(x, y, z) + f_{2, n}(x, y, z) - f_{3, n}(x, y, z).$$\n\nWe call $(x, y, z)$ a golden triple of order $k$ if $x$, $y$, and $z$ are all rational numbers of the form $a / b$ with $0 \\lt a \\lt b \\le k$ and there is (at least) one integer $n$, so that $f_n(x, y, z) = 0$.\n\nLet $s(x, y, z) = x + y + z$.\n\nLet $t = u / v$ be the sum of all distinct $s(x, y, z)$ for all golden triples $(x, y, z)$ of order $35$.\nAll the $s(x, y, z)$ and $t$ must be in reduced form.\n\nFind $u + v$.", "raw_html": "

For any integer $n$, consider the three functions

\n$$\\begin{align}\nf_{1, n}(x, y, z) &= x^{n + 1} + y^{n + 1} - z^{n + 1}\\\\\nf_{2, n}(x, y, z) &= (xy + yz + zx) \\cdot (x^{n - 1} + y^{n - 1} - z^{n - 1})\\\\\nf_{3, n}(x, y, z) &= xyz \\cdot (x^{n - 2} + y^{n - 2} - z^{n - 2})\n\\end{align}$$\n\n

and their combination\n$$f_n(x, y, z) = f_{1, n}(x, y, z) + f_{2, n}(x, y, z) - f_{3, n}(x, y, z).$$

\n\n

We call $(x, y, z)$ a golden triple of order $k$ if $x$, $y$, and $z$ are all rational numbers of the form $a / b$ with $0 \\lt a \\lt b \\le k$ and there is (at least) one integer $n$, so that $f_n(x, y, z) = 0$.

\n

Let $s(x, y, z) = x + y + z$.
\nLet $t = u / v$ be the sum of all distinct $s(x, y, z)$ for all golden triples $(x, y, z)$ of order $35$.
All the $s(x, y, z)$ and $t$ must be in reduced form.

\n

Find $u + v$.

", "url": "https://projecteuler.net/problem=180", "answer": "285196020571078987"} {"id": 181, "problem": "Having three black objects B and one white object W they can be grouped in 7 ways like this:\n\n| (BBBW) | (B,BBW) | (B,B,BW) | (B,B,B,W) | (B,BB,W) | (BBB,W) | (BB,BW) |\n\nIn how many ways can sixty black objects B and forty white objects W be thus grouped?", "raw_html": "

Having three black objects B and one white object W they can be grouped in 7 ways like this:

\n\n\n
(BBBW)(B,BBW)(B,B,BW)(B,B,B,W)(B,BB,W)(BBB,W)(BB,BW)

In how many ways can sixty black objects B and forty white objects W be thus grouped?

", "url": "https://projecteuler.net/problem=181", "answer": "83735848679360680"} {"id": 182, "problem": "The RSA encryption is based on the following procedure:\n\nGenerate two distinct primes $p$ and $q$.\nCompute $n = pq$ and $\\phi = (p - 1)(q - 1)$.\n\nFind an integer $e$, $1 \\lt e \\lt \\phi$, such that $\\gcd(e, \\phi) = 1$.\n\nA message in this system is a number in the interval $[0, n - 1]$.\n\nA text to be encrypted is then somehow converted to messages (numbers in the interval $[0, n - 1]$).\n\nTo encrypt the text, for each message, $m$, $c = m^e \\bmod n$ is calculated.\n\nTo decrypt the text, the following procedure is needed: calculate $d$ such that $ed = 1 \\bmod \\phi$, then for each encrypted message, $c$, calculate $m = c^d \\bmod n$.\n\nThere exist values of $e$ and $m$ such that $m^e \\bmod n = m$.\nWe call messages $m$ for which $m^e \\bmod n = m$ unconcealed messages.\n\nAn issue when choosing $e$ is that there should not be too many unconcealed messages.\nFor instance, let $p = 19$ and $q = 37$.\n\nThen $n = 19 \\cdot 37 = 703$ and $\\phi = 18 \\cdot 36 = 648$.\n\nIf we choose $e = 181$, then, although $\\gcd(181,648) = 1$ it turns out that all possible messages $m$ ($0 \\le m \\le n - 1$) are unconcealed when calculating $m^e \\bmod n$.\n\nFor any valid choice of $e$ there exist some unconcealed messages.\n\nIt's important that the number of unconcealed messages is at a minimum.\n\nChoose $p = 1009$ and $q = 3643$.\n\nFind the sum of all values of $e$, $1 \\lt e \\lt \\phi(1009,3643)$ and $\\gcd(e, \\phi) = 1$, so that the number of unconcealed messages for this value of $e$ is at a minimum.", "raw_html": "

The RSA encryption is based on the following procedure:

\n

Generate two distinct primes $p$ and $q$.
Compute $n = pq$ and $\\phi = (p - 1)(q - 1)$.
\nFind an integer $e$, $1 \\lt e \\lt \\phi$, such that $\\gcd(e, \\phi) = 1$.

\n

A message in this system is a number in the interval $[0, n - 1]$.
\nA text to be encrypted is then somehow converted to messages (numbers in the interval $[0, n - 1]$).
\nTo encrypt the text, for each message, $m$, $c = m^e \\bmod n$ is calculated.

\n

To decrypt the text, the following procedure is needed: calculate $d$ such that $ed = 1 \\bmod \\phi$, then for each encrypted message, $c$, calculate $m = c^d \\bmod n$.

\n

There exist values of $e$ and $m$ such that $m^e \\bmod n = m$.
We call messages $m$ for which $m^e \\bmod n = m$ unconcealed messages.

\n

An issue when choosing $e$ is that there should not be too many unconcealed messages.
For instance, let $p = 19$ and $q = 37$.
\nThen $n = 19 \\cdot 37 = 703$ and $\\phi = 18 \\cdot 36 = 648$.
\nIf we choose $e = 181$, then, although $\\gcd(181,648) = 1$ it turns out that all possible messages $m$ ($0 \\le m \\le n - 1$) are unconcealed when calculating $m^e \\bmod n$.
\nFor any valid choice of $e$ there exist some unconcealed messages.
\nIt's important that the number of unconcealed messages is at a minimum.

\n

Choose $p = 1009$ and $q = 3643$.
\nFind the sum of all values of $e$, $1 \\lt e \\lt \\phi(1009,3643)$ and $\\gcd(e, \\phi) = 1$, so that the number of unconcealed messages for this value of $e$ is at a minimum.

", "url": "https://projecteuler.net/problem=182", "answer": "399788195976"} {"id": 183, "problem": "Let $N$ be a positive integer and let $N$ be split into $k$ equal parts, $r = N/k$, so that $N = r + r + \\cdots + r$.\n\nLet $P$ be the product of these parts, $P = r \\times r \\times \\cdots \\times r = r^k$.\n\nFor example, if $11$ is split into five equal parts, $11 = 2.2 + 2.2 + 2.2 + 2.2 + 2.2$, then $P = 2.2^5 = 51.53632$.\n\nLet $M(N) = P_{\\mathrm{max}}$ for a given value of $N$.\n\nIt turns out that the maximum for $N = 11$ is found by splitting eleven into four equal parts which leads to $P_{\\mathrm{max}} = (11/4)^4$; that is, $M(11) = 14641/256 = 57.19140625$, which is a terminating decimal.\n\nHowever, for $N = 8$ the maximum is achieved by splitting it into three equal parts, so $M(8) = 512/27$, which is a non-terminating decimal.\n\nLet $D(N) = N$ if $M(N)$ is a non-terminating decimal and $D(N) = -N$ if $M(N)$ is a terminating decimal.\n\nFor example, $\\sum\\limits_{N = 5}^{100} D(N)$ is $2438$.\n\nFind $\\sum\\limits_{N = 5}^{10000} D(N)$.", "raw_html": "

Let $N$ be a positive integer and let $N$ be split into $k$ equal parts, $r = N/k$, so that $N = r + r + \\cdots + r$.
\nLet $P$ be the product of these parts, $P = r \\times r \\times \\cdots \\times r = r^k$.

\n\n

For example, if $11$ is split into five equal parts, $11 = 2.2 + 2.2 + 2.2 + 2.2 + 2.2$, then $P = 2.2^5 = 51.53632$.

\n\n

Let $M(N) = P_{\\mathrm{max}}$ for a given value of $N$.

\n\n

It turns out that the maximum for $N = 11$ is found by splitting eleven into four equal parts which leads to $P_{\\mathrm{max}} = (11/4)^4$; that is, $M(11) = 14641/256 = 57.19140625$, which is a terminating decimal.

\n\n

However, for $N = 8$ the maximum is achieved by splitting it into three equal parts, so $M(8) = 512/27$, which is a non-terminating decimal.

\n\n

Let $D(N) = N$ if $M(N)$ is a non-terminating decimal and $D(N) = -N$ if $M(N)$ is a terminating decimal.

\n\n

For example, $\\sum\\limits_{N = 5}^{100} D(N)$ is $2438$.

\n\n

Find $\\sum\\limits_{N = 5}^{10000} D(N)$.

", "url": "https://projecteuler.net/problem=183", "answer": "48861552"} {"id": 184, "problem": "Consider the set $I_r$ of points $(x,y)$ with integer co-ordinates in the interior of the circle with radius $r$, centered at the origin, i.e. $x^2 + y^2 \\lt r^2$.\n\nFor a radius of $2$, $I_2$ contains the nine points $(0,0)$, $(1,0)$, $(1,1)$, $(0,1)$, $(-1,1)$, $(-1,0)$, $(-1,-1)$, $(0,-1)$ and $(1,-1)$. There are eight triangles having all three vertices in $I_2$ which contain the origin in the interior. Two of them are shown below, the others are obtained from these by rotation.\n\nFor a radius of $3$, there are $360$ triangles containing the origin in the interior and having all vertices in $I_3$ and for $I_5$ the number is $10600$.\n\nHow many triangles are there containing the origin in the interior and having all three vertices in $I_{105}$?", "raw_html": "

Consider the set $I_r$ of points $(x,y)$ with integer co-ordinates in the interior of the circle with radius $r$, centered at the origin, i.e. $x^2 + y^2 \\lt r^2$.

\n

For a radius of $2$, $I_2$ contains the nine points $(0,0)$, $(1,0)$, $(1,1)$, $(0,1)$, $(-1,1)$, $(-1,0)$, $(-1,-1)$, $(0,-1)$ and $(1,-1)$. There are eight triangles having all three vertices in $I_2$ which contain the origin in the interior. Two of them are shown below, the others are obtained from these by rotation.

\n

\"\"

\n\n

For a radius of $3$, there are $360$ triangles containing the origin in the interior and having all vertices in $I_3$ and for $I_5$ the number is $10600$.

\n\n

How many triangles are there containing the origin in the interior and having all three vertices in $I_{105}$?

", "url": "https://projecteuler.net/problem=184", "answer": "1725323624056"} {"id": 185, "problem": "The game Number Mind is a variant of the well known game Master Mind.\n\nInstead of coloured pegs, you have to guess a secret sequence of digits. After each guess you're only told in how many places you've guessed the correct digit. So, if the sequence was 1234 and you guessed 2036, you'd be told that you have one correct digit; however, you would NOT be told that you also have another digit in the wrong place.\n\nFor instance, given the following guesses for a 5-digit secret sequence,\n\n90342 ;2 correct\n\n70794 ;0 correct\n\n39458 ;2 correct\n\n34109 ;1 correct\n\n51545 ;2 correct\n\n12531 ;1 correct\n\nThe correct sequence 39542 is unique.\n\nBased on the following guesses,\n\n5616185650518293 ;2 correct\n\n3847439647293047 ;1 correct\n\n5855462940810587 ;3 correct\n\n9742855507068353 ;3 correct\n\n4296849643607543 ;3 correct\n\n3174248439465858 ;1 correct\n\n4513559094146117 ;2 correct\n\n7890971548908067 ;3 correct\n\n8157356344118483 ;1 correct\n\n2615250744386899 ;2 correct\n\n8690095851526254 ;3 correct\n\n6375711915077050 ;1 correct\n\n6913859173121360 ;1 correct\n\n6442889055042768 ;2 correct\n\n2321386104303845 ;0 correct\n\n2326509471271448 ;2 correct\n\n5251583379644322 ;2 correct\n\n1748270476758276 ;3 correct\n\n4895722652190306 ;1 correct\n\n3041631117224635 ;3 correct\n\n1841236454324589 ;3 correct\n\n2659862637316867 ;2 correct\n\nFind the unique 16-digit secret sequence.", "raw_html": "

The game Number Mind is a variant of the well known game Master Mind.

\n

Instead of coloured pegs, you have to guess a secret sequence of digits. After each guess you're only told in how many places you've guessed the correct digit. So, if the sequence was 1234 and you guessed 2036, you'd be told that you have one correct digit; however, you would NOT be told that you also have another digit in the wrong place.

\n\n

For instance, given the following guesses for a 5-digit secret sequence,

\n

90342 ;2 correct
\n70794 ;0 correct
\n39458 ;2 correct
\n34109 ;1 correct
\n51545 ;2 correct
\n12531 ;1 correct

\n

The correct sequence 39542 is unique.

\n\n

Based on the following guesses,

\n\n

5616185650518293 ;2 correct
\n3847439647293047 ;1 correct
\n5855462940810587 ;3 correct
\n9742855507068353 ;3 correct
\n4296849643607543 ;3 correct
\n3174248439465858 ;1 correct
\n4513559094146117 ;2 correct
\n7890971548908067 ;3 correct
\n8157356344118483 ;1 correct
\n2615250744386899 ;2 correct
\n8690095851526254 ;3 correct
\n6375711915077050 ;1 correct
\n6913859173121360 ;1 correct
\n6442889055042768 ;2 correct
\n2321386104303845 ;0 correct
\n2326509471271448 ;2 correct
\n5251583379644322 ;2 correct
\n1748270476758276 ;3 correct
\n4895722652190306 ;1 correct
\n3041631117224635 ;3 correct
\n1841236454324589 ;3 correct
\n2659862637316867 ;2 correct

\n\n

Find the unique 16-digit secret sequence.

", "url": "https://projecteuler.net/problem=185", "answer": "4640261571849533"} {"id": 186, "problem": "Here are the records from a busy telephone system with one million users:\n\n| RecNr | Caller | Called |\n| --- | --- | --- |\n| $1$ | $200007$ | $100053$ |\n| $2$ | $600183$ | $500439$ |\n| $3$ | $600863$ | $701497$ |\n| $\\cdots$ | $\\cdots$ | $\\cdots$ |\n\nThe telephone number of the caller and the called number in record $n$ are $\\operatorname{Caller}(n) = S_{2n-1}$ and $\\operatorname{Called}(n) = S_{2n}$ where $S_{1,2,3,\\dots}$ come from the \"Lagged Fibonacci Generator\":\n\nFor $1 \\le k \\le 55$, $S_k = [100003 - 200003k + 300007k^3] \\pmod{1000000}$.\n\nFor $56 \\le k$, $S_k = [S_{k-24} + S_{k-55}] \\pmod{1000000}$.\n\nIf $\\operatorname{Caller}(n) = \\operatorname{Called}(n)$ then the user is assumed to have misdialled and the call fails; otherwise the call is successful.\n\nFrom the start of the records, we say that any pair of users $X$ and $Y$ are friends if $X$ calls $Y$ or vice-versa. Similarly, $X$ is a friend of a friend of $Z$ if $X$ is a friend of $Y$ and $Y$ is a friend of $Z$; and so on for longer chains.\n\nThe Prime Minister's phone number is $524287$. After how many successful calls, not counting misdials, will $99\\%$ of the users (including the PM) be a friend, or a friend of a friend etc., of the Prime Minister?", "raw_html": "

Here are the records from a busy telephone system with one million users:

\n
\n\n
RecNrCallerCalled
$1$$200007$$100053$
$2$$600183$$500439$
$3$$600863$$701497$
$\\cdots$$\\cdots$$\\cdots$
\n

The telephone number of the caller and the called number in record $n$ are $\\operatorname{Caller}(n) = S_{2n-1}$ and $\\operatorname{Called}(n) = S_{2n}$ where $S_{1,2,3,\\dots}$ come from the \"Lagged Fibonacci Generator\":

\n\n

For $1 \\le k \\le 55$, $S_k = [100003 - 200003k + 300007k^3] \\pmod{1000000}$.
\nFor $56 \\le k$, $S_k = [S_{k-24} + S_{k-55}] \\pmod{1000000}$.

\n\n

If $\\operatorname{Caller}(n) = \\operatorname{Called}(n)$ then the user is assumed to have misdialled and the call fails; otherwise the call is successful.

\n\n

From the start of the records, we say that any pair of users $X$ and $Y$ are friends if $X$ calls $Y$ or vice-versa. Similarly, $X$ is a friend of a friend of $Z$ if $X$ is a friend of $Y$ and $Y$ is a friend of $Z$; and so on for longer chains.

\n\n

The Prime Minister's phone number is $524287$. After how many successful calls, not counting misdials, will $99\\%$ of the users (including the PM) be a friend, or a friend of a friend etc., of the Prime Minister?

", "url": "https://projecteuler.net/problem=186", "answer": "2325629"} {"id": 187, "problem": "A composite is a number containing at least two prime factors. For example, $15 = 3 \\times 5$; $9 = 3 \\times 3$; $12 = 2 \\times 2 \\times 3$.\n\nThere are ten composites below thirty containing precisely two, not necessarily distinct, prime factors:\n$4, 6, 9, 10, 14, 15, 21, 22, 25, 26$.\n\nHow many composite integers, $n \\lt 10^8$, have precisely two, not necessarily distinct, prime factors?", "raw_html": "

A composite is a number containing at least two prime factors. For example, $15 = 3 \\times 5$; $9 = 3 \\times 3$; $12 = 2 \\times 2 \\times 3$.

\n\n

There are ten composites below thirty containing precisely two, not necessarily distinct, prime factors:\n$4, 6, 9, 10, 14, 15, 21, 22, 25, 26$.

\n\n

How many composite integers, $n \\lt 10^8$, have precisely two, not necessarily distinct, prime factors?

", "url": "https://projecteuler.net/problem=187", "answer": "17427258"} {"id": 188, "problem": "The hyperexponentiation or tetration of a number $a$ by a positive integer $b$, denoted by $a\\mathbin{\\uparrow \\uparrow}b$ or $^b a$, is recursively defined by:\n\n$a \\mathbin{\\uparrow \\uparrow} 1 = a$,\n\n$a \\mathbin{\\uparrow \\uparrow} (k+1) = a^{(a \\mathbin{\\uparrow \\uparrow} k)}$.\n\nThus we have e.g. $3 \\mathbin{\\uparrow \\uparrow} 2 = 3^3 = 27$, hence $3 \\mathbin{\\uparrow \\uparrow} 3 = 3^{27} = 7625597484987$ and $3 \\mathbin{\\uparrow \\uparrow} 4$ is roughly $10^{3.6383346400240996 \\cdot 10^{12}}$.\n\nFind the last $8$ digits of $1777 \\mathbin{\\uparrow \\uparrow} 1855$.", "raw_html": "

The hyperexponentiation or tetration of a number $a$ by a positive integer $b$, denoted by $a\\mathbin{\\uparrow \\uparrow}b$ or $^b a$, is recursively defined by:

\n$a \\mathbin{\\uparrow \\uparrow} 1 = a$,
\n$a \\mathbin{\\uparrow \\uparrow} (k+1) = a^{(a \\mathbin{\\uparrow \\uparrow} k)}$.

\n

\nThus we have e.g. $3 \\mathbin{\\uparrow \\uparrow} 2 = 3^3 = 27$, hence $3 \\mathbin{\\uparrow \\uparrow} 3 = 3^{27} = 7625597484987$ and $3 \\mathbin{\\uparrow \\uparrow} 4$ is roughly $10^{3.6383346400240996 \\cdot 10^{12}}$.

\n

Find the last $8$ digits of $1777 \\mathbin{\\uparrow \\uparrow} 1855$.

", "url": "https://projecteuler.net/problem=188", "answer": "95962097"} {"id": 189, "problem": "Consider the following configuration of $64$ triangles:\n\nWe wish to colour the interior of each triangle with one of three colours: red, green or blue, so that no two neighbouring triangles have the same colour. Such a colouring shall be called valid. Here, two triangles are said to be neighbouring if they share an edge.\n\nNote: if they only share a vertex, then they are not neighbours.\n\n\n\nFor example, here is a valid colouring of the above grid:\n\nA colouring $C^\\prime$ which is obtained from a colouring $C$ by rotation or reflection is considered distinct from $C$ unless the two are identical.\n\nHow many distinct valid colourings are there for the above configuration?", "raw_html": "

Consider the following configuration of $64$ triangles:

\n\n
\"\"
\n\n

We wish to colour the interior of each triangle with one of three colours: red, green or blue, so that no two neighbouring triangles have the same colour. Such a colouring shall be called valid. Here, two triangles are said to be neighbouring if they share an edge.
\nNote: if they only share a vertex, then they are not neighbours.

\n\n

For example, here is a valid colouring of the above grid:

\n
\"\"
\n\n

A colouring $C^\\prime$ which is obtained from a colouring $C$ by rotation or reflection is considered distinct from $C$ unless the two are identical.

\n\n

How many distinct valid colourings are there for the above configuration?

", "url": "https://projecteuler.net/problem=189", "answer": "10834893628237824"} {"id": 190, "problem": "Let $S_m = (x_1, x_2, \\dots , x_m)$ be the $m$-tuple of positive real numbers with $x_1 + x_2 + \\cdots + x_m = m$ for which $P_m = x_1 \\cdot x_2^2 \\cdot \\cdots \\cdot x_m^m$ is maximised.\n\nFor example, it can be verified that $\\lfloor P_{10}\\rfloor = 4112$ ($\\lfloor \\, \\rfloor$ is the integer part function).\n\nFind $\\sum\\limits_{m = 2}^{15} \\lfloor P_m \\rfloor$.", "raw_html": "

Let $S_m = (x_1, x_2, \\dots , x_m)$ be the $m$-tuple of positive real numbers with $x_1 + x_2 + \\cdots + x_m = m$ for which $P_m = x_1 \\cdot x_2^2 \\cdot \\cdots \\cdot x_m^m$ is maximised.

\n\n

For example, it can be verified that $\\lfloor P_{10}\\rfloor = 4112$ ($\\lfloor \\, \\rfloor$ is the integer part function).

\n\n

Find $\\sum\\limits_{m = 2}^{15} \\lfloor P_m \\rfloor$.

", "url": "https://projecteuler.net/problem=190", "answer": "371048281"} {"id": 191, "problem": "A particular school offers cash rewards to children with good attendance and punctuality. If they are absent for three consecutive days or late on more than one occasion then they forfeit their prize.\n\nDuring an n-day period a trinary string is formed for each child consisting of L's (late), O's (on time), and A's (absent).\n\nAlthough there are eighty-one trinary strings for a 4-day period that can be formed, exactly forty-three strings would lead to a prize:\n\nOOOO OOOA OOOL OOAO OOAA OOAL OOLO OOLA OAOO OAOA\n\nOAOL OAAO OAAL OALO OALA OLOO OLOA OLAO OLAA AOOO\n\nAOOA AOOL AOAO AOAA AOAL AOLO AOLA AAOO AAOA AAOL\n\nAALO AALA ALOO ALOA ALAO ALAA LOOO LOOA LOAO LOAA\n\nLAOO LAOA LAAO\n\nHow many \"prize\" strings exist over a 30-day period?", "raw_html": "

A particular school offers cash rewards to children with good attendance and punctuality. If they are absent for three consecutive days or late on more than one occasion then they forfeit their prize.

\n\n

During an n-day period a trinary string is formed for each child consisting of L's (late), O's (on time), and A's (absent).

\n\n

Although there are eighty-one trinary strings for a 4-day period that can be formed, exactly forty-three strings would lead to a prize:

\n\n

OOOO OOOA OOOL OOAO OOAA OOAL OOLO OOLA OAOO OAOA
\nOAOL OAAO OAAL OALO OALA OLOO OLOA OLAO OLAA AOOO
\nAOOA AOOL AOAO AOAA AOAL AOLO AOLA AAOO AAOA AAOL
\nAALO AALA ALOO ALOA ALAO ALAA LOOO LOOA LOAO LOAA
\nLAOO LAOA LAAO

\n\n

How many \"prize\" strings exist over a 30-day period?

", "url": "https://projecteuler.net/problem=191", "answer": "1918080160"} {"id": 192, "problem": "Let $x$ be a real number.\n\nA best approximation to $x$ for the denominator bound $d$ is a rational number $\\frac r s $ in reduced form, with $s \\le d$, such that any rational number which is closer to $x$ than $\\frac r s$ has a denominator larger than $d$:\n\n$|\\frac p q -x | < |\\frac r s -x| \\Rightarrow q > d$\n\nFor example, the best approximation to $\\sqrt {13}$ for the denominator bound 20 is $\\frac {18} 5$ and the best approximation to $\\sqrt {13}$ for the denominator bound 30 is $\\frac {101}{28}$.\n\nFind the sum of all denominators of the best approximations to $\\sqrt n$ for the denominator bound $10^{12}$, where $n$ is not a perfect square and $ 1 < n \\le 100000$.", "raw_html": "

Let $x$ be a real number.
\nA best approximation to $x$ for the denominator bound $d$ is a rational number $\\frac r s $ in reduced form, with $s \\le d$, such that any rational number which is closer to $x$ than $\\frac r s$ has a denominator larger than $d$:

\n\n
$|\\frac p q -x | < |\\frac r s -x| \\Rightarrow q > d$\n
\n\n

For example, the best approximation to $\\sqrt {13}$ for the denominator bound 20 is $\\frac {18} 5$ and the best approximation to $\\sqrt {13}$ for the denominator bound 30 is $\\frac {101}{28}$.

\n\n

Find the sum of all denominators of the best approximations to $\\sqrt n$ for the denominator bound $10^{12}$, where $n$ is not a perfect square and $ 1 < n \\le 100000$.

", "url": "https://projecteuler.net/problem=192", "answer": "57060635927998347"} {"id": 193, "problem": "A positive integer $n$ is called squarefree, if no square of a prime divides $n$, thus $1, 2, 3, 5, 6, 7, 10, 11$ are squarefree, but not $4, 8, 9, 12$.\n\nHow many squarefree numbers are there below $2^{50}$?", "raw_html": "

A positive integer $n$ is called squarefree, if no square of a prime divides $n$, thus $1, 2, 3, 5, 6, 7, 10, 11$ are squarefree, but not $4, 8, 9, 12$.

\n\n

How many squarefree numbers are there below $2^{50}$?

", "url": "https://projecteuler.net/problem=193", "answer": "684465067343069"} {"id": 194, "problem": "Consider graphs built with the units $A$:\nand $B$: , where the units are glued along\nthe vertical edges as in the graph .\n\nA configuration of type $(a, b, c)$ is a graph thus built of $a$ units $A$ and $b$ units $B$, where the graph's vertices are coloured using up to $c$ colours, so that no two adjacent vertices have the same colour.\n\nThe compound graph above is an example of a configuration of type $(2,2,6)$, in fact of type $(2,2,c)$ for all $c \\ge 4$.\n\nLet $N(a, b, c)$ be the number of configurations of type $(a, b, c)$.\n\nFor example, $N(1,0,3) = 24$, $N(0,2,4) = 92928$ and $N(2,2,3) = 20736$.\n\nFind the last $8$ digits of $N(25,75,1984)$.", "raw_html": "

Consider graphs built with the units $A$: \"\"\nand $B$: \"\", where the units are glued along\nthe vertical edges as in the graph \"\".

\n\n

A configuration of type $(a, b, c)$ is a graph thus built of $a$ units $A$ and $b$ units $B$, where the graph's vertices are coloured using up to $c$ colours, so that no two adjacent vertices have the same colour.
\nThe compound graph above is an example of a configuration of type $(2,2,6)$, in fact of type $(2,2,c)$ for all $c \\ge 4$.

\n\n

Let $N(a, b, c)$ be the number of configurations of type $(a, b, c)$.
\nFor example, $N(1,0,3) = 24$, $N(0,2,4) = 92928$ and $N(2,2,3) = 20736$.

\n\n

Find the last $8$ digits of $N(25,75,1984)$.

", "url": "https://projecteuler.net/problem=194", "answer": "61190912"} {"id": 195, "problem": "Let's call an integer sided triangle with exactly one angle of $60$ degrees a $60$-degree triangle.\n\nLet $r$ be the radius of the inscribed circle of such a $60$-degree triangle.\n\nThere are $1234$ $60$-degree triangles for which $r \\le 100$.\n\nLet $T(n)$ be the number of $60$-degree triangles for which $r \\le n$, so\n\n$T(100) = 1234$, $T(1000) = 22767$, and $T(10000) = 359912$.\n\nFind $T(1053779)$.", "raw_html": "

Let's call an integer sided triangle with exactly one angle of $60$ degrees a $60$-degree triangle.
\nLet $r$ be the radius of the inscribed circle of such a $60$-degree triangle.

\n

There are $1234$ $60$-degree triangles for which $r \\le 100$.\n
Let $T(n)$ be the number of $60$-degree triangles for which $r \\le n$, so
\n$T(100) = 1234$, $T(1000) = 22767$, and $T(10000) = 359912$.

\n\n

Find $T(1053779)$.

", "url": "https://projecteuler.net/problem=195", "answer": "75085391"} {"id": 196, "problem": "Build a triangle from all positive integers in the following way:\n\n1\n\n2  3\n\n4  5  6\n\n7  8  9 10\n11 12 13 14 15\n\n16 17 18 19 20 21\n\n22 23 24 25 26 27 28\n29 30 31 32 33 34 35 36\n37 38 39 40 41 42 43 44 45\n\n46 47 48 49 50 51 52 53 54 55\n\n56 57 58 59 60 61 62 63 64 65 66\n\n. . .\n\nEach positive integer has up to eight neighbours in the triangle.\n\nA set of three primes is called a prime triplet if one of the three primes has the other two as neighbours in the triangle.\n\nFor example, in the second row, the prime numbers $2$ and $3$ are elements of some prime triplet.\n\nIf row $8$ is considered, it contains two primes which are elements of some prime triplet, i.e. $29$ and $31$.\n\nIf row $9$ is considered, it contains only one prime which is an element of some prime triplet: $37$.\n\nDefine $S(n)$ as the sum of the primes in row $n$ which are elements of any prime triplet.\n\nThen $S(8)=60$ and $S(9)=37$.\n\nYou are given that $S(10000)=950007619$.\n\nFind $S(5678027) + S(7208785)$.", "raw_html": "

Build a triangle from all positive integers in the following way:

\n\n

 1
\n 2  3
\n 4  5  6
\n 7  8  9 10
11 12 13 14 15
\n16 17 18 19 20 21
\n22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
\n46 47 48 49 50 51 52 53 54 55
\n56 57 58 59 60 61 62 63 64 65 66
\n. . .

\n\n

Each positive integer has up to eight neighbours in the triangle.

\n\n

A set of three primes is called a prime triplet if one of the three primes has the other two as neighbours in the triangle.

\n\n

For example, in the second row, the prime numbers $2$ and $3$ are elements of some prime triplet.

\n\n

If row $8$ is considered, it contains two primes which are elements of some prime triplet, i.e. $29$ and $31$.
\nIf row $9$ is considered, it contains only one prime which is an element of some prime triplet: $37$.

\n\n

Define $S(n)$ as the sum of the primes in row $n$ which are elements of any prime triplet.
\nThen $S(8)=60$ and $S(9)=37$.

\n\n

You are given that $S(10000)=950007619$.

\n\n

Find $S(5678027) + S(7208785)$.

", "url": "https://projecteuler.net/problem=196", "answer": "322303240771079935"} {"id": 197, "problem": "Given is the function $f(x) = \\lfloor 2^{30.403243784 - x^2}\\rfloor \\times 10^{-9}$ ($\\lfloor \\, \\rfloor$ is the floor-function),\n\nthe sequence $u_n$ is defined by $u_0 = -1$ and $u_{n + 1} = f(u_n)$.\n\nFind $u_n + u_{n + 1}$ for $n = 10^{12}$.\n\nGive your answer with $9$ digits after the decimal point.", "raw_html": "

Given is the function $f(x) = \\lfloor 2^{30.403243784 - x^2}\\rfloor \\times 10^{-9}$ ($\\lfloor \\, \\rfloor$ is the floor-function),
\nthe sequence $u_n$ is defined by $u_0 = -1$ and $u_{n + 1} = f(u_n)$.

\n\n

Find $u_n + u_{n + 1}$ for $n = 10^{12}$.
\nGive your answer with $9$ digits after the decimal point.

", "url": "https://projecteuler.net/problem=197", "answer": "1.710637717"} {"id": 198, "problem": "A best approximation to a real number $x$ for the denominator bound $d$ is a rational number $\\frac r s$ (in reduced form) with $s \\le d$, so that any rational number $\\frac p q$ which is closer to $x$ than $\\frac r s$ has $q \\gt d$.\n\nUsually the best approximation to a real number is uniquely determined for all denominator bounds. However, there are some exceptions, e.g. $\\frac 9 {40}$ has the two best approximations $\\frac 1 4$ and $\\frac 1 5$ for the denominator bound $6$.\nWe shall call a real number $x$ ambiguous, if there is at least one denominator bound for which $x$ possesses two best approximations. Clearly, an ambiguous number is necessarily rational.\n\nHow many ambiguous numbers $x=\\frac p q, 0 \\lt x \\lt \\frac 1 {100}$, are there whose denominator $q$ does not exceed $10^8$?", "raw_html": "

A best approximation to a real number $x$ for the denominator bound $d$ is a rational number $\\frac r s$ (in reduced form) with $s \\le d$, so that any rational number $\\frac p q$ which is closer to $x$ than $\\frac r s$ has $q \\gt d$.

\n\n

Usually the best approximation to a real number is uniquely determined for all denominator bounds. However, there are some exceptions, e.g. $\\frac 9 {40}$ has the two best approximations $\\frac 1 4$ and $\\frac 1 5$ for the denominator bound $6$.\nWe shall call a real number $x$ ambiguous, if there is at least one denominator bound for which $x$ possesses two best approximations. Clearly, an ambiguous number is necessarily rational.

\n\n

How many ambiguous numbers $x=\\frac p q, 0 \\lt x \\lt \\frac 1 {100}$, are there whose denominator $q$ does not exceed $10^8$?

", "url": "https://projecteuler.net/problem=198", "answer": "52374425"} {"id": 199, "problem": "Three circles of equal radius are placed inside a larger circle such that each pair of circles is tangent to one another and the inner circles do not overlap. There are four uncovered \"gaps\" which are to be filled iteratively with more tangent circles.\n\nAt each iteration, a maximally sized circle is placed in each gap, which creates more gaps for the next iteration. After $3$ iterations (pictured), there are $108$ gaps and the fraction of the area which is not covered by circles is $0.06790342$, rounded to eight decimal places.\n\nWhat fraction of the area is not covered by circles after $10$ iterations?\n\nGive your answer rounded to eight decimal places using the format x.xxxxxxxx .", "raw_html": "

Three circles of equal radius are placed inside a larger circle such that each pair of circles is tangent to one another and the inner circles do not overlap. There are four uncovered \"gaps\" which are to be filled iteratively with more tangent circles.

\n
\n\"\"
\n

\nAt each iteration, a maximally sized circle is placed in each gap, which creates more gaps for the next iteration. After $3$ iterations (pictured), there are $108$ gaps and the fraction of the area which is not covered by circles is $0.06790342$, rounded to eight decimal places.\n

\n

\nWhat fraction of the area is not covered by circles after $10$ iterations?
\nGive your answer rounded to eight decimal places using the format x.xxxxxxxx .\n

", "url": "https://projecteuler.net/problem=199", "answer": "0.00396087"} {"id": 200, "problem": "We shall define a sqube to be a number of the form, $p^2 q^3$, where $p$ and $q$ are distinct primes.\n\nFor example, $200 = 5^2 2^3$ or $120072949 = 23^2 61^3$.\n\nThe first five squbes are $72, 108, 200, 392$, and $500$.\n\nInterestingly, $200$ is also the first number for which you cannot change any single digit to make a prime; we shall call such numbers, prime-proof. The next prime-proof sqube which contains the contiguous sub-string \"$200$\" is $1992008$.\n\nFind the $200$th prime-proof sqube containing the contiguous sub-string \"$200$\".", "raw_html": "

We shall define a sqube to be a number of the form, $p^2 q^3$, where $p$ and $q$ are distinct primes.
\nFor example, $200 = 5^2 2^3$ or $120072949 = 23^2 61^3$.

\n\n

The first five squbes are $72, 108, 200, 392$, and $500$.

\n\n

Interestingly, $200$ is also the first number for which you cannot change any single digit to make a prime; we shall call such numbers, prime-proof. The next prime-proof sqube which contains the contiguous sub-string \"$200$\" is $1992008$.

\n\n

Find the $200$th prime-proof sqube containing the contiguous sub-string \"$200$\".

", "url": "https://projecteuler.net/problem=200", "answer": "229161792008"} {"id": 201, "problem": "For any set $A$ of numbers, let $\\operatorname{sum}(A)$ be the sum of the elements of $A$.\n\nConsider the set $B = \\{1,3,6,8,10,11\\}$.\nThere are $20$ subsets of $B$ containing three elements, and their sums are:\n\n$$\\begin{align}\n\\operatorname{sum}(\\{1,3,6\\}) &= 10,\\\\\n\\operatorname{sum}(\\{1,3,8\\}) &= 12,\\\\\n\\operatorname{sum}(\\{1,3,10\\}) &= 14,\\\\\n\\operatorname{sum}(\\{1,3,11\\}) &= 15,\\\\\n\\operatorname{sum}(\\{1,6,8\\}) &= 15,\\\\\n\\operatorname{sum}(\\{1,6,10\\}) &= 17,\\\\\n\\operatorname{sum}(\\{1,6,11\\}) &= 18,\\\\\n\\operatorname{sum}(\\{1,8,10\\}) &= 19,\\\\\n\\operatorname{sum}(\\{1,8,11\\}) &= 20,\\\\\n\\operatorname{sum}(\\{1,10,11\\}) &= 22,\\\\\n\\operatorname{sum}(\\{3,6,8\\}) &= 17,\\\\\n\\operatorname{sum}(\\{3,6,10\\}) &= 19,\\\\\n\\operatorname{sum}(\\{3,6,11\\}) &= 20,\\\\\n\\operatorname{sum}(\\{3,8,10\\}) &= 21,\\\\\n\\operatorname{sum}(\\{3,8,11\\}) &= 22,\\\\\n\\operatorname{sum}(\\{3,10,11\\}) &= 24,\\\\\n\\operatorname{sum}(\\{6,8,10\\}) &= 24,\\\\\n\\operatorname{sum}(\\{6,8,11\\}) &= 25,\\\\\n\\operatorname{sum}(\\{6,10,11\\}) &= 27,\\\\\n\\operatorname{sum}(\\{8,10,11\\}) &= 29.\n\\end{align}$$\n\nSome of these sums occur more than once, others are unique.\n\nFor a set $A$, let $U(A,k)$ be the set of unique sums of $k$-element subsets of $A$, in our example we find $U(B,3) = \\{10,12,14,18,21,25,27,29\\}$ and $\\operatorname{sum}(U(B,3)) = 156$.\n\nNow consider the $100$-element set $S = \\{1^2, 2^2, \\dots, 100^2\\}$.\n\nS has $100891344545564193334812497256$ $50$-element subsets.\n\nDetermine the sum of all integers which are the sum of exactly one of the $50$-element subsets of $S$, i.e. find $\\operatorname{sum}(U(S,50))$.", "raw_html": "

For any set $A$ of numbers, let $\\operatorname{sum}(A)$ be the sum of the elements of $A$.
\nConsider the set $B = \\{1,3,6,8,10,11\\}$.
There are $20$ subsets of $B$ containing three elements, and their sums are:

\n\n$$\\begin{align}\n\\operatorname{sum}(\\{1,3,6\\}) &= 10,\\\\\n\\operatorname{sum}(\\{1,3,8\\}) &= 12,\\\\\n\\operatorname{sum}(\\{1,3,10\\}) &= 14,\\\\\n\\operatorname{sum}(\\{1,3,11\\}) &= 15,\\\\\n\\operatorname{sum}(\\{1,6,8\\}) &= 15,\\\\\n\\operatorname{sum}(\\{1,6,10\\}) &= 17,\\\\\n\\operatorname{sum}(\\{1,6,11\\}) &= 18,\\\\\n\\operatorname{sum}(\\{1,8,10\\}) &= 19,\\\\\n\\operatorname{sum}(\\{1,8,11\\}) &= 20,\\\\\n\\operatorname{sum}(\\{1,10,11\\}) &= 22,\\\\\n\\operatorname{sum}(\\{3,6,8\\}) &= 17,\\\\\n\\operatorname{sum}(\\{3,6,10\\}) &= 19,\\\\\n\\operatorname{sum}(\\{3,6,11\\}) &= 20,\\\\\n\\operatorname{sum}(\\{3,8,10\\}) &= 21,\\\\\n\\operatorname{sum}(\\{3,8,11\\}) &= 22,\\\\\n\\operatorname{sum}(\\{3,10,11\\}) &= 24,\\\\\n\\operatorname{sum}(\\{6,8,10\\}) &= 24,\\\\\n\\operatorname{sum}(\\{6,8,11\\}) &= 25,\\\\\n\\operatorname{sum}(\\{6,10,11\\}) &= 27,\\\\\n\\operatorname{sum}(\\{8,10,11\\}) &= 29.\n\\end{align}$$\n\n

Some of these sums occur more than once, others are unique.
\nFor a set $A$, let $U(A,k)$ be the set of unique sums of $k$-element subsets of $A$, in our example we find $U(B,3) = \\{10,12,14,18,21,25,27,29\\}$ and $\\operatorname{sum}(U(B,3)) = 156$.

\n\n

Now consider the $100$-element set $S = \\{1^2, 2^2, \\dots, 100^2\\}$.
\nS has $100891344545564193334812497256$ $50$-element subsets.

\n\n

Determine the sum of all integers which are the sum of exactly one of the $50$-element subsets of $S$, i.e. find $\\operatorname{sum}(U(S,50))$.

", "url": "https://projecteuler.net/problem=201", "answer": "115039000"} {"id": 202, "problem": "Three mirrors are arranged in the shape of an equilateral triangle, with their reflective surfaces pointing inwards. There is an infinitesimal gap at each vertex of the triangle through which a laser beam may pass.\n\nLabel the vertices $A$, $B$ and $C$. There are $2$ ways in which a laser beam may enter vertex $C$, bounce off $11$ surfaces, then exit through the same vertex: one way is shown below; the other is the reverse of that.\n\n\n\nThere are $80840$ ways in which a laser beam may enter vertex $C$, bounce off $1000001$ surfaces, then exit through the same vertex.\n\nIn how many ways can a laser beam enter at vertex $C$, bounce off $12017639147$ surfaces, then exit through the same vertex?", "raw_html": "

Three mirrors are arranged in the shape of an equilateral triangle, with their reflective surfaces pointing inwards. There is an infinitesimal gap at each vertex of the triangle through which a laser beam may pass.

\n\n

Label the vertices $A$, $B$ and $C$. There are $2$ ways in which a laser beam may enter vertex $C$, bounce off $11$ surfaces, then exit through the same vertex: one way is shown below; the other is the reverse of that.

\n\n
\n \"\"
\n\n

There are $80840$ ways in which a laser beam may enter vertex $C$, bounce off $1000001$ surfaces, then exit through the same vertex.

\n\n

In how many ways can a laser beam enter at vertex $C$, bounce off $12017639147$ surfaces, then exit through the same vertex?

", "url": "https://projecteuler.net/problem=202", "answer": "1209002624"} {"id": 203, "problem": "The binomial coefficients $\\displaystyle \\binom n k$ can be arranged in triangular form, Pascal's triangle, like this:\n\n| | 1 | |\n| | 1 | | 1 | |\n| | 1 | | 2 | | 1 | |\n| | 1 | | 3 | | 3 | | 1 | |\n| | 1 | | 4 | | 6 | | 4 | | 1 | |\n| | 1 | | 5 | | 10 | | 10 | | 5 | | 1 | |\n| | 1 | | 6 | | 15 | | 20 | | 15 | | 6 | | 1 | |\n| 1 | | 7 | | 21 | | 35 | | 35 | | 21 | | 7 | | 1 |\n\n.........\n\nIt can be seen that the first eight rows of Pascal's triangle contain twelve distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15, 20, 21 and 35.\n\nA positive integer n is called squarefree if no square of a prime divides n.\nOf the twelve distinct numbers in the first eight rows of Pascal's triangle, all except 4 and 20 are squarefree.\nThe sum of the distinct squarefree numbers in the first eight rows is 105.\n\nFind the sum of the distinct squarefree numbers in the first 51 rows of Pascal's triangle.", "raw_html": "

The binomial coefficients $\\displaystyle \\binom n k$ can be arranged in triangular form, Pascal's triangle, like this:

\n\n
\n
1
11
121
1331
14641
15101051
1615201561
172135352171
\n.........\n
\n\n

It can be seen that the first eight rows of Pascal's triangle contain twelve distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15, 20, 21 and 35.

\n\n

A positive integer n is called squarefree if no square of a prime divides n.\nOf the twelve distinct numbers in the first eight rows of Pascal's triangle, all except 4 and 20 are squarefree.\nThe sum of the distinct squarefree numbers in the first eight rows is 105.

\n\n

Find the sum of the distinct squarefree numbers in the first 51 rows of Pascal's triangle.

", "url": "https://projecteuler.net/problem=203", "answer": "34029210557338"} {"id": 204, "problem": "A Hamming number is a positive number which has no prime factor larger than $5$.\n\nSo the first few Hamming numbers are $1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15$.\n\nThere are $1105$ Hamming numbers not exceeding $10^8$.\n\nWe will call a positive number a generalised Hamming number of type $n$, if it has no prime factor larger than $n$.\n\nHence the Hamming numbers are the generalised Hamming numbers of type $5$.\n\nHow many generalised Hamming numbers of type $100$ are there which don't exceed $10^9$?", "raw_html": "

A Hamming number is a positive number which has no prime factor larger than $5$.
\nSo the first few Hamming numbers are $1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15$.
\nThere are $1105$ Hamming numbers not exceeding $10^8$.

\n\n

We will call a positive number a generalised Hamming number of type $n$, if it has no prime factor larger than $n$.
\nHence the Hamming numbers are the generalised Hamming numbers of type $5$.

\n\n

How many generalised Hamming numbers of type $100$ are there which don't exceed $10^9$?

", "url": "https://projecteuler.net/problem=204", "answer": "2944730"} {"id": 205, "problem": "Peter has nine four-sided (pyramidal) dice, each with faces numbered $1, 2, 3, 4$.\n\nColin has six six-sided (cubic) dice, each with faces numbered $1, 2, 3, 4, 5, 6$.\n\nPeter and Colin roll their dice and compare totals: the highest total wins. The result is a draw if the totals are equal.\n\nWhat is the probability that Pyramidal Peter beats Cubic Colin? Give your answer rounded to seven decimal places in the form 0.abcdefg.", "raw_html": "

Peter has nine four-sided (pyramidal) dice, each with faces numbered $1, 2, 3, 4$.
\nColin has six six-sided (cubic) dice, each with faces numbered $1, 2, 3, 4, 5, 6$.

\n\n

Peter and Colin roll their dice and compare totals: the highest total wins. The result is a draw if the totals are equal.

\n\n

What is the probability that Pyramidal Peter beats Cubic Colin? Give your answer rounded to seven decimal places in the form 0.abcdefg.

", "url": "https://projecteuler.net/problem=205", "answer": "0.5731441"} {"id": 206, "problem": "Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,\nwhere each “_” is a single digit.", "raw_html": "

Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
where each “_” is a single digit.

", "url": "https://projecteuler.net/problem=206", "answer": "1389019170"} {"id": 207, "problem": "For some positive integers $k$, there exists an integer partition of the form $4^t = 2^t + k$,\n\nwhere $4^t$, $2^t$, and $k$ are all positive integers and $t$ is a real number.\n\nThe first two such partitions are $4^1 = 2^1 + 2$ and $4^{1.5849625\\cdots} = 2^{1.5849625\\cdots} + 6$.\n\nPartitions where $t$ is also an integer are called perfect.\n\nFor any $m \\ge 1$ let $P(m)$ be the proportion of such partitions that are perfect with $k \\le m$.\n\nThus $P(6) = 1/2$.\n\nIn the following table are listed some values of $P(m)$.\n\n$$\\begin{align}\nP(5) &= 1/1\\\\\nP(10) &= 1/2\\\\\nP(15) &= 2/3\\\\\nP(20) &= 1/2\\\\\nP(25) &= 1/2\\\\\nP(30) &= 2/5\\\\\n\\cdots &\\\\\nP(180) &= 1/4\\\\\nP(185) &= 3/13\n\\end{align}$$\n\nFind the smallest $m$ for which $P(m) \\lt 1/12345$.", "raw_html": "

For some positive integers $k$, there exists an integer partition of the form $4^t = 2^t + k$,
\nwhere $4^t$, $2^t$, and $k$ are all positive integers and $t$ is a real number.

\n\n

The first two such partitions are $4^1 = 2^1 + 2$ and $4^{1.5849625\\cdots} = 2^{1.5849625\\cdots} + 6$.

\n\n

Partitions where $t$ is also an integer are called perfect.
\nFor any $m \\ge 1$ let $P(m)$ be the proportion of such partitions that are perfect with $k \\le m$.
\nThus $P(6) = 1/2$.

\n\n

In the following table are listed some values of $P(m)$.

\n$$\\begin{align}\nP(5) &= 1/1\\\\\nP(10) &= 1/2\\\\\nP(15) &= 2/3\\\\\nP(20) &= 1/2\\\\\nP(25) &= 1/2\\\\\nP(30) &= 2/5\\\\\n\\cdots &\\\\\nP(180) &= 1/4\\\\\nP(185) &= 3/13\n\\end{align}$$\n\n\n

Find the smallest $m$ for which $P(m) \\lt 1/12345$.

", "url": "https://projecteuler.net/problem=207", "answer": "44043947822"} {"id": 208, "problem": "A robot moves in a series of one-fifth circular arcs ($72^\\circ$), with a free choice of a clockwise or an anticlockwise arc for each step, but no turning on the spot.\n\nOne of $70932$ possible closed paths of $25$ arcs starting northward is\n\nGiven that the robot starts facing North, how many journeys of $70$ arcs in length can it take that return it, after the final arc, to its starting position?\n\n(Any arc may be traversed multiple times.)", "raw_html": "

A robot moves in a series of one-fifth circular arcs ($72^\\circ$), with a free choice of a clockwise or an anticlockwise arc for each step, but no turning on the spot.

\n\n

One of $70932$ possible closed paths of $25$ arcs starting northward is

\n
\n\"\"
\n\n

Given that the robot starts facing North, how many journeys of $70$ arcs in length can it take that return it, after the final arc, to its starting position?
\n(Any arc may be traversed multiple times.) \n

", "url": "https://projecteuler.net/problem=208", "answer": "331951449665644800"} {"id": 209, "problem": "A $k$-input binary truth table is a map from $k$ input bits (binary digits, $0$ [false] or $1$ [true]) to $1$ output bit. For example, the $2$-input binary truth tables for the logical $\\mathbin{\\text{AND}}$ and $\\mathbin{\\text{XOR}}$ functions are:\n\n| $x$ | $y$ | $x \\mathbin{\\text{AND}} y$ |\n| --- | --- | --- |\n| $0$ | $0$ | $0$ |\n| $0$ | $1$ | $0$ |\n| $1$ | $0$ | $0$ |\n| $1$ | $1$ | $1$ |\n\n| $x$ | $y$ | $x\\mathbin{\\text{XOR}}y$ |\n| --- | --- | --- |\n| $0$ | $0$ | $0$ |\n| $0$ | $1$ | $1$ |\n| $1$ | $0$ | $1$ |\n| $1$ | $1$ | $0$ |\n\nHow many $6$-input binary truth tables, $\\tau$, satisfy the formula\n$$\\tau(a, b, c, d, e, f) \\mathbin{\\text{AND}} \\tau(b, c, d, e, f, a \\mathbin{\\text{XOR}} (b \\mathbin{\\text{AND}} c)) = 0$$\nfor all $6$-bit inputs $(a, b, c, d, e, f)$?", "raw_html": "

A $k$-input binary truth table is a map from $k$ input bits (binary digits, $0$ [false] or $1$ [true]) to $1$ output bit. For example, the $2$-input binary truth tables for the logical $\\mathbin{\\text{AND}}$ and $\\mathbin{\\text{XOR}}$ functions are:

\n
\n\n\n\n
$x$$y$$x \\mathbin{\\text{AND}} y$
$0$$0$$0$
$0$$1$$0$
$1$$0$$0$
$1$$1$$1$
\n
\n
\n\n\n\n
$x$$y$$x\\mathbin{\\text{XOR}}y$
$0$$0$$0$
$0$$1$$1$
$1$$0$$1$
$1$$1$$0$
\n
\n
\n

How many $6$-input binary truth tables, $\\tau$, satisfy the formula\n$$\\tau(a, b, c, d, e, f) \\mathbin{\\text{AND}} \\tau(b, c, d, e, f, a \\mathbin{\\text{XOR}} (b \\mathbin{\\text{AND}} c)) = 0$$\nfor all $6$-bit inputs $(a, b, c, d, e, f)$?\n

", "url": "https://projecteuler.net/problem=209", "answer": "15964587728784"} {"id": 210, "problem": "Consider the set $S(r)$ of points $(x,y)$ with integer coordinates satisfying $|x| + |y| \\le r$.\n\nLet $O$ be the point $(0,0)$ and $C$ the point $(r/4,r/4)$.\n\nLet $N(r)$ be the number of points $B$ in $S(r)$, so that the triangle $OBC$ has an obtuse angle, i.e. the largest angle $\\alpha$ satisfies $90^\\circ \\lt \\alpha \\lt 180^\\circ$.\n\nSo, for example, $N(4)=24$ and $N(8)=100$.\n\nWhat is $N(1\\,000\\,000\\,000)$?", "raw_html": "Consider the set $S(r)$ of points $(x,y)$ with integer coordinates satisfying $|x| + |y| \\le r$.
\nLet $O$ be the point $(0,0)$ and $C$ the point $(r/4,r/4)$.
\nLet $N(r)$ be the number of points $B$ in $S(r)$, so that the triangle $OBC$ has an obtuse angle, i.e. the largest angle $\\alpha$ satisfies $90^\\circ \\lt \\alpha \\lt 180^\\circ$.
\nSo, for example, $N(4)=24$ and $N(8)=100$.\n

\nWhat is $N(1\\,000\\,000\\,000)$?\n

", "url": "https://projecteuler.net/problem=210", "answer": "1598174770174689458"} {"id": 211, "problem": "For a positive integer $n$, let $\\sigma_2(n)$ be the sum of the squares of its divisors. For example,\n$$\\sigma_2(10) = 1 + 4 + 25 + 100 = 130.$$\n\nFind the sum of all $n$, $0 \\lt n \\lt 64\\,000\\,000$ such that $\\sigma_2(n)$ is a perfect square.", "raw_html": "

For a positive integer $n$, let $\\sigma_2(n)$ be the sum of the squares of its divisors. For example,\n$$\\sigma_2(10) = 1 + 4 + 25 + 100 = 130.$$

\n

Find the sum of all $n$, $0 \\lt n \\lt 64\\,000\\,000$ such that $\\sigma_2(n)$ is a perfect square.

", "url": "https://projecteuler.net/problem=211", "answer": "1922364685"} {"id": 212, "problem": "An axis-aligned cuboid, specified by parameters $\\{(x_0, y_0, z_0), (dx, dy, dz)\\}$, consists of all points $(X,Y,Z)$ such that $x_0 \\le X \\le x_0 + dx$, $y_0 \\le Y \\le y_0 + dy$ and $z_0 \\le Z \\le z_0 + dz$. The volume of the cuboid is the product, $dx \\times dy \\times dz$. The combined volume of a collection of cuboids is the volume of their union and will be less than the sum of the individual volumes if any cuboids overlap.\n\nLet $C_1, \\dots, C_{50000}$ be a collection of $50000$ axis-aligned cuboids such that $C_n$ has parameters\n\n$$\\begin{align}\nx_0 &= S_{6n - 5} \\bmod 10000\\\\\ny_0 &= S_{6n - 4} \\bmod 10000\\\\\nz_0 &= S_{6n - 3} \\bmod 10000\\\\\ndx &= 1 + (S_{6n - 2} \\bmod 399)\\\\\ndy &= 1 + (S_{6n - 1} \\bmod 399)\\\\\ndz &= 1 + (S_{6n} \\bmod 399)\n\\end{align}$$\n\nwhere $S_1,\\dots,S_{300000}$ come from the \"Lagged Fibonacci Generator\":\n\n- For $1 \\le k \\le 55$, $S_k = [100003 - 200003k + 300007k^3] \\pmod{1000000}$.\n- For $56 \\le k$, $S_k = [S_{k -24} + S_{k - 55}] \\pmod{1000000}$.\n\nThus, $C_1$ has parameters $\\{(7,53,183),(94,369,56)\\}$, $C_2$ has parameters $\\{(2383,3563,5079),(42,212,344)\\}$, and so on.\n\nThe combined volume of the first $100$ cuboids, $C_1, \\dots, C_{100}$, is $723581599$.\n\nWhat is the combined volume of all $50000$ cuboids, $C_1, \\dots, C_{50000}$?", "raw_html": "

An axis-aligned cuboid, specified by parameters $\\{(x_0, y_0, z_0), (dx, dy, dz)\\}$, consists of all points $(X,Y,Z)$ such that $x_0 \\le X \\le x_0 + dx$, $y_0 \\le Y \\le y_0 + dy$ and $z_0 \\le Z \\le z_0 + dz$. The volume of the cuboid is the product, $dx \\times dy \\times dz$. The combined volume of a collection of cuboids is the volume of their union and will be less than the sum of the individual volumes if any cuboids overlap.

\n\n

Let $C_1, \\dots, C_{50000}$ be a collection of $50000$ axis-aligned cuboids such that $C_n$ has parameters

\n\n$$\\begin{align}\nx_0 &= S_{6n - 5} \\bmod 10000\\\\\ny_0 &= S_{6n - 4} \\bmod 10000\\\\\nz_0 &= S_{6n - 3} \\bmod 10000\\\\\ndx &= 1 + (S_{6n - 2} \\bmod 399)\\\\\ndy &= 1 + (S_{6n - 1} \\bmod 399)\\\\\ndz &= 1 + (S_{6n} \\bmod 399)\n\\end{align}$$\n\n

where $S_1,\\dots,S_{300000}$ come from the \"Lagged Fibonacci Generator\":

\n\n\n\n

Thus, $C_1$ has parameters $\\{(7,53,183),(94,369,56)\\}$, $C_2$ has parameters $\\{(2383,3563,5079),(42,212,344)\\}$, and so on.

\n\n

The combined volume of the first $100$ cuboids, $C_1, \\dots, C_{100}$, is $723581599$.

\n\n

What is the combined volume of all $50000$ cuboids, $C_1, \\dots, C_{50000}$?

", "url": "https://projecteuler.net/problem=212", "answer": "328968937309"} {"id": 213, "problem": "A $30 \\times 30$ grid of squares contains $900$ fleas, initially one flea per square.\n\nWhen a bell is rung, each flea jumps to an adjacent square at random (usually $4$ possibilities, except for fleas on the edge of the grid or at the corners).\n\nWhat is the expected number of unoccupied squares after $50$ rings of the bell? Give your answer rounded to six decimal places.", "raw_html": "

A $30 \\times 30$ grid of squares contains $900$ fleas, initially one flea per square.
\nWhen a bell is rung, each flea jumps to an adjacent square at random (usually $4$ possibilities, except for fleas on the edge of the grid or at the corners).

\n\n

What is the expected number of unoccupied squares after $50$ rings of the bell? Give your answer rounded to six decimal places.

", "url": "https://projecteuler.net/problem=213", "answer": "330.721154"} {"id": 214, "problem": "Let $\\phi$ be Euler's totient function, i.e. for a natural number $n$,\n$\\phi(n)$ is the number of $k$, $1 \\le k \\le n$, for which $\\gcd(k, n) = 1$.\n\nBy iterating $\\phi$, each positive integer generates a decreasing chain of numbers ending in $1$.\n\nE.g. if we start with $5$ the sequence $5,4,2,1$ is generated.\n\nHere is a listing of all chains with length $4$:\n\n$$\\begin{align}\n5,4,2,1&\\\\\n7,6,2,1&\\\\\n8,4,2,1&\\\\\n9,6,2,1&\\\\\n10,4,2,1&\\\\\n12,4,2,1&\\\\\n14,6,2,1&\\\\\n18,6,2,1\n\\end{align}$$\n\nOnly two of these chains start with a prime, their sum is $12$.\n\nWhat is the sum of all primes less than $40000000$ which generate a chain of length $25$?", "raw_html": "

Let $\\phi$ be Euler's totient function, i.e. for a natural number $n$,\n$\\phi(n)$ is the number of $k$, $1 \\le k \\le n$, for which $\\gcd(k, n) = 1$.

\n\n

By iterating $\\phi$, each positive integer generates a decreasing chain of numbers ending in $1$.
\nE.g. if we start with $5$ the sequence $5,4,2,1$ is generated.
\nHere is a listing of all chains with length $4$:

\n\n$$\\begin{align}\n5,4,2,1&\\\\\n7,6,2,1&\\\\\n8,4,2,1&\\\\\n9,6,2,1&\\\\\n10,4,2,1&\\\\\n12,4,2,1&\\\\\n14,6,2,1&\\\\\n18,6,2,1\n\\end{align}$$\n\n

Only two of these chains start with a prime, their sum is $12$.

\n\n

What is the sum of all primes less than $40000000$ which generate a chain of length $25$?

", "url": "https://projecteuler.net/problem=214", "answer": "1677366278943"} {"id": 215, "problem": "Consider the problem of building a wall out of $2 \\times 1$ and $3 \\times 1$ bricks ($\\text{horizontal} \\times \\text{vertical}$ dimensions) such that, for extra strength, the gaps between horizontally-adjacent bricks never line up in consecutive layers, i.e. never form a \"running crack\".\n\nFor example, the following $9 \\times 3$ wall is not acceptable due to the running crack shown in red:\n\nThere are eight ways of forming a crack-free $9 \\times 3$ wall, written $W(9,3) = 8$.\n\nCalculate $W(32,10)$.", "raw_html": "

Consider the problem of building a wall out of $2 \\times 1$ and $3 \\times 1$ bricks ($\\text{horizontal} \\times \\text{vertical}$ dimensions) such that, for extra strength, the gaps between horizontally-adjacent bricks never line up in consecutive layers, i.e. never form a \"running crack\".

\n\n

For example, the following $9 \\times 3$ wall is not acceptable due to the running crack shown in red:

\n\n
\n\"\"
\n\n

There are eight ways of forming a crack-free $9 \\times 3$ wall, written $W(9,3) = 8$.

\n\n

Calculate $W(32,10)$.

", "url": "https://projecteuler.net/problem=215", "answer": "806844323190414"} {"id": 216, "problem": "Consider numbers $t(n)$ of the form $t(n) = 2n^2 - 1$ with $n \\gt 1$.\n\nThe first such numbers are $7, 17, 31, 49, 71, 97, 127$ and $161$.\n\nIt turns out that only $49 = 7 \\cdot 7$ and $161 = 7 \\cdot 23$ are not prime.\n\nFor $n \\le 10000$ there are $2202$ numbers $t(n)$ that are prime.\n\nHow many numbers $t(n)$ are prime for $n \\le 50\\,000\\,000$?", "raw_html": "

Consider numbers $t(n)$ of the form $t(n) = 2n^2 - 1$ with $n \\gt 1$.
\nThe first such numbers are $7, 17, 31, 49, 71, 97, 127$ and $161$.
\nIt turns out that only $49 = 7 \\cdot 7$ and $161 = 7 \\cdot 23$ are not prime.
\nFor $n \\le 10000$ there are $2202$ numbers $t(n)$ that are prime.

\n\n

How many numbers $t(n)$ are prime for $n \\le 50\\,000\\,000$?

", "url": "https://projecteuler.net/problem=216", "answer": "5437849"} {"id": 217, "problem": "A positive integer with $k$ (decimal) digits is called balanced if its first $\\lceil k/2 \\rceil$ digits sum to the same value as its last $\\lceil k/2 \\rceil$ digits, where $\\lceil x \\rceil$, pronounced ceiling of $x$, is the smallest integer $\\ge x$, thus $\\lceil \\pi \\rceil = 4$ and $\\lceil 5 \\rceil = 5$.\n\nSo, for example, all palindromes are balanced, as is $13722$.\n\nLet $T(n)$ be the sum of all balanced numbers less than $10^n$.\n\nThus: $T(1) = 45$, $T(2) = 540$ and $T(5) = 334795890$.\n\nFind $T(47) \\bmod 3^{15}$.", "raw_html": "

\nA positive integer with $k$ (decimal) digits is called balanced if its first $\\lceil k/2 \\rceil$ digits sum to the same value as its last $\\lceil k/2 \\rceil$ digits, where $\\lceil x \\rceil$, pronounced ceiling of $x$, is the smallest integer $\\ge x$, thus $\\lceil \\pi \\rceil = 4$ and $\\lceil 5 \\rceil = 5$.

\n

So, for example, all palindromes are balanced, as is $13722$.

\n

Let $T(n)$ be the sum of all balanced numbers less than $10^n$.
\nThus: $T(1) = 45$, $T(2) = 540$ and $T(5) = 334795890$.

\n

Find $T(47) \\bmod 3^{15}$.

", "url": "https://projecteuler.net/problem=217", "answer": "6273134"} {"id": 218, "problem": "Consider the right angled triangle with sides $a=7$, $b=24$ and $c=25$.\nThe area of this triangle is $84$, which is divisible by the perfect numbers $6$ and $28$.\n\nMoreover it is a primitive right angled triangle as $\\gcd(a,b)=1$ and $\\gcd(b,c)=1$.\n\nAlso $c$ is a perfect square.\n\nWe will call a right angled triangle perfect if\n\n-it is a primitive right angled triangle\n\n-its hypotenuse is a perfect square.\n\nWe will call a right angled triangle super-perfect if\n\n-it is a perfect right angled triangle and\n\n-its area is a multiple of the perfect numbers $6$ and $28$.\n\nHow many perfect right-angled triangles with $c \\le 10^{16}$ exist that are not super-perfect?", "raw_html": "

Consider the right angled triangle with sides $a=7$, $b=24$ and $c=25$.\nThe area of this triangle is $84$, which is divisible by the perfect numbers $6$ and $28$.
\nMoreover it is a primitive right angled triangle as $\\gcd(a,b)=1$ and $\\gcd(b,c)=1$.
\nAlso $c$ is a perfect square.

\n\n

We will call a right angled triangle perfect if
\n-it is a primitive right angled triangle
\n-its hypotenuse is a perfect square.

\n\n

We will call a right angled triangle super-perfect if
\n-it is a perfect right angled triangle and
\n-its area is a multiple of the perfect numbers $6$ and $28$.\n

\n\n

How many perfect right-angled triangles with $c \\le 10^{16}$ exist that are not super-perfect?

", "url": "https://projecteuler.net/problem=218", "answer": "0"} {"id": 219, "problem": "Let A and B be bit strings (sequences of 0's and 1's).\n\nIf A is equal to the leftmost length(A) bits of B, then A is said to be a prefix of B.\n\nFor example, 00110 is a prefix of 001101001, but not of 00111 or 100110.\n\nA prefix-free code of size n is a collection of n distinct bit strings such that no string is a prefix of any other. For example, this is a prefix-free code of size 6:\n\n0000, 0001, 001, 01, 10, 11\n\nNow suppose that it costs one penny to transmit a '0' bit, but four pence to transmit a '1'.\n\nThen the total cost of the prefix-free code shown above is 35 pence, which happens to be the cheapest possible for the skewed pricing scheme in question.\n\nIn short, we write Cost(6) = 35.\n\nWhat is Cost(109) ?", "raw_html": "

Let A and B be bit strings (sequences of 0's and 1's).
\nIf A is equal to the leftmost length(A) bits of B, then A is said to be a prefix of B.
\nFor example, 00110 is a prefix of 001101001, but not of 00111 or 100110.

\n\n

A prefix-free code of size n is a collection of n distinct bit strings such that no string is a prefix of any other. For example, this is a prefix-free code of size 6:

\n\n

0000, 0001, 001, 01, 10, 11

\n\n

Now suppose that it costs one penny to transmit a '0' bit, but four pence to transmit a '1'.
\nThen the total cost of the prefix-free code shown above is 35 pence, which happens to be the cheapest possible for the skewed pricing scheme in question.
\nIn short, we write Cost(6) = 35.

\n\n

What is Cost(109) ?

", "url": "https://projecteuler.net/problem=219", "answer": "64564225042"} {"id": 220, "problem": "Let $D_0$ be the two-letter string \"Fa\". For $n\\ge 1$, derive $D_n$ from $D_{n-1}$ by the string-rewriting rules:\n\n\"a\" → \"aRbFR\"\n\n\"b\" → \"LFaLb\"\n\nThus, $D_0 = $ \"Fa\", $D_1 = $ \"FaRbFR\", $D_2 = $ \"FaRbFRRLFaLbFR\", and so on.\n\nThese strings can be interpreted as instructions to a computer graphics program, with \"F\" meaning \"draw forward one unit\", \"L\" meaning \"turn left $90$ degrees\", \"R\" meaning \"turn right $90$ degrees\", and \"a\" and \"b\" being ignored. The initial position of the computer cursor is $(0,0)$, pointing up towards $(0,1)$.\n\nThen $D_n$ is an exotic drawing known as the Heighway Dragon of order $n$. For example, $D_{10}$ is shown below; counting each \"F\" as one step, the highlighted spot at $(18,16)$ is the position reached after $500$ steps.\n\nWhat is the position of the cursor after $10^{12}$ steps in $D_{50}$?\n\nGive your answer in the form x,y with no spaces.", "raw_html": "

Let $D_0$ be the two-letter string \"Fa\". For $n\\ge 1$, derive $D_n$ from $D_{n-1}$ by the string-rewriting rules:

\n\n

\"a\" → \"aRbFR\"
\n\"b\" → \"LFaLb\"

\n\n

Thus, $D_0 = $ \"Fa\", $D_1 = $ \"FaRbFR\", $D_2 = $ \"FaRbFRRLFaLbFR\", and so on.

\n\n

These strings can be interpreted as instructions to a computer graphics program, with \"F\" meaning \"draw forward one unit\", \"L\" meaning \"turn left $90$ degrees\", \"R\" meaning \"turn right $90$ degrees\", and \"a\" and \"b\" being ignored. The initial position of the computer cursor is $(0,0)$, pointing up towards $(0,1)$.

\n\n

Then $D_n$ is an exotic drawing known as the Heighway Dragon of order $n$. For example, $D_{10}$ is shown below; counting each \"F\" as one step, the highlighted spot at $(18,16)$ is the position reached after $500$ steps.

\n\n
\n\"\"
\n\n

What is the position of the cursor after $10^{12}$ steps in $D_{50}$?
\nGive your answer in the form x,y with no spaces.

", "url": "https://projecteuler.net/problem=220", "answer": "139776,963904"} {"id": 221, "problem": "We shall call a positive integer $A$ an \"Alexandrian integer\", if there exist integers $p, q, r$ such that:\n\n$$A = p \\cdot q \\cdot r$$\nand\n$$\\dfrac{1}{A} = \\dfrac{1}{p} + \\dfrac{1}{q} + \\dfrac{1}{r}.$$\n\nFor example, $630$ is an Alexandrian integer ($p = 5, q = -7, r = -18$).\nIn fact, $630$ is the $6$th Alexandrian integer, the first $6$ Alexandrian integers being: $6, 42, 120, 156, 420$, and $630$.\n\nFind the $150000$th Alexandrian integer.", "raw_html": "

We shall call a positive integer $A$ an \"Alexandrian integer\", if there exist integers $p, q, r$ such that:

\n\n

$$A = p \\cdot q \\cdot r$$\nand\n$$\\dfrac{1}{A} = \\dfrac{1}{p} + \\dfrac{1}{q} + \\dfrac{1}{r}.$$

\n\n

For example, $630$ is an Alexandrian integer ($p = 5, q = -7, r = -18$).\nIn fact, $630$ is the $6$th Alexandrian integer, the first $6$ Alexandrian integers being: $6, 42, 120, 156, 420$, and $630$.

\n\n

Find the $150000$th Alexandrian integer.

", "url": "https://projecteuler.net/problem=221", "answer": "1884161251122450"} {"id": 222, "problem": "What is the length of the shortest pipe, of internal radius $\\pu{50 mm}$, that can fully contain $21$ balls of radii $\\pu{30 mm}, \\pu{31 mm}, \\dots, \\pu{50 mm}$?\n\nGive your answer in micrometres ($\\pu{10^{-6} m}$) rounded to the nearest integer.", "raw_html": "

What is the length of the shortest pipe, of internal radius $\\pu{50 mm}$, that can fully contain $21$ balls of radii $\\pu{30 mm}, \\pu{31 mm}, \\dots, \\pu{50 mm}$?

\n\n

Give your answer in micrometres ($\\pu{10^{-6} m}$) rounded to the nearest integer.

", "url": "https://projecteuler.net/problem=222", "answer": "1590933"} {"id": 223, "problem": "Let us call an integer sided triangle with sides $a \\le b \\le c$ barely acute if the sides satisfy $a^2 + b^2 = c^2 + 1$.\n\nHow many barely acute triangles are there with perimeter $\\le 25\\,000\\,000$?", "raw_html": "

Let us call an integer sided triangle with sides $a \\le b \\le c$ barely acute if the sides satisfy $a^2 + b^2 = c^2 + 1$.

\n\n

How many barely acute triangles are there with perimeter $\\le 25\\,000\\,000$?

", "url": "https://projecteuler.net/problem=223", "answer": "61614848"} {"id": 224, "problem": "Let us call an integer sided triangle with sides $a \\le b \\le c$ barely obtuse if the sides satisfy\n$a^2 + b^2 = c^2 - 1$.\n\nHow many barely obtuse triangles are there with perimeter $\\le 75\\,000\\,000$?", "raw_html": "

Let us call an integer sided triangle with sides $a \\le b \\le c$ barely obtuse if the sides satisfy
$a^2 + b^2 = c^2 - 1$.

\n\n

How many barely obtuse triangles are there with perimeter $\\le 75\\,000\\,000$?

", "url": "https://projecteuler.net/problem=224", "answer": "4137330"} {"id": 225, "problem": "The sequence $1, 1, 1, 3, 5, 9, 17, 31, 57, 105, 193, 355, 653, 1201, \\dots$\n\nis defined by $T_1 = T_2 = T_3 = 1$ and $T_n = T_{n - 1} + T_{n - 2} + T_{n - 3}$.\n\nIt can be shown that $27$ does not divide any terms of this sequence.\nIn fact, $27$ is the first odd number with this property.\n\nFind the $124$th odd number that does not divide any terms of the above sequence.", "raw_html": "

\nThe sequence $1, 1, 1, 3, 5, 9, 17, 31, 57, 105, 193, 355, 653, 1201, \\dots$
\nis defined by $T_1 = T_2 = T_3 = 1$ and $T_n = T_{n - 1} + T_{n - 2} + T_{n - 3}$.\n

\n

\nIt can be shown that $27$ does not divide any terms of this sequence.
In fact, $27$ is the first odd number with this property.

\n

\nFind the $124$th odd number that does not divide any terms of the above sequence.

", "url": "https://projecteuler.net/problem=225", "answer": "2009"} {"id": 226, "problem": "The blancmange curve is the set of points $(x, y)$ such that $0 \\le x \\le 1$ and $y = \\sum \\limits_{n = 0}^{\\infty} {\\dfrac{s(2^n x)}{2^n}}$, where $s(x)$ is the distance from $x$ to the nearest integer.\n\nThe area under the blancmange curve is equal to ½, shown in pink in the diagram below.\n\nLet $C$ be the circle with centre $\\left ( \\frac{1}{4}, \\frac{1}{2} \\right )$ and radius $\\frac{1}{4}$, shown in black in the diagram.\n\nWhat area under the blancmange curve is enclosed by $C$?\nGive your answer rounded to eight decimal places in the form 0.abcdefgh.", "raw_html": "

The blancmange curve is the set of points $(x, y)$ such that $0 \\le x \\le 1$ and $y = \\sum \\limits_{n = 0}^{\\infty} {\\dfrac{s(2^n x)}{2^n}}$, where $s(x)$ is the distance from $x$ to the nearest integer.

\n\n

The area under the blancmange curve is equal to ½, shown in pink in the diagram below.

\n\n
\n\"blancmange
\n\n

Let $C$ be the circle with centre $\\left ( \\frac{1}{4}, \\frac{1}{2} \\right )$ and radius $\\frac{1}{4}$, shown in black in the diagram.

\n\n

What area under the blancmange curve is enclosed by $C$?
Give your answer rounded to eight decimal places in the form 0.abcdefgh.

", "url": "https://projecteuler.net/problem=226", "answer": "0.11316017"} {"id": 227, "problem": "The Chase is a game played with two dice and an even number of players.\n\nThe players sit around a table and the game begins with two opposite players having one die each. On each turn, the two players with a die roll it.\n\nIf the player rolls 1, then the die passes to the neighbour on the left.\n\nIf the player rolls 6, then the die passes to the neighbour on the right.\n\nOtherwise, the player keeps the die for the next turn.\n\nThe game ends when one player has both dice after they have been rolled and passed; that player has then lost.\n\nIn a game with 100 players, what is the expected number of turns the game lasts?\n\nGive your answer rounded to ten significant digits.", "raw_html": "

The Chase is a game played with two dice and an even number of players.

\n\n

The players sit around a table and the game begins with two opposite players having one die each. On each turn, the two players with a die roll it.

\n\n

If the player rolls 1, then the die passes to the neighbour on the left.
\nIf the player rolls 6, then the die passes to the neighbour on the right.
\nOtherwise, the player keeps the die for the next turn.

\n\n

The game ends when one player has both dice after they have been rolled and passed; that player has then lost.

\n\n

In a game with 100 players, what is the expected number of turns the game lasts?

\n

Give your answer rounded to ten significant digits.

", "url": "https://projecteuler.net/problem=227", "answer": "3780.618622"} {"id": 228, "problem": "Let $S_n$ be the regular $n$-sided polygon – or shape – whose vertices\n\n$v_k$ ($k = 1, 2, \\dots, n$) have coordinates:\n\n$$\\begin{align}\nx_k &= \\cos((2k - 1)/n \\times 180^\\circ)\\\\\ny_k &= \\sin((2k - 1)/n \\times 180^\\circ)\n\\end{align}$$\n\nEach $S_n$ is to be interpreted as a filled shape consisting of all points on the perimeter and in the interior.\n\nThe Minkowski sum, $S + T$, of two shapes $S$ and $T$ is the result of adding every point in $S$ to every point in $T$, where point addition is performed coordinate-wise: $(u, v) + (x, y) = (u + x, v + y)$.\n\nFor example, the sum of $S_3$ and $S_4$ is the six-sided shape shown in pink below:\n\nHow many sides does $S_{1864} + S_{1865} + \\cdots + S_{1909}$ have?", "raw_html": "

Let $S_n$ be the regular $n$-sided polygon – or shape – whose vertices \n\n$v_k$ ($k = 1, 2, \\dots, n$) have coordinates:

\n$$\\begin{align}\nx_k &= \\cos((2k - 1)/n \\times 180^\\circ)\\\\\ny_k &= \\sin((2k - 1)/n \\times 180^\\circ)\n\\end{align}$$\n\n

Each $S_n$ is to be interpreted as a filled shape consisting of all points on the perimeter and in the interior.

\n\n

The Minkowski sum, $S + T$, of two shapes $S$ and $T$ is the result of adding every point in $S$ to every point in $T$, where point addition is performed coordinate-wise: $(u, v) + (x, y) = (u + x, v + y)$.

\n\n

For example, the sum of $S_3$ and $S_4$ is the six-sided shape shown in pink below:

\n\n
\n\"picture
\n\n

How many sides does $S_{1864} + S_{1865} + \\cdots + S_{1909}$ have?

", "url": "https://projecteuler.net/problem=228", "answer": "86226"} {"id": 229, "problem": "Consider the number $3600$. It is very special, because\n\n$$\\begin{alignat}{2}\n3600 &= 48^2 + &&36^2\\\\\n3600 &= 20^2 + 2 \\times &&40^2\\\\\n3600 &= 30^2 + 3 \\times &&30^2\\\\\n3600 &= 45^2 + 7 \\times &&15^2\n\\end{alignat}$$\n\nSimilarly, we find that $88201 = 99^2 + 280^2 = 287^2 + 2 \\times 54^2 = 283^2 + 3 \\times 52^2 = 197^2 + 7 \\times 84^2$.\n\nIn 1747, Euler proved which numbers are representable as a sum of two squares.\nWe are interested in the numbers $n$ which admit representations of all of the following four types:\n\n$$\\begin{alignat}{2}\nn &= a_1^2 + && b_1^2\\\\\nn &= a_2^2 + 2 && b_2^2\\\\\nn &= a_3^2 + 3 && b_3^2\\\\\nn &= a_7^2 + 7 && b_7^2,\n\\end{alignat}$$\nwhere the $a_k$ and $b_k$ are positive integers.\n\nThere are $75373$ such numbers that do not exceed $10^7$.\n\nHow many such numbers are there that do not exceed $2 \\times 10^9$?", "raw_html": "

Consider the number $3600$. It is very special, because

\n$$\\begin{alignat}{2}\n3600 &= 48^2 + &&36^2\\\\\n3600 &= 20^2 + 2 \\times &&40^2\\\\\n3600 &= 30^2 + 3 \\times &&30^2\\\\\n3600 &= 45^2 + 7 \\times &&15^2\n\\end{alignat}$$\n\n

Similarly, we find that $88201 = 99^2 + 280^2 = 287^2 + 2 \\times 54^2 = 283^2 + 3 \\times 52^2 = 197^2 + 7 \\times 84^2$.

\n\n

In 1747, Euler proved which numbers are representable as a sum of two squares.\nWe are interested in the numbers $n$ which admit representations of all of the following four types:

\n$$\\begin{alignat}{2}\nn &= a_1^2 + && b_1^2\\\\\nn &= a_2^2 + 2 && b_2^2\\\\\nn &= a_3^2 + 3 && b_3^2\\\\\nn &= a_7^2 + 7 && b_7^2,\n\\end{alignat}$$\n

where the $a_k$ and $b_k$ are positive integers.

\n\n

There are $75373$ such numbers that do not exceed $10^7$.
\n\nHow many such numbers are there that do not exceed $2 \\times 10^9$?

", "url": "https://projecteuler.net/problem=229", "answer": "11325263"} {"id": 230, "problem": "For any two strings of digits, $A$ and $B$, we define $F_{A, B}$ to be the sequence $(A,B,AB,BAB,ABBAB,\\dots)$ in which each term is the concatenation of the previous two.\n\nFurther, we define $D_{A, B}(n)$ to be the $n$th digit in the first term of $F_{A, B}$ that contains at least $n$ digits.\n\nExample:\n\nLet $A=1415926535$, $B=8979323846$. We wish to find $D_{A, B}(35)$, say.\n\nThe first few terms of $F_{A, B}$ are:\n\n$1415926535$\n\n$8979323846$\n\n$14159265358979323846$\n\n$897932384614159265358979323846$\n\n$1415926535897932384689793238461415{\\color{red}\\mathbf 9}265358979323846$\n\nThen $D_{A, B}(35)$ is the $35$th digit in the fifth term, which is $9$.\n\nNow we use for $A$ the first $100$ digits of $\\pi$ behind the decimal point:\n\n$14159265358979323846264338327950288419716939937510$\n\n$58209749445923078164062862089986280348253421170679$\n\nand for $B$ the next hundred digits:\n\n$82148086513282306647093844609550582231725359408128$\n\n$48111745028410270193852110555964462294895493038196$.\n\nFind $\\sum_{n = 0}^{17} 10^n \\times D_{A,B}((127+19n) \\times 7^n)$.", "raw_html": "

For any two strings of digits, $A$ and $B$, we define $F_{A, B}$ to be the sequence $(A,B,AB,BAB,ABBAB,\\dots)$ in which each term is the concatenation of the previous two.

\n\n

Further, we define $D_{A, B}(n)$ to be the $n$th digit in the first term of $F_{A, B}$ that contains at least $n$ digits.

\n\n

Example:

\n\n

Let $A=1415926535$, $B=8979323846$. We wish to find $D_{A, B}(35)$, say.

\n\n

The first few terms of $F_{A, B}$ are:
\n$1415926535$
\n$8979323846$
\n$14159265358979323846$
\n$897932384614159265358979323846$
\n$1415926535897932384689793238461415{\\color{red}\\mathbf 9}265358979323846$

\n\n

Then $D_{A, B}(35)$ is the $35$th digit in the fifth term, which is $9$.

\n\n

Now we use for $A$ the first $100$ digits of $\\pi$ behind the decimal point:

\n

$14159265358979323846264338327950288419716939937510$
\n$58209749445923078164062862089986280348253421170679$

\n\n

and for $B$ the next hundred digits:

\n\n

$82148086513282306647093844609550582231725359408128$
\n$48111745028410270193852110555964462294895493038196$.

\n\n

Find $\\sum_{n = 0}^{17} 10^n \\times D_{A,B}((127+19n) \\times 7^n)$.

", "url": "https://projecteuler.net/problem=230", "answer": "850481152593119296"} {"id": 231, "problem": "The binomial coefficient $\\displaystyle \\binom {10} 3 = 120$.\n\n$120 = 2^3 \\times 3 \\times 5 = 2 \\times 2 \\times 2 \\times 3 \\times 5$, and $2 + 2 + 2 + 3 + 5 = 14$.\n\nSo the sum of the terms in the prime factorisation of $\\displaystyle \\binom {10} 3$ is $14$.\n\nFind the sum of the terms in the prime factorisation of $\\displaystyle \\binom {20\\,000\\,000} {15\\,000\\,000}$.", "raw_html": "

The binomial coefficient $\\displaystyle \\binom {10} 3 = 120$.
\n$120 = 2^3 \\times 3 \\times 5 = 2 \\times 2 \\times 2 \\times 3 \\times 5$, and $2 + 2 + 2 + 3 + 5 = 14$.
\nSo the sum of the terms in the prime factorisation of $\\displaystyle \\binom {10} 3$ is $14$.\n

\nFind the sum of the terms in the prime factorisation of $\\displaystyle \\binom {20\\,000\\,000} {15\\,000\\,000}$.\n

", "url": "https://projecteuler.net/problem=231", "answer": "7526965179680"} {"id": 232, "problem": "Two players share an unbiased coin and take it in turns to play The Race.\n\nOn Player 1's turn, the coin is tossed once. If it comes up Heads, then Player 1 scores one point; if it comes up Tails, then no points are scored.\n\nOn Player 2's turn, a positive integer, $T$, is chosen by Player 2 and the coin is tossed $T$ times. If it comes up all Heads, then Player 2 scores $2^{T-1}$ points; otherwise, no points are scored.\n\nPlayer 1 goes first and the winner is the first to 100 or more points.\n\nPlayer 2 will always select the number, $T$, of coin tosses that maximises the probability of winning.\n\nWhat is the probability that Player 2 wins?\n\nGive your answer rounded to eight decimal places in the form 0.abcdefgh.", "raw_html": "

Two players share an unbiased coin and take it in turns to play The Race.

\n\n

On Player 1's turn, the coin is tossed once. If it comes up Heads, then Player 1 scores one point; if it comes up Tails, then no points are scored.

\n\n

On Player 2's turn, a positive integer, $T$, is chosen by Player 2 and the coin is tossed $T$ times. If it comes up all Heads, then Player 2 scores $2^{T-1}$ points; otherwise, no points are scored.

\n\n

Player 1 goes first and the winner is the first to 100 or more points.

\n\n

Player 2 will always select the number, $T$, of coin tosses that maximises the probability of winning.

\n\n

What is the probability that Player 2 wins?

\n\n

Give your answer rounded to eight decimal places in the form 0.abcdefgh.

", "url": "https://projecteuler.net/problem=232", "answer": "0.83648556"} {"id": 233, "problem": "Let $f(N)$ be the number of points with integer coordinates that are on a circle passing through $(0,0)$, $(N,0)$,$(0,N)$, and $(N,N)$.\n\nIt can be shown that $f(10000) = 36$.\n\nWhat is the sum of all positive integers $N \\le 10^{11}$ such that $f(N) = 420$?", "raw_html": "

Let $f(N)$ be the number of points with integer coordinates that are on a circle passing through $(0,0)$, $(N,0)$,$(0,N)$, and $(N,N)$.

\n

It can be shown that $f(10000) = 36$.

\n\n

What is the sum of all positive integers $N \\le 10^{11}$ such that $f(N) = 420$?

", "url": "https://projecteuler.net/problem=233", "answer": "271204031455541309"} {"id": 234, "problem": "For an integer $n \\ge 4$, we define the lower prime square root of $n$, denoted by $\\operatorname{lps}(n)$, as the largest prime $\\le \\sqrt n$ and the upper prime square root of $n$, $\\operatorname{ups}(n)$, as the smallest prime $\\ge \\sqrt n$.\n\nSo, for example, $\\operatorname{lps}(4) = 2 = \\operatorname{ups}(4)$, $\\operatorname{lps}(1000) = 31$, $\\operatorname{ups}(1000) = 37$.\n\nLet us call an integer $n \\ge 4$ semidivisible, if one of $\\operatorname{lps}(n)$ and $\\operatorname{ups}(n)$ divides $n$, but not both.\n\nThe sum of the semidivisible numbers not exceeding $15$ is $30$, the numbers are $8$, $10$ and $12$.\n$15$ is not semidivisible because it is a multiple of both $\\operatorname{lps}(15) = 3$ and $\\operatorname{ups}(15) = 5$.\n\nAs a further example, the sum of the $92$ semidivisible numbers up to $1000$ is $34825$.\n\nWhat is the sum of all semidivisible numbers not exceeding $999966663333$?", "raw_html": "

For an integer $n \\ge 4$, we define the lower prime square root of $n$, denoted by $\\operatorname{lps}(n)$, as the largest prime $\\le \\sqrt n$ and the upper prime square root of $n$, $\\operatorname{ups}(n)$, as the smallest prime $\\ge \\sqrt n$.

\n

So, for example, $\\operatorname{lps}(4) = 2 = \\operatorname{ups}(4)$, $\\operatorname{lps}(1000) = 31$, $\\operatorname{ups}(1000) = 37$.
\nLet us call an integer $n \\ge 4$ semidivisible, if one of $\\operatorname{lps}(n)$ and $\\operatorname{ups}(n)$ divides $n$, but not both.

\n\n

The sum of the semidivisible numbers not exceeding $15$ is $30$, the numbers are $8$, $10$ and $12$.
$15$ is not semidivisible because it is a multiple of both $\\operatorname{lps}(15) = 3$ and $\\operatorname{ups}(15) = 5$.
\nAs a further example, the sum of the $92$ semidivisible numbers up to $1000$ is $34825$.

\n\n

What is the sum of all semidivisible numbers not exceeding $999966663333$?

", "url": "https://projecteuler.net/problem=234", "answer": "1259187438574927161"} {"id": 235, "problem": "Given is the arithmetic-geometric sequence $u(k) = (900-3k)r^{k - 1}$.\n\nLet $s(n) = \\sum_{k = 1}^n u(k)$.\n\nFind the value of $r$ for which $s(5000) = -600\\,000\\,000\\,000$.\n\nGive your answer rounded to $12$ places behind the decimal point.", "raw_html": "

\nGiven is the arithmetic-geometric sequence $u(k) = (900-3k)r^{k - 1}$.
\nLet $s(n) = \\sum_{k = 1}^n u(k)$.\n

\n

\nFind the value of $r$ for which $s(5000) = -600\\,000\\,000\\,000$.\n

\n

\nGive your answer rounded to $12$ places behind the decimal point.\n

", "url": "https://projecteuler.net/problem=235", "answer": "1.002322108633"} {"id": 236, "problem": "Suppliers 'A' and 'B' provided the following numbers of products for the luxury hamper market:\n\n| Product | 'A' | 'B' |\n| --- | --- | --- |\n| Beluga Caviar | 5248 | 640 |\n| Christmas Cake | 1312 | 1888 |\n| Gammon Joint | 2624 | 3776 |\n| Vintage Port | 5760 | 3776 |\n| Champagne Truffles | 3936 | 5664 |\n\nAlthough the suppliers try very hard to ship their goods in perfect condition, there is inevitably some spoilage - i.e. products gone bad.\n\nThe suppliers compare their performance using two types of statistic:\n\n- The five per-product spoilage rates for each supplier are equal to the number of products gone bad divided by the number of products supplied, for each of the five products in turn.\n\n- The overall spoilage rate for each supplier is equal to the total number of products gone bad divided by the total number of products provided by that supplier.\n\nTo their surprise, the suppliers found that each of the five per-product spoilage rates was worse (higher) for 'B' than for 'A' by the same factor (ratio of spoilage rates), m>1; and yet, paradoxically, the overall spoilage rate was worse for 'A' than for 'B', also by a factor of m.\n\nThere are thirty-five m>1 for which this surprising result could have occurred, the smallest of which is 1476/1475.\n\nWhat's the largest possible value of m?\n\nGive your answer as a fraction reduced to its lowest terms, in the form u/v.", "raw_html": "

Suppliers 'A' and 'B' provided the following numbers of products for the luxury hamper market:

\n\n

Product'A''B'
Beluga Caviar5248640
Christmas Cake13121888
Gammon Joint26243776
Vintage Port57603776
Champagne Truffles39365664
\n\n

Although the suppliers try very hard to ship their goods in perfect condition, there is inevitably some spoilage - i.e. products gone bad.

\n\n

The suppliers compare their performance using two types of statistic:

To their surprise, the suppliers found that each of the five per-product spoilage rates was worse (higher) for 'B' than for 'A' by the same factor (ratio of spoilage rates), m>1; and yet, paradoxically, the overall spoilage rate was worse for 'A' than for 'B', also by a factor of m.

\n\n

There are thirty-five m>1 for which this surprising result could have occurred, the smallest of which is 1476/1475.

\n\n

What's the largest possible value of m?
\nGive your answer as a fraction reduced to its lowest terms, in the form u/v.

", "url": "https://projecteuler.net/problem=236", "answer": "123/59"} {"id": 237, "problem": "Let $T(n)$ be the number of tours over a $4 \\times n$ playing board such that:\n\n- The tour starts in the top left corner.\n\n- The tour consists of moves that are up, down, left, or right one square.\n\n- The tour visits each square exactly once.\n\n- The tour ends in the bottom left corner.\n\nThe diagram shows one tour over a $4 \\times 10$ board:\n\n$T(10)$ is $2329$. What is $T(10^{12})$ modulo $10^8$?", "raw_html": "

Let $T(n)$ be the number of tours over a $4 \\times n$ playing board such that:

\n

The diagram shows one tour over a $4 \\times 10$ board:

\n\n
\n\"\"
\n\n

$T(10)$ is $2329$. What is $T(10^{12})$ modulo $10^8$?

", "url": "https://projecteuler.net/problem=237", "answer": "15836928"} {"id": 238, "problem": "Create a sequence of numbers using the \"Blum Blum Shub\" pseudo-random number generator:\n\n$$\\begin{align}\ns_0 &= 14025256\\\\\ns_{n + 1} &= s_n^2 \\bmod 20300713\n\\end{align}$$\n\nConcatenate these numbers $s_0s_1s_2\\cdots$ to create a string $w$ of infinite length.\n\nThen, $w = {\\color{blue}14025256741014958470038053646\\cdots}$\n\nFor a positive integer $k$, if no substring of $w$ exists with a sum of digits equal to $k$, $p(k)$ is defined to be zero. If at least one substring of $w$ exists with a sum of digits equal to $k$, we define $p(k) = z$, where $z$ is the starting position of the earliest such substring.\n\nFor instance:\n\nThe substrings $\\color{blue}1, 14, 1402, \\dots$\n\nwith respective sums of digits equal to $1, 5, 7, \\dots$\n\nstart at position $\\mathbf 1$, hence $p(1) = p(5) = p(7) = \\cdots = \\mathbf 1$.\n\nThe substrings $\\color{blue}4, 402, 4025, \\dots$\n\nwith respective sums of digits equal to $4, 6, 11, \\dots$\n\nstart at position $\\mathbf 2$, hence $p(4) = p(6) = p(11) = \\cdots = \\mathbf 2$.\n\nThe substrings $\\color{blue}02, 0252, \\dots$\n\nwith respective sums of digits equal to $2, 9, \\dots$\n\nstart at position $\\mathbf 3$, hence $p(2) = p(9) = \\cdots = \\mathbf 3$.\n\nNote that substring $\\color{blue}025$ starting at position $\\mathbf 3$, has a sum of digits equal to $7$, but there was an earlier substring (starting at position $\\mathbf 1$) with a sum of digits equal to $7$, so $p(7) = 1$, not $3$.\n\nWe can verify that, for $0 \\lt k \\le 10^3$, $\\sum p(k) = 4742$.\n\nFind $\\sum p(k)$, for $0 \\lt k \\le 2 \\times 10^{15}$.", "raw_html": "

Create a sequence of numbers using the \"Blum Blum Shub\" pseudo-random number generator:

\n\n$$\\begin{align}\ns_0 &= 14025256\\\\\ns_{n + 1} &= s_n^2 \\bmod 20300713\n\\end{align}$$\n\n

Concatenate these numbers $s_0s_1s_2\\cdots$ to create a string $w$ of infinite length.
\nThen, $w = {\\color{blue}14025256741014958470038053646\\cdots}$

\n\n

For a positive integer $k$, if no substring of $w$ exists with a sum of digits equal to $k$, $p(k)$ is defined to be zero. If at least one substring of $w$ exists with a sum of digits equal to $k$, we define $p(k) = z$, where $z$ is the starting position of the earliest such substring.

\n\n

For instance:

\n\n

The substrings $\\color{blue}1, 14, 1402, \\dots$
\nwith respective sums of digits equal to $1, 5, 7, \\dots$
\nstart at position $\\mathbf 1$, hence $p(1) = p(5) = p(7) = \\cdots = \\mathbf 1$.

\n\n

The substrings $\\color{blue}4, 402, 4025, \\dots$
\nwith respective sums of digits equal to $4, 6, 11, \\dots$
\nstart at position $\\mathbf 2$, hence $p(4) = p(6) = p(11) = \\cdots = \\mathbf 2$.

\n\n

The substrings $\\color{blue}02, 0252, \\dots$
\nwith respective sums of digits equal to $2, 9, \\dots$
\nstart at position $\\mathbf 3$, hence $p(2) = p(9) = \\cdots = \\mathbf 3$.

\n\n

Note that substring $\\color{blue}025$ starting at position $\\mathbf 3$, has a sum of digits equal to $7$, but there was an earlier substring (starting at position $\\mathbf 1$) with a sum of digits equal to $7$, so $p(7) = 1$, not $3$.

\n\n

We can verify that, for $0 \\lt k \\le 10^3$, $\\sum p(k) = 4742$.

\n\n

Find $\\sum p(k)$, for $0 \\lt k \\le 2 \\times 10^{15}$.

", "url": "https://projecteuler.net/problem=238", "answer": "9922545104535661"} {"id": 239, "problem": "A set of disks numbered $1$ through $100$ are placed in a line in random order.\n\nWhat is the probability that we have a partial derangement such that exactly $22$ prime number discs are found away from their natural positions?\n\n(Any number of non-prime disks may also be found in or out of their natural positions.)\n\nGive your answer rounded to $12$ places behind the decimal point in the form 0.abcdefghijkl.", "raw_html": "

A set of disks numbered $1$ through $100$ are placed in a line in random order.

\n\n

What is the probability that we have a partial derangement such that exactly $22$ prime number discs are found away from their natural positions?
\n(Any number of non-prime disks may also be found in or out of their natural positions.)

\n\n

Give your answer rounded to $12$ places behind the decimal point in the form 0.abcdefghijkl.

", "url": "https://projecteuler.net/problem=239", "answer": "0.001887854841"} {"id": 240, "problem": "There are $1111$ ways in which five $6$-sided dice (sides numbered $1$ to $6$) can be rolled so that the top three sum to $15$. Some examples are:\n\n$D_1,D_2,D_3,D_4,D_5 = 4,3,6,3,5$\n\n$D_1,D_2,D_3,D_4,D_5 = 4,3,3,5,6$\n\n$D_1,D_2,D_3,D_4,D_5 = 3,3,3,6,6$\n\n$D_1,D_2,D_3,D_4,D_5 = 6,6,3,3,3$\n\nIn how many ways can twenty $12$-sided dice (sides numbered $1$ to $12$) be rolled so that the top ten sum to $70$?", "raw_html": "

There are $1111$ ways in which five $6$-sided dice (sides numbered $1$ to $6$) can be rolled so that the top three sum to $15$. Some examples are:\n\n

\n$D_1,D_2,D_3,D_4,D_5 = 4,3,6,3,5$\n
\n$D_1,D_2,D_3,D_4,D_5 = 4,3,3,5,6$\n
\n$D_1,D_2,D_3,D_4,D_5 = 3,3,3,6,6$\n
\n$D_1,D_2,D_3,D_4,D_5 = 6,6,3,3,3$\n

\nIn how many ways can twenty $12$-sided dice (sides numbered $1$ to $12$) be rolled so that the top ten sum to $70$?

", "url": "https://projecteuler.net/problem=240", "answer": "7448717393364181966"} {"id": 241, "problem": "For a positive integer $n$, let $\\sigma(n)$ be the sum of all divisors of $n$. For example, $\\sigma(6) = 1 + 2 + 3 + 6 = 12$.\n\nA perfect number, as you probably know, is a number with $\\sigma(n) = 2n$.\n\nLet us define the perfection quotient of a positive integer as $p(n) = \\dfrac{\\sigma(n)}{n}$.\n\nFind the sum of all positive integers $n \\le 10^{18}$ for which $p(n)$ has the form $k + \\dfrac{1}{2}$, where $k$ is an integer.", "raw_html": "

For a positive integer $n$, let $\\sigma(n)$ be the sum of all divisors of $n$. For example, $\\sigma(6) = 1 + 2 + 3 + 6 = 12$.

\n\n

A perfect number, as you probably know, is a number with $\\sigma(n) = 2n$.

\n\n

Let us define the perfection quotient of a positive integer as $p(n) = \\dfrac{\\sigma(n)}{n}$.

\n\n

Find the sum of all positive integers $n \\le 10^{18}$ for which $p(n)$ has the form $k + \\dfrac{1}{2}$, where $k$ is an integer.

", "url": "https://projecteuler.net/problem=241", "answer": "482316491800641154"} {"id": 242, "problem": "Given the set $\\{1,2,\\dots,n\\}$, we define $f(n, k)$ as the number of its $k$-element subsets with an odd sum of elements. For example, $f(5,3) = 4$, since the set $\\{1,2,3,4,5\\}$ has four $3$-element subsets having an odd sum of elements, i.e.: $\\{1,2,4\\}$, $\\{1,3,5\\}$, $\\{2,3,4\\}$ and $\\{2,4,5\\}$.\n\nWhen all three values $n$, $k$ and $f(n, k)$ are odd, we say that they make\nan odd-triplet $[n,k,f(n, k)]$.\n\nThere are exactly five odd-triplets with $n \\le 10$, namely:\n\n$[1,1,f(1,1) = 1]$, $[5,1,f(5,1) = 3]$, $[5,5,f(5,5) = 1]$, $[9,1,f(9,1) = 5]$ and $[9,9,f(9,9) = 1]$.\n\nHow many odd-triplets are there with $n \\le 10^{12}$?", "raw_html": "

Given the set $\\{1,2,\\dots,n\\}$, we define $f(n, k)$ as the number of its $k$-element subsets with an odd sum of elements. For example, $f(5,3) = 4$, since the set $\\{1,2,3,4,5\\}$ has four $3$-element subsets having an odd sum of elements, i.e.: $\\{1,2,4\\}$, $\\{1,3,5\\}$, $\\{2,3,4\\}$ and $\\{2,4,5\\}$.

\n\n

When all three values $n$, $k$ and $f(n, k)$ are odd, we say that they make\nan odd-triplet $[n,k,f(n, k)]$.

\n\n

There are exactly five odd-triplets with $n \\le 10$, namely:
\n$[1,1,f(1,1) = 1]$, $[5,1,f(5,1) = 3]$, $[5,5,f(5,5) = 1]$, $[9,1,f(9,1) = 5]$ and $[9,9,f(9,9) = 1]$.

\n\n

How many odd-triplets are there with $n \\le 10^{12}$?

", "url": "https://projecteuler.net/problem=242", "answer": "997104142249036713"} {"id": 243, "problem": "A positive fraction whose numerator is less than its denominator is called a proper fraction.\n\nFor any denominator, $d$, there will be $d - 1$ proper fractions; for example, with $d = 12$:\n$1 / 12, 2 / 12, 3 / 12, 4 / 12, 5 / 12, 6 / 12, 7 / 12, 8 / 12, 9 / 12, 10 / 12, 11 / 12$.\n\nWe shall call a fraction that cannot be cancelled down a resilient fraction.\n\nFurthermore we shall define the resilience of a denominator, $R(d)$, to be the ratio of its proper fractions that are resilient; for example, $R(12) = 4/11$.\n\nIn fact, $d = 12$ is the smallest denominator having a resilience $R(d) \\lt 4/10$.\n\nFind the smallest denominator $d$, having a resilience $R(d) \\lt 15499/94744$.", "raw_html": "

A positive fraction whose numerator is less than its denominator is called a proper fraction.
\nFor any denominator, $d$, there will be $d - 1$ proper fractions; for example, with $d = 12$:
$1 / 12, 2 / 12, 3 / 12, 4 / 12, 5 / 12, 6 / 12, 7 / 12, 8 / 12, 9 / 12, 10 / 12, 11 / 12$.\n

\n\n

We shall call a fraction that cannot be cancelled down a resilient fraction.
\nFurthermore we shall define the resilience of a denominator, $R(d)$, to be the ratio of its proper fractions that are resilient; for example, $R(12) = 4/11$.
\nIn fact, $d = 12$ is the smallest denominator having a resilience $R(d) \\lt 4/10$.

\n\n

Find the smallest denominator $d$, having a resilience $R(d) \\lt 15499/94744$.

", "url": "https://projecteuler.net/problem=243", "answer": "892371480"} {"id": 244, "problem": "You probably know the game Fifteen Puzzle. Here, instead of numbered tiles, we have seven red tiles and eight blue tiles.\n\nA move is denoted by the uppercase initial of the direction (Left, Right, Up, Down) in which the tile is slid, e.g. starting from configuration (S), by the sequence LULUR we reach the configuration (E):\n\n| (S) | | , (E) | |\n\nFor each path, its checksum is calculated by (pseudocode):\n\n$$\\begin{align}\n\\mathrm{checksum} &= 0\\\\\n\\mathrm{checksum} &= (\\mathrm{checksum} \\times 243 + m_1) \\bmod 100\\,000\\,007\\\\\n\\mathrm{checksum} &= (\\mathrm{checksum} \\times 243 + m_2) \\bmod 100\\,000\\,007\\\\\n\\cdots &\\\\\n\\mathrm{checksum} &= (\\mathrm{checksum} \\times 243 + m_n) \\bmod 100\\,000\\,007\n\\end{align}$$\nwhere $m_k$ is the ASCII value of the $k$th letter in the move sequence and the ASCII values for the moves are:\n\n| L | 76 |\n| R | 82 |\n| U | 85 |\n| D | 68 |\n\nFor the sequence LULUR given above, the checksum would be $19761398$.\n\nNow, starting from configuration (S),\nfind all shortest ways to reach configuration (T).\n\n| (S) | | , (T) | |\n\nWhat is the sum of all checksums for the paths having the minimal length?", "raw_html": "

You probably know the game Fifteen Puzzle. Here, instead of numbered tiles, we have seven red tiles and eight blue tiles.

\n

A move is denoted by the uppercase initial of the direction (Left, Right, Up, Down) in which the tile is slid, e.g. starting from configuration (S), by the sequence LULUR we reach the configuration (E):

\n

\n\n
(S)\"0244_start.gif\", (E)\"0244_example.gif\"
\n\n

For each path, its checksum is calculated by (pseudocode):\n

\n$$\\begin{align}\n\\mathrm{checksum} &= 0\\\\\n\\mathrm{checksum} &= (\\mathrm{checksum} \\times 243 + m_1) \\bmod 100\\,000\\,007\\\\\n\\mathrm{checksum} &= (\\mathrm{checksum} \\times 243 + m_2) \\bmod 100\\,000\\,007\\\\\n\\cdots &\\\\\n\\mathrm{checksum} &= (\\mathrm{checksum} \\times 243 + m_n) \\bmod 100\\,000\\,007\n\\end{align}$$\nwhere $m_k$ is the ASCII value of the $k$th letter in the move sequence and the ASCII values for the moves are:\n\n
\n
L76
R82
U85
D68
\n\n

For the sequence LULUR given above, the checksum would be $19761398$.

\n

Now, starting from configuration (S),\nfind all shortest ways to reach configuration (T).

\n

\n\n
(S)\"0244_start.gif\", (T)\"0244_target.gif\"
\n\n

What is the sum of all checksums for the paths having the minimal length?

", "url": "https://projecteuler.net/problem=244", "answer": "96356848"} {"id": 245, "problem": "We shall call a fraction that cannot be cancelled down a resilient fraction.\nFurthermore we shall define the resilience of a denominator, $R(d)$, to be the ratio of its proper fractions that are resilient; for example, $R(12) = \\dfrac{4}{11}$.\n\nThe resilience of a number $d \\gt 1$ is then $\\dfrac{\\varphi(d)}{d - 1}$, where $\\varphi$ is Euler's totient function.\n\nWe further define the coresilience of a number $n \\gt 1$ as $C(n) = \\dfrac{n - \\varphi(n)}{n - 1}$.\n\nThe coresilience of a prime $p$ is $C(p) = \\dfrac{1}{p - 1}$.\n\nFind the sum of all composite integers $1 \\lt n \\le 2 \\times 10^{11}$, for which $C(n)$ is a unit fractionA fraction with numerator $1$.", "raw_html": "

We shall call a fraction that cannot be cancelled down a resilient fraction.
Furthermore we shall define the resilience of a denominator, $R(d)$, to be the ratio of its proper fractions that are resilient; for example, $R(12) = \\dfrac{4}{11}$.

\n\n

The resilience of a number $d \\gt 1$ is then $\\dfrac{\\varphi(d)}{d - 1}$, where $\\varphi$ is Euler's totient function.

\n\n

We further define the coresilience of a number $n \\gt 1$ as $C(n) = \\dfrac{n - \\varphi(n)}{n - 1}$.

\n\n

The coresilience of a prime $p$ is $C(p) = \\dfrac{1}{p - 1}$.

\n\n

Find the sum of all composite integers $1 \\lt n \\le 2 \\times 10^{11}$, for which $C(n)$ is a unit fractionA fraction with numerator $1$.

", "url": "https://projecteuler.net/problem=245", "answer": "288084712410001"} {"id": 246, "problem": "A definition for an ellipse is:\n\nGiven a circle $c$ with centre $M$ and radius $r$ and a point $G$ such that $d(G,M) \\lt r$, the locus of the points that are equidistant from $c$ and $G$ form an ellipse.\n\nThe construction of the points of the ellipse is shown below.\n\nGiven are the points $M(-2000,1500)$ and $G(8000,1500)$.\n\nGiven is also the circle $c$ with centre $M$ and radius $15000$.\n\nThe locus of the points that are equidistant from $G$ and $c$ form an ellipse $e$.\n\nFrom a point $P$ outside $e$ the two tangents $t_1$ and $t_2$ to the ellipse are drawn.\n\nLet the points where $t_1$ and $t_2$ touch the ellipse be $R$ and $S$.\n\nFor how many lattice points $P$ is angle $RPS$ greater than $45$ degrees?", "raw_html": "

\nA definition for an ellipse is:
\nGiven a circle $c$ with centre $M$ and radius $r$ and a point $G$ such that $d(G,M) \\lt r$, the locus of the points that are equidistant from $c$ and $G$ form an ellipse.\n

\nThe construction of the points of the ellipse is shown below.\n\n
\n\"\"
\n\n

\nGiven are the points $M(-2000,1500)$ and $G(8000,1500)$.
\nGiven is also the circle $c$ with centre $M$ and radius $15000$.
\nThe locus of the points that are equidistant from $G$ and $c$ form an ellipse $e$.
\nFrom a point $P$ outside $e$ the two tangents $t_1$ and $t_2$ to the ellipse are drawn.
\nLet the points where $t_1$ and $t_2$ touch the ellipse be $R$ and $S$.\n

\n
\n\"\"
\n

\nFor how many lattice points $P$ is angle $RPS$ greater than $45$ degrees?\n

", "url": "https://projecteuler.net/problem=246", "answer": "810834388"} {"id": 247, "problem": "Consider the region constrained by $1 \\le x$ and $0 \\le y \\le 1/x$.\n\nLet $S_1$ be the largest square that can fit under the curve.\n\nLet $S_2$ be the largest square that fits in the remaining area, and so on.\n\nLet the index of $S_n$ be the pair $(\\text{left}, \\text{below})$ indicating the number of squares to the left of $S_n$ and the number of squares below $S_n$.\n\nThe diagram shows some such squares labelled by number.\n\n$S_2$ has one square to its left and none below, so the index of $S_2$ is $(1,0)$.\n\nIt can be seen that the index of $S_{32}$ is $(1,1)$ as is the index of $S_{50}$.\n\n$50$ is the largest $n$ for which the index of $S_n$ is $(1,1)$.\n\nWhat is the largest $n$ for which the index of $S_n$ is $(3,3)$?", "raw_html": "

Consider the region constrained by $1 \\le x$ and $0 \\le y \\le 1/x$.\n

\nLet $S_1$ be the largest square that can fit under the curve.
\nLet $S_2$ be the largest square that fits in the remaining area, and so on.
\nLet the index of $S_n$ be the pair $(\\text{left}, \\text{below})$ indicating the number of squares to the left of $S_n$ and the number of squares below $S_n$.\n

\n
\n\"\"
\n

\nThe diagram shows some such squares labelled by number.
\n$S_2$ has one square to its left and none below, so the index of $S_2$ is $(1,0)$.
\nIt can be seen that the index of $S_{32}$ is $(1,1)$ as is the index of $S_{50}$.
\n$50$ is the largest $n$ for which the index of $S_n$ is $(1,1)$.\n

\n

\nWhat is the largest $n$ for which the index of $S_n$ is $(3,3)$?\n

", "url": "https://projecteuler.net/problem=247", "answer": "782252"} {"id": 248, "problem": "The first number $n$ for which $\\phi(n)=13!$ is $6227180929$.\n\nFind the $150\\,000$th such number.", "raw_html": "

The first number $n$ for which $\\phi(n)=13!$ is $6227180929$.

\n

Find the $150\\,000$th such number.

", "url": "https://projecteuler.net/problem=248", "answer": "23507044290"} {"id": 249, "problem": "Let $S = \\{2, 3, 5, \\dots, 4999\\}$ be the set of prime numbers less than $5000$.\n\nFind the number of subsets of $S$, the sum of whose elements is a prime number.\n\nEnter the rightmost $16$ digits as your answer.", "raw_html": "

Let $S = \\{2, 3, 5, \\dots, 4999\\}$ be the set of prime numbers less than $5000$.

\n

Find the number of subsets of $S$, the sum of whose elements is a prime number.
\nEnter the rightmost $16$ digits as your answer.

", "url": "https://projecteuler.net/problem=249", "answer": "9275262564250418"} {"id": 250, "problem": "Find the number of non-empty subsets of $\\{1^1, 2^2, 3^3,\\dots, 250250^{250250}\\}$, the sum of whose elements is divisible by $250$. Enter the rightmost $16$ digits as your answer.", "raw_html": "

Find the number of non-empty subsets of $\\{1^1, 2^2, 3^3,\\dots, 250250^{250250}\\}$, the sum of whose elements is divisible by $250$. Enter the rightmost $16$ digits as your answer.

", "url": "https://projecteuler.net/problem=250", "answer": "1425480602091519"} {"id": 251, "problem": "A triplet of positive integers $(a, b, c)$ is called a Cardano Triplet if it satisfies the condition:\n\n$$\\sqrt[3]{a + b \\sqrt{c}} + \\sqrt[3]{a - b \\sqrt{c}} = 1$$\n\nFor example, $(2,1,5)$ is a Cardano Triplet.\n\nThere exist $149$ Cardano Triplets for which $a + b + c \\le 1000$.\n\nFind how many Cardano Triplets exist such that $a + b + c \\le 110\\,000\\,000$.", "raw_html": "

\nA triplet of positive integers $(a, b, c)$ is called a Cardano Triplet if it satisfies the condition:

\n$$\\sqrt[3]{a + b \\sqrt{c}} + \\sqrt[3]{a - b \\sqrt{c}} = 1$$\n\n

\nFor example, $(2,1,5)$ is a Cardano Triplet.\n

\n

\nThere exist $149$ Cardano Triplets for which $a + b + c \\le 1000$.\n

\n

\nFind how many Cardano Triplets exist such that $a + b + c \\le 110\\,000\\,000$.\n

", "url": "https://projecteuler.net/problem=251", "answer": "18946051"} {"id": 252, "problem": "Given a set of points on a plane, we define a convex hole to be a convex polygon having as vertices any of the given points and not containing any of the given points in its interior (in addition to the vertices, other given points may lie on the perimeter of the polygon).\n\nAs an example, the image below shows a set of twenty points and a few such convex holes.\nThe convex hole shown as a red heptagon has an area equal to $1049694.5$ square units, which is the highest possible area for a convex hole on the given set of points.\n\nFor our example, we used the first $20$ points $(T_{2k - 1}, T_{2k})$, for $k = 1,2,\\dots,20$, produced with the pseudo-random number generator:\n\n$$\\begin{align}\nS_0 &= 290797\\\\\nS_{n + 1} &= S_n^2 \\bmod 50515093\\\\\nT_n &= (S_n \\bmod 2000) - 1000\n\\end{align}$$\n\ni.e. $(527, 144), (-488, 732), (-454, -947), \\dots$\n\nWhat is the maximum area for a convex hole on the set containing the first $500$ points in the pseudo-random sequence?\nSpecify your answer including one digit after the decimal point.", "raw_html": "

\nGiven a set of points on a plane, we define a convex hole to be a convex polygon having as vertices any of the given points and not containing any of the given points in its interior (in addition to the vertices, other given points may lie on the perimeter of the polygon). \n

\n

\nAs an example, the image below shows a set of twenty points and a few such convex holes. \nThe convex hole shown as a red heptagon has an area equal to $1049694.5$ square units, which is the highest possible area for a convex hole on the given set of points.\n

\n
\n\"\"
\n

\n

For our example, we used the first $20$ points $(T_{2k - 1}, T_{2k})$, for $k = 1,2,\\dots,20$, produced with the pseudo-random number generator:

\n\n$$\\begin{align}\nS_0 &= 290797\\\\\nS_{n + 1} &= S_n^2 \\bmod 50515093\\\\\nT_n &= (S_n \\bmod 2000) - 1000\n\\end{align}$$\n\n

\ni.e. $(527, 144), (-488, 732), (-454, -947), \\dots$\n

\n

\nWhat is the maximum area for a convex hole on the set containing the first $500$ points in the pseudo-random sequence?
Specify your answer including one digit after the decimal point.\n

", "url": "https://projecteuler.net/problem=252", "answer": "104924.0"} {"id": 253, "problem": "A small child has a “number caterpillar” consisting of forty jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers $1$ to $40$ in order.\n\nEvery night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order.\nAs the caterpillar is built up in this way, it forms distinct segments that gradually merge together.\nThe number of segments starts at zero (no pieces placed), generally increases up to about eleven or twelve, then tends to drop again before finishing at a single segment (all pieces placed).\n\nFor example:\n\n| Piece Placed | Segments So Far |\n| --- | --- |\n| 12 | 1 |\n| 4 | 2 |\n| 29 | 3 |\n| 6 | 4 |\n| 34 | 5 |\n| 5 | 4 |\n| 35 | 4 |\n| … | … |\n\nLet $M$ be the maximum number of segments encountered during a random tidy-up of the caterpillar.\n\nFor a caterpillar of ten pieces, the number of possibilities for each $M$ is\n\n| M | Possibilities |\n| --- | --- |\n| 1 | 512 |\n| 2 | 250912 |\n| 3 | 1815264 |\n| 4 | 1418112 |\n| 5 | 144000 |\n\nso the most likely value of $M$ is $3$ and the average value is $385643/113400 = 3.400732$, rounded to six decimal places.\n\nThe most likely value of $M$ for a forty-piece caterpillar is $11$; but what is the average value of $M$?\n\nGive your answer rounded to six decimal places.", "raw_html": "

A small child has a “number caterpillar” consisting of forty jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers $1$ to $40$ in order.

\n\n

Every night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order.
As the caterpillar is built up in this way, it forms distinct segments that gradually merge together.
The number of segments starts at zero (no pieces placed), generally increases up to about eleven or twelve, then tends to drop again before finishing at a single segment (all pieces placed).

\n\n

For example:

\n
\n\n\n
Piece PlacedSegments So Far
121
42
293
64
345
54
354
\n\n

Let $M$ be the maximum number of segments encountered during a random tidy-up of the caterpillar.
\nFor a caterpillar of ten pieces, the number of possibilities for each $M$ is

\n
\n\n\n
MPossibilities
1512      
2250912      
31815264      
41418112      
5144000      
\n\n

so the most likely value of $M$ is $3$ and the average value is $385643/113400 = 3.400732$, rounded to six decimal places.

\n\n

The most likely value of $M$ for a forty-piece caterpillar is $11$; but what is the average value of $M$?

\n

Give your answer rounded to six decimal places.

", "url": "https://projecteuler.net/problem=253", "answer": "11.492847"} {"id": 254, "problem": "Define $f(n)$ as the sum of the factorials of the digits of $n$. For example, $f(342) = 3! + 4! + 2! = 32$.\n\nDefine $sf(n)$ as the sum of the digits of $f(n)$. So $sf(342) = 3 + 2 = 5$.\n\nDefine $g(i)$ to be the smallest positive integer $n$ such that $sf(n) = i$. Though $sf(342)$ is $5$, $sf(25)$ is also $5$, and it can be verified that $g(5)$ is $25$.\n\nDefine $sg(i)$ as the sum of the digits of $g(i)$. So $sg(5) = 2 + 5 = 7$.\n\nFurther, it can be verified that $g(20)$ is $267$ and $\\sum sg(i)$ for $1 \\le i \\le 20$ is $156$.\n\nWhat is $\\sum sg(i)$ for $1 \\le i \\le 150$?", "raw_html": "

Define $f(n)$ as the sum of the factorials of the digits of $n$. For example, $f(342) = 3! + 4! + 2! = 32$.

\n\n

Define $sf(n)$ as the sum of the digits of $f(n)$. So $sf(342) = 3 + 2 = 5$.

\n\n

Define $g(i)$ to be the smallest positive integer $n$ such that $sf(n) = i$. Though $sf(342)$ is $5$, $sf(25)$ is also $5$, and it can be verified that $g(5)$ is $25$.

\n\n

Define $sg(i)$ as the sum of the digits of $g(i)$. So $sg(5) = 2 + 5 = 7$.

\n\n

Further, it can be verified that $g(20)$ is $267$ and $\\sum sg(i)$ for $1 \\le i \\le 20$ is $156$.

\n\n

What is $\\sum sg(i)$ for $1 \\le i \\le 150$?

", "url": "https://projecteuler.net/problem=254", "answer": "8184523820510"} {"id": 255, "problem": "We define the rounded-square-root of a positive integer $n$ as the square root of $n$ rounded to the nearest integer.\n\nThe following procedure (essentially Heron's method adapted to integer arithmetic) finds the rounded-square-root of $n$:\n\nLet $d$ be the number of digits of the number $n$.\n\nIf $d$ is odd, set $x_0 = 2 \\times 10^{(d-1)/2}$.\n\nIf $d$ is even, set $x_0 = 7 \\times 10^{(d-2)/2}$.\n\nRepeat:\n\n$$x_{k+1} = \\Biggl\\lfloor{\\dfrac{x_k + \\lceil{n / x_k}\\rceil}{2}}\\Biggr\\rfloor$$\n\nuntil $x_{k+1} = x_k$.\n\nAs an example, let us find the rounded-square-root of $n = 4321$.\n$n$ has $4$ digits, so $x_0 = 7 \\times 10^{(4-2)/2} = 70$.\n\n$$x_1 = \\Biggl\\lfloor{\\dfrac{70 + \\lceil{4321 / 70}\\rceil}{2}}\\Biggr\\rfloor = 66$$\n$$x_2 = \\Biggl\\lfloor{\\dfrac{66 + \\lceil{4321 / 66}\\rceil}{2}}\\Biggr\\rfloor = 66$$\n\nSince $x_2 = x_1$, we stop here.\n\nSo, after just two iterations, we have found that the rounded-square-root of $4321$ is $66$ (the actual square root is $65.7343137\\cdots$).\n\nThe number of iterations required when using this method is surprisingly low.\n\nFor example, we can find the rounded-square-root of a $5$-digit integer ($10\\,000 \\le n \\le 99\\,999$) with an average of $3.2102888889$ iterations (the average value was rounded to $10$ decimal places).\n\nUsing the procedure described above, what is the average number of iterations required to find the rounded-square-root of a $14$-digit number ($10^{13} \\le n \\lt 10^{14}$)?\n\nGive your answer rounded to $10$ decimal places.\n\nNote: The symbols $\\lfloor x \\rfloor$ and $\\lceil x \\rceil$ represent the floor functionthe largest integer not greater than $x$ and ceiling functionthe smallest integer not less than $x$ respectively.", "raw_html": "

We define the rounded-square-root of a positive integer $n$ as the square root of $n$ rounded to the nearest integer.

\n\n

The following procedure (essentially Heron's method adapted to integer arithmetic) finds the rounded-square-root of $n$:

\n

Let $d$ be the number of digits of the number $n$.
\nIf $d$ is odd, set $x_0 = 2 \\times 10^{(d-1)/2}$.
\nIf $d$ is even, set $x_0 = 7 \\times 10^{(d-2)/2}$.
\nRepeat:

\n$$x_{k+1} = \\Biggl\\lfloor{\\dfrac{x_k + \\lceil{n / x_k}\\rceil}{2}}\\Biggr\\rfloor$$\n\n

until $x_{k+1} = x_k$.

\n

As an example, let us find the rounded-square-root of $n = 4321$.
$n$ has $4$ digits, so $x_0 = 7 \\times 10^{(4-2)/2} = 70$.
\n$$x_1 = \\Biggl\\lfloor{\\dfrac{70 + \\lceil{4321 / 70}\\rceil}{2}}\\Biggr\\rfloor = 66$$\n$$x_2 = \\Biggl\\lfloor{\\dfrac{66 + \\lceil{4321 / 66}\\rceil}{2}}\\Biggr\\rfloor = 66$$\n\nSince $x_2 = x_1$, we stop here.
\nSo, after just two iterations, we have found that the rounded-square-root of $4321$ is $66$ (the actual square root is $65.7343137\\cdots$).\n

\n

The number of iterations required when using this method is surprisingly low.
\nFor example, we can find the rounded-square-root of a $5$-digit integer ($10\\,000 \\le n \\le 99\\,999$) with an average of $3.2102888889$ iterations (the average value was rounded to $10$ decimal places).\n

\n

Using the procedure described above, what is the average number of iterations required to find the rounded-square-root of a $14$-digit number ($10^{13} \\le n \\lt 10^{14}$)?
\nGive your answer rounded to $10$ decimal places.\n

\n

Note: The symbols $\\lfloor x \\rfloor$ and $\\lceil x \\rceil$ represent the floor functionthe largest integer not greater than $x$ and ceiling functionthe smallest integer not less than $x$ respectively.\n

", "url": "https://projecteuler.net/problem=255", "answer": "4.4474011180"} {"id": 256, "problem": "Tatami are rectangular mats, used to completely cover the floor of a room, without overlap.\n\nAssuming that the only type of available tatami has dimensions $1 \\times 2$, there are obviously some limitations for the shape and size of the rooms that can be covered.\n\nFor this problem, we consider only rectangular rooms with integer dimensions $a, b$ and even size $s = a \\cdot b$.\n\nWe use the term 'size' to denote the floor surface area of the room, and — without loss of generality — we add the condition $a \\le b$.\n\nThere is one rule to follow when laying out tatami: there must be no points where corners of four different mats meet.\n\nFor example, consider the two arrangements below for a $4 \\times 4$ room:\n\nThe arrangement on the left is acceptable, whereas the one on the right is not: a red \"X\" in the middle, marks the point where four tatami meet.\n\nBecause of this rule, certain even-sized rooms cannot be covered with tatami: we call them tatami-free rooms.\n\nFurther, we define $T(s)$ as the number of tatami-free rooms of size $s$.\n\nThe smallest tatami-free room has size $s = 70$ and dimensions $7 \\times 10$.\n\nAll the other rooms of size $s = 70$ can be covered with tatami; they are: $1 \\times 70$, $2 \\times 35$ and $5 \\times 14$.\n\nHence, $T(70) = 1$.\n\nSimilarly, we can verify that $T(1320) = 5$ because there are exactly $5$ tatami-free rooms of size $s = 1320$:\n\n$20 \\times 66$, $22 \\times 60$, $24 \\times 55$, $30 \\times 44$ and $33 \\times 40$.\n\nIn fact, $s = 1320$ is the smallest room-size $s$ for which $T(s) = 5$.\n\nFind the smallest room-size $s$ for which $T(s) = 200$.", "raw_html": "

Tatami are rectangular mats, used to completely cover the floor of a room, without overlap.

\n\n

Assuming that the only type of available tatami has dimensions $1 \\times 2$, there are obviously some limitations for the shape and size of the rooms that can be covered.

\n\n

For this problem, we consider only rectangular rooms with integer dimensions $a, b$ and even size $s = a \\cdot b$.
\nWe use the term 'size' to denote the floor surface area of the room, and — without loss of generality — we add the condition $a \\le b$.

\n\n

There is one rule to follow when laying out tatami: there must be no points where corners of four different mats meet.
\nFor example, consider the two arrangements below for a $4 \\times 4$ room:

\n
\n\"0256_tatami3.gif\"
\n\n

The arrangement on the left is acceptable, whereas the one on the right is not: a red \"X\" in the middle, marks the point where four tatami meet.

\n\n

Because of this rule, certain even-sized rooms cannot be covered with tatami: we call them tatami-free rooms.
\nFurther, we define $T(s)$ as the number of tatami-free rooms of size $s$.

\n\n

The smallest tatami-free room has size $s = 70$ and dimensions $7 \\times 10$.
\nAll the other rooms of size $s = 70$ can be covered with tatami; they are: $1 \\times 70$, $2 \\times 35$ and $5 \\times 14$.
\nHence, $T(70) = 1$.

\n\n

Similarly, we can verify that $T(1320) = 5$ because there are exactly $5$ tatami-free rooms of size $s = 1320$:
\n$20 \\times 66$, $22 \\times 60$, $24 \\times 55$, $30 \\times 44$ and $33 \\times 40$.
\nIn fact, $s = 1320$ is the smallest room-size $s$ for which $T(s) = 5$.

\n\n

Find the smallest room-size $s$ for which $T(s) = 200$.

", "url": "https://projecteuler.net/problem=256", "answer": "85765680"} {"id": 257, "problem": "Given is an integer sided triangle $ABC$ with sides $a \\le b \\le c$.\n($AB = c$, $BC = a$ and $AC = b$.)\n\nThe angular bisectors of the triangle intersect the sides at points $E$, $F$ and $G$ (see picture below).\n\nThe segments $EF$, $EG$ and $FG$ partition the triangle $ABC$ into four smaller triangles: $AEG$, $BFE$, $CGF$ and $EFG$.\n\nIt can be proven that for each of these four triangles the ratio area($ABC$)/area(subtriangle) is rational.\n\nHowever, there exist triangles for which some or all of these ratios are integral.\n\nHow many triangles $ABC$ with perimeter $\\le 100\\,000\\,000$ exist so that the ratio area($ABC$)/area($AEG$) is integral?", "raw_html": "

Given is an integer sided triangle $ABC$ with sides $a \\le b \\le c$. \n($AB = c$, $BC = a$ and $AC = b$.)
\nThe angular bisectors of the triangle intersect the sides at points $E$, $F$ and $G$ (see picture below).\n

\n
\n\"0257_bisector.gif\"
\n

\nThe segments $EF$, $EG$ and $FG$ partition the triangle $ABC$ into four smaller triangles: $AEG$, $BFE$, $CGF$ and $EFG$.
\nIt can be proven that for each of these four triangles the ratio area($ABC$)/area(subtriangle) is rational.
\nHowever, there exist triangles for which some or all of these ratios are integral.\n

\n

\nHow many triangles $ABC$ with perimeter $\\le 100\\,000\\,000$ exist so that the ratio area($ABC$)/area($AEG$) is integral?\n

", "url": "https://projecteuler.net/problem=257", "answer": "139012411"} {"id": 258, "problem": "A sequence is defined as:\n\n- $g_k = 1$, for $0 \\le k \\le 1999$\n\n- $g_k = g_{k-2000} + g_{k - 1999}$, for $k \\ge 2000$.\n\nFind $g_k \\bmod 20092010$ for $k = 10^{18}$.", "raw_html": "

A sequence is defined as:

\n

\n

Find $g_k \\bmod 20092010$ for $k = 10^{18}$.

", "url": "https://projecteuler.net/problem=258", "answer": "12747994"} {"id": 259, "problem": "A positive integer will be called reachable if it can result from an arithmetic expression obeying the following rules:\n\n- Uses the digits $1$ through $9$, in that order and exactly once each.\n\n- Any successive digits can be concatenated (for example, using the digits $2$, $3$ and $4$ we obtain the number $234$).\n\n- Only the four usual binary arithmetic operations (addition, subtraction, multiplication and division) are allowed.\n\n- Each operation can be used any number of times, or not at all.\n\n- Unary minusA minus sign applied to a single operand (as opposed to a subtraction operator between two operands) is not allowed.\n\n- Any number of (possibly nested) parentheses may be used to define the order of operations.\n\nFor example, $42$ is reachable, since $(1 / 23) \\times ((4 \\times 5) - 6) \\times (78 - 9) = 42$.\n\nWhat is the sum of all positive reachable integers?", "raw_html": "

A positive integer will be called reachable if it can result from an arithmetic expression obeying the following rules:

\n\n

For example, $42$ is reachable, since $(1 / 23) \\times ((4 \\times 5) - 6) \\times (78 - 9) = 42$.

\n\n

What is the sum of all positive reachable integers?

", "url": "https://projecteuler.net/problem=259", "answer": "20101196798"} {"id": 260, "problem": "A game is played with three piles of stones and two players.\n\nOn each player's turn, the player may remove one or more stones from the piles. However, if the player takes stones from more than one pile, then the same number of stones must be removed from each of the selected piles.\n\nIn other words, the player chooses some $N \\gt 0$ and removes:\n\n- $N$ stones from any single pile; or\n\n- $N$ stones from each of any two piles ($2N$ total); or\n\n- $N$ stones from each of the three piles ($3N$ total).\n\nThe player taking the last stone(s) wins the game.\n\nA winning configuration is one where the first player can force a win.\n\nFor example, $(0,0,13)$, $(0,11,11)$, and $(5,5,5)$ are winning configurations because the first player can immediately remove all stones.\n\nA losing configuration is one where the second player can force a win, no matter what the first player does.\n\nFor example, $(0,1,2)$ and $(1,3,3)$ are losing configurations: any legal move leaves a winning configuration for the second player.\n\nConsider all losing configurations $(x_i, y_i, z_i)$ where $x_i \\le y_i \\le z_i \\le 100$.\n\nWe can verify that $\\sum (x_i + y_i + z_i) = 173895$ for these.\n\nFind $\\sum (x_i + y_i + z_i)$ where $(x_i, y_i, z_i)$ ranges over the losing configurations with $x_i \\le y_i \\le z_i \\le 1000$.", "raw_html": "

A game is played with three piles of stones and two players.
\nOn each player's turn, the player may remove one or more stones from the piles. However, if the player takes stones from more than one pile, then the same number of stones must be removed from each of the selected piles.

\n\n

In other words, the player chooses some $N \\gt 0$ and removes:

\n\n\n\n

The player taking the last stone(s) wins the game.

\n\n

A winning configuration is one where the first player can force a win.
\nFor example, $(0,0,13)$, $(0,11,11)$, and $(5,5,5)$ are winning configurations because the first player can immediately remove all stones.

\n\n

A losing configuration is one where the second player can force a win, no matter what the first player does.
\nFor example, $(0,1,2)$ and $(1,3,3)$ are losing configurations: any legal move leaves a winning configuration for the second player.

\n\n

Consider all losing configurations $(x_i, y_i, z_i)$ where $x_i \\le y_i \\le z_i \\le 100$.
\nWe can verify that $\\sum (x_i + y_i + z_i) = 173895$ for these.

\n\n

Find $\\sum (x_i + y_i + z_i)$ where $(x_i, y_i, z_i)$ ranges over the losing configurations with $x_i \\le y_i \\le z_i \\le 1000$.

", "url": "https://projecteuler.net/problem=260", "answer": "167542057"} {"id": 261, "problem": "Let us call a positive integer $k$ a square-pivot, if there is a pair of integers $m \\gt 0$ and $n \\ge k$, such that the sum of the $(m+1)$ consecutive squares up to $k$ equals the sum of the $m$ consecutive squares from $(n+1)$ on:\n\n$$(k - m)^2 + \\cdots + k^2 = (n + 1)^2 + \\cdots + (n + m)^2.$$\n\nSome small square-pivots are\n\n- $\\mathbf 4$: $3^2 + \\mathbf 4^2 = 5^2$\n\n- $\\mathbf{21}$: $20^2 + \\mathbf{21}^2 = 29^2$\n\n- $\\mathbf{24}$: $21^2 + 22^2 + 23^2 + \\mathbf{24}^2 = 25^2 + 26^2 + 27^2$\n\n- $\\mathbf{110}$: $108^2 + 109^2 + \\mathbf{110}^2 = 133^2 + 134^2$\n\nFind the sum of all distinct square-pivots $\\le 10^{10}$.", "raw_html": "

Let us call a positive integer $k$ a square-pivot, if there is a pair of integers $m \\gt 0$ and $n \\ge k$, such that the sum of the $(m+1)$ consecutive squares up to $k$ equals the sum of the $m$ consecutive squares from $(n+1)$ on:

\n$$(k - m)^2 + \\cdots + k^2 = (n + 1)^2 + \\cdots + (n + m)^2.$$\n\n

Some small square-pivots are\n

Find the sum of all distinct square-pivots $\\le 10^{10}$.

", "url": "https://projecteuler.net/problem=261", "answer": "238890850232021"} {"id": 262, "problem": "The following equation represents the continuous topography of a mountainous region, giving the elevationheight above sea level $h$ at any point $(x, y)$:\n$$h = \\left(5000 - \\frac{x^2 + y^2 + xy}{200} + \\frac{25(x + y)}2\\right) \\cdot e^{-\\left|\\frac{x^2 + y^2}{1000000} - \\frac{3(x + y)}{2000} + \\frac 7 {10}\\right|}.$$\n\nA mosquito intends to fly from $A(200,200)$ to $B(1400,1400)$, without leaving the area given by $0 \\le x, y \\le 1600$.\n\nBecause of the intervening mountains, it first rises straight up to a point $A^\\prime$, having elevation $f$. Then, while remaining at the same elevation $f$, it flies around any obstacles until it arrives at a point $B^\\prime$ directly above $B$.\n\nFirst, determine $f_{\\mathrm{min}}$ which is the minimum constant elevation allowing such a trip from $A$ to $B$, while remaining in the specified area.\n\nThen, find the length of the shortest path between $A^\\prime$ and $B^\\prime$, while flying at that constant elevation $f_{\\mathrm{min}}$.\n\nGive that length as your answer, rounded to three decimal places.\n\nNote: For convenience, the elevation function shown above is repeated below, in a form suitable for most programming languages:\n\nh=( 5000-0.005*(x*x+y*y+x*y)+12.5*(x+y) ) * exp( -abs(0.000001*(x*x+y*y)-0.0015*(x+y)+0.7) )", "raw_html": "

The following equation represents the continuous topography of a mountainous region, giving the elevationheight above sea level $h$ at any point $(x, y)$:\n$$h = \\left(5000 - \\frac{x^2 + y^2 + xy}{200} + \\frac{25(x + y)}2\\right) \\cdot e^{-\\left|\\frac{x^2 + y^2}{1000000} - \\frac{3(x + y)}{2000} + \\frac 7 {10}\\right|}.$$\n

\n\n

A mosquito intends to fly from $A(200,200)$ to $B(1400,1400)$, without leaving the area given by $0 \\le x, y \\le 1600$.

\n\n

Because of the intervening mountains, it first rises straight up to a point $A^\\prime$, having elevation $f$. Then, while remaining at the same elevation $f$, it flies around any obstacles until it arrives at a point $B^\\prime$ directly above $B$.

\n\n

First, determine $f_{\\mathrm{min}}$ which is the minimum constant elevation allowing such a trip from $A$ to $B$, while remaining in the specified area.
\nThen, find the length of the shortest path between $A^\\prime$ and $B^\\prime$, while flying at that constant elevation $f_{\\mathrm{min}}$.

\n\n

Give that length as your answer, rounded to three decimal places.

\n\n

Note: For convenience, the elevation function shown above is repeated below, in a form suitable for most programming languages:
\nh=( 5000-0.005*(x*x+y*y+x*y)+12.5*(x+y) ) * exp( -abs(0.000001*(x*x+y*y)-0.0015*(x+y)+0.7) )

", "url": "https://projecteuler.net/problem=262", "answer": "2531.205"} {"id": 263, "problem": "Consider the number $6$. The divisors of $6$ are: $1,2,3$ and $6$.\n\nEvery number from $1$ up to and including $6$ can be written as a sum of distinct divisors of $6$:\n\n$1=1$, $2=2$, $3=1+2$, $4=1+3$, $5=2+3$, $6=6$.\n\nA number $n$ is called a practical number if every number from $1$ up to and including $n$ can be expressed as a sum of distinct divisors of $n$.\n\nA pair of consecutive prime numbers with a difference of six is called a sexy pair (since \"sex\" is the Latin word for \"six\"). The first sexy pair is $(23, 29)$.\n\nWe may occasionally find a triple-pair, which means three consecutive sexy prime pairs, such that the second member of each pair is the first member of the next pair.\n\nWe shall call a number $n$ such that :\n\n- $(n-9, n-3)$, $(n-3,n+3)$, $(n+3, n+9)$ form a triple-pair, and\n\n- the numbers $n-8$, $n-4$, $n$, $n+4$ and $n+8$ are all practical,\n\n\nan engineers’ paradise.\n\nFind the sum of the first four engineers’ paradises.", "raw_html": "

\nConsider the number $6$. The divisors of $6$ are: $1,2,3$ and $6$.
\nEvery number from $1$ up to and including $6$ can be written as a sum of distinct divisors of $6$:
\n$1=1$, $2=2$, $3=1+2$, $4=1+3$, $5=2+3$, $6=6$.
\nA number $n$ is called a practical number if every number from $1$ up to and including $n$ can be expressed as a sum of distinct divisors of $n$.\n

\n

\nA pair of consecutive prime numbers with a difference of six is called a sexy pair (since \"sex\" is the Latin word for \"six\"). The first sexy pair is $(23, 29)$.\n

\n

\nWe may occasionally find a triple-pair, which means three consecutive sexy prime pairs, such that the second member of each pair is the first member of the next pair.\n

\n

\nWe shall call a number $n$ such that :\n

\nan engineers’ paradise.\n\n

\nFind the sum of the first four engineers’ paradises.\n

", "url": "https://projecteuler.net/problem=263", "answer": "2039506520"} {"id": 264, "problem": "Consider all the triangles having:\n\n- All their vertices on lattice pointsInteger coordinates.\n\n- CircumcentreCentre of the circumscribed circle at the origin $O$.\n\n- OrthocentrePoint where the three altitudes meet at the point $H(5, 0)$.\n\nThere are nine such triangles having a perimeter $\\le 50$.\n\nListed and shown in ascending order of their perimeter, they are:\n\n| $A(-4, 3)$, $B(5, 0)$, $C(4, -3)$\n$A(4, 3)$, $B(5, 0)$, $C(-4, -3)$\n$A(-3, 4)$, $B(5, 0)$, $C(3, -4)$\n$A(3, 4)$, $B(5, 0)$, $C(-3, -4)$\n$A(0, 5)$, $B(5, 0)$, $C(0, -5)$\n$A(1, 8)$, $B(8, -1)$, $C(-4, -7)$\n$A(8, 1)$, $B(1, -8)$, $C(-4, 7)$\n$A(2, 9)$, $B(9, -2)$, $C(-6, -7)$\n$A(9, 2)$, $B(2, -9)$, $C(-6, 7)$ | |\n\nThe sum of their perimeters, rounded to four decimal places, is $291.0089$.\n\nFind all such triangles with a perimeter $\\le 10^5$.\n\nEnter as your answer the sum of their perimeters rounded to four decimal places.", "raw_html": "

Consider all the triangles having:\n

There are nine such triangles having a perimeter $\\le 50$.
\nListed and shown in ascending order of their perimeter, they are:

\n\n

\n\n
$A(-4, 3)$, $B(5, 0)$, $C(4, -3)$
\n$A(4, 3)$, $B(5, 0)$, $C(-4, -3)$
\n$A(-3, 4)$, $B(5, 0)$, $C(3, -4)$


\n$A(3, 4)$, $B(5, 0)$, $C(-3, -4)$
\n$A(0, 5)$, $B(5, 0)$, $C(0, -5)$
\n$A(1, 8)$, $B(8, -1)$, $C(-4, -7)$


\n$A(8, 1)$, $B(1, -8)$, $C(-4, 7)$
\n$A(2, 9)$, $B(9, -2)$, $C(-6, -7)$
\n$A(9, 2)$, $B(2, -9)$, $C(-6, 7)$
\"0264_TriangleCentres.gif\"
\n\n

The sum of their perimeters, rounded to four decimal places, is $291.0089$.

\n\n

Find all such triangles with a perimeter $\\le 10^5$.
\nEnter as your answer the sum of their perimeters rounded to four decimal places.

", "url": "https://projecteuler.net/problem=264", "answer": "2816417.1055"} {"id": 265, "problem": "$2^N$ binary digits can be placed in a circle so that all the $N$-digit clockwise subsequences are distinct.\n\nFor $N=3$, two such circular arrangements are possible, ignoring rotations:\n\nFor the first arrangement, the $3$-digit subsequences, in clockwise order, are:\n$000$, $001$, $010$, $101$, $011$, $111$, $110$ and $100$.\n\nEach circular arrangement can be encoded as a number by concatenating the binary digits starting with the subsequence of all zeros as the most significant bits and proceeding clockwise. The two arrangements for $N=3$ are thus represented as $23$ and $29$:\n\n$$\\begin{align}\n00010111_2 &= 23\\\\\n00011101_2 &= 29\n\\end{align}$$\n\nCalling $S(N)$ the sum of the unique numeric representations, we can see that $S(3) = 23 + 29 = 52$.\n\nFind $S(5)$.", "raw_html": "

$2^N$ binary digits can be placed in a circle so that all the $N$-digit clockwise subsequences are distinct.

\n\n

For $N=3$, two such circular arrangements are possible, ignoring rotations:

\n
\"0265_BinaryCircles.gif\"
\n\n

For the first arrangement, the $3$-digit subsequences, in clockwise order, are:
$000$, $001$, $010$, $101$, $011$, $111$, $110$ and $100$.

\n\n

Each circular arrangement can be encoded as a number by concatenating the binary digits starting with the subsequence of all zeros as the most significant bits and proceeding clockwise. The two arrangements for $N=3$ are thus represented as $23$ and $29$:\n

\n$$\\begin{align}\n00010111_2 &= 23\\\\\n00011101_2 &= 29\n\\end{align}$$\n\n

Calling $S(N)$ the sum of the unique numeric representations, we can see that $S(3) = 23 + 29 = 52$.

\n\n

Find $S(5)$.

", "url": "https://projecteuler.net/problem=265", "answer": "209110240768"} {"id": 266, "problem": "The divisors of $12$ are: $1,2,3,4,6$ and $12$.\n\nThe largest divisor of $12$ that does not exceed the square root of $12$ is $3$.\n\nWe shall call the largest divisor of an integer $n$ that does not exceed the square root of $n$ the pseudo square root ($\\operatorname{PSR}$) of $n$.\n\nIt can be seen that $\\operatorname{PSR}(3102)=47$.\n\nLet $p$ be the product of the primes below $190$.\n\nFind $\\operatorname{PSR}(p) \\bmod 10^{16}$.", "raw_html": "

\nThe divisors of $12$ are: $1,2,3,4,6$ and $12$.
\nThe largest divisor of $12$ that does not exceed the square root of $12$ is $3$.
\nWe shall call the largest divisor of an integer $n$ that does not exceed the square root of $n$ the pseudo square root ($\\operatorname{PSR}$) of $n$.
\nIt can be seen that $\\operatorname{PSR}(3102)=47$.\n

\n

\nLet $p$ be the product of the primes below $190$.
\nFind $\\operatorname{PSR}(p) \\bmod 10^{16}$.\n

", "url": "https://projecteuler.net/problem=266", "answer": "1096883702440585"} {"id": 267, "problem": "You are given a unique investment opportunity.\n\nStarting with £1 of capital, you can choose a fixed proportion, f, of your capital to bet on a fair coin toss repeatedly for 1000 tosses.\n\nYour return is double your bet for heads and you lose your bet for tails.\n\nFor example, if f = 1/4, for the first toss you bet £0.25, and if heads comes up you win £0.5 and so then have £1.5. You then bet £0.375 and if the second toss is tails, you have £1.125.\n\nChoosing f to maximize your chances of having at least £1,000,000,000 after 1,000 flips, what is the chance that you become a billionaire?\n\nAll computations are assumed to be exact (no rounding), but give your answer rounded to 12 digits behind the decimal point in the form 0.abcdefghijkl.", "raw_html": "

You are given a unique investment opportunity.

\n

Starting with £1 of capital, you can choose a fixed proportion, f, of your capital to bet on a fair coin toss repeatedly for 1000 tosses.

\n

Your return is double your bet for heads and you lose your bet for tails.

\n

For example, if f = 1/4, for the first toss you bet £0.25, and if heads comes up you win £0.5 and so then have £1.5. You then bet £0.375 and if the second toss is tails, you have £1.125.

\n

Choosing f to maximize your chances of having at least £1,000,000,000 after 1,000 flips, what is the chance that you become a billionaire?

\n

All computations are assumed to be exact (no rounding), but give your answer rounded to 12 digits behind the decimal point in the form 0.abcdefghijkl.

", "url": "https://projecteuler.net/problem=267", "answer": "0.999992836187"} {"id": 268, "problem": "It can be verified that there are $23$ positive integers less than $1000$ that are divisible by at least four distinct primes less than $100$.\n\nFind how many positive integers less than $10^{16}$ are divisible by at least four distinct primes less than $100$.", "raw_html": "

It can be verified that there are $23$ positive integers less than $1000$ that are divisible by at least four distinct primes less than $100$.

\n\n

Find how many positive integers less than $10^{16}$ are divisible by at least four distinct primes less than $100$.

", "url": "https://projecteuler.net/problem=268", "answer": "785478606870985"} {"id": 269, "problem": "A root or zero of a polynomial $P(x)$ is a solution to the equation $P(x) = 0$.\n\nDefine $P_n$ as the polynomial whose coefficients are the digits of $n$.\n\nFor example, $P_{5703}(x) = 5x^3 + 7x^2 + 3$.\n\nWe can see that:\n\n- $P_n(0)$ is the last digit of $n$,\n\n- $P_n(1)$ is the sum of the digits of $n$,\n\n- $P_n(10)$ is $n$ itself.\n\nDefine $Z(k)$ as the number of positive integers, $n$, not exceeding $k$ for which the polynomial $P_n$ has at least one integer root.\n\nIt can be verified that $Z(100\\,000)$ is $14696$.\n\nWhat is $Z(10^{16})$?", "raw_html": "

A root or zero of a polynomial $P(x)$ is a solution to the equation $P(x) = 0$.
\nDefine $P_n$ as the polynomial whose coefficients are the digits of $n$.
\nFor example, $P_{5703}(x) = 5x^3 + 7x^2 + 3$.

\n\n

We can see that:

Define $Z(k)$ as the number of positive integers, $n$, not exceeding $k$ for which the polynomial $P_n$ has at least one integer root.

\n\n

It can be verified that $Z(100\\,000)$ is $14696$.

\n\n

What is $Z(10^{16})$?

", "url": "https://projecteuler.net/problem=269", "answer": "1311109198529286"} {"id": 270, "problem": "A square piece of paper with integer dimensions $N \\times N$ is placed with a corner at the origin and two of its sides along the $x$- and $y$-axes. Then, we cut it up respecting the following rules:\n\n- We only make straight cuts between two points lying on different sides of the square, and having integer coordinates.\n\n- Two cuts cannot cross, but several cuts can meet at the same border point.\n\n- Proceed until no more legal cuts can be made.\n\nCounting any reflections or rotations as distinct, we call $C(N)$ the number of ways to cut an $N \\times N$ square. For example, $C(1) = 2$ and $C(2) = 30$ (shown below).\n\nWhat is $C(30) \\bmod 10^8$?", "raw_html": "

A square piece of paper with integer dimensions $N \\times N$ is placed with a corner at the origin and two of its sides along the $x$- and $y$-axes. Then, we cut it up respecting the following rules:\n

Counting any reflections or rotations as distinct, we call $C(N)$ the number of ways to cut an $N \\times N$ square. For example, $C(1) = 2$ and $C(2) = 30$ (shown below).

\n
\"0270_CutSquare.gif\"
\n\n

What is $C(30) \\bmod 10^8$?

", "url": "https://projecteuler.net/problem=270", "answer": "82282080"} {"id": 271, "problem": "For a positive number $n$, define $S(n)$ as the sum of the integers $x$, for which $1 \\lt x \\lt n$ and\n$x^3 \\equiv 1 \\bmod n$.\n\nWhen $n=91$, there are $8$ possible values for $x$, namely: $9, 16, 22, 29, 53, 74, 79, 81$.\n\nThus, $S(91)=9+16+22+29+53+74+79+81=363$.\n\nFind $S(13082761331670030)$.", "raw_html": "

\nFor a positive number $n$, define $S(n)$ as the sum of the integers $x$, for which $1 \\lt x \\lt n$ and
$x^3 \\equiv 1 \\bmod n$.\n

\n

\nWhen $n=91$, there are $8$ possible values for $x$, namely: $9, 16, 22, 29, 53, 74, 79, 81$.
\nThus, $S(91)=9+16+22+29+53+74+79+81=363$.

\n

\nFind $S(13082761331670030)$.\n

", "url": "https://projecteuler.net/problem=271", "answer": "4617456485273129588"} {"id": 272, "problem": "For a positive number $n$, define $C(n)$ as the number of the integers $x$, for which $1 \\lt x \\lt n$ and\n$x^3 \\equiv 1 \\bmod n$.\n\nWhen $n=91$, there are $8$ possible values for $x$, namely: $9, 16, 22, 29, 53, 74, 79, 81$.\n\nThus, $C(91)=8$.\n\nFind the sum of the positive numbers $n \\le 10^{11}$ for which $C(n)=242$.", "raw_html": "

\nFor a positive number $n$, define $C(n)$ as the number of the integers $x$, for which $1 \\lt x \\lt n$ and
$x^3 \\equiv 1 \\bmod n$.\n

\n

\nWhen $n=91$, there are $8$ possible values for $x$, namely: $9, 16, 22, 29, 53, 74, 79, 81$.
\nThus, $C(91)=8$.

\n

\nFind the sum of the positive numbers $n \\le 10^{11}$ for which $C(n)=242$.

", "url": "https://projecteuler.net/problem=272", "answer": "8495585919506151122"} {"id": 273, "problem": "Consider equations of the form: $a^2 + b^2 = N$, $0 \\le a \\le b$, $a$, $b$ and $N$ integer.\n\nFor $N=65$ there are two solutions:\n\n$a=1$, $b=8$ and $a=4$, $b=7$.\n\nWe call $S(N)$ the sum of the values of $a$ of all solutions of $a^2 + b^2 = N$, $0 \\le a \\le b$, $a$, $b$ and $N$ integer.\n\nThus $S(65) = 1 + 4 = 5$.\n\nFind $\\sum S(N)$, for all squarefree $N$ only divisible by primes of the form $4k+1$ with $4k+1 \\lt 150$.", "raw_html": "

Consider equations of the form: $a^2 + b^2 = N$, $0 \\le a \\le b$, $a$, $b$ and $N$ integer.

\n\n

For $N=65$ there are two solutions:

\n

$a=1$, $b=8$ and $a=4$, $b=7$.

\n

We call $S(N)$ the sum of the values of $a$ of all solutions of $a^2 + b^2 = N$, $0 \\le a \\le b$, $a$, $b$ and $N$ integer.

\n

Thus $S(65) = 1 + 4 = 5$.

\n

Find $\\sum S(N)$, for all squarefree $N$ only divisible by primes of the form $4k+1$ with $4k+1 \\lt 150$.

", "url": "https://projecteuler.net/problem=273", "answer": "2032447591196869022"} {"id": 274, "problem": "For each integer $p \\gt 1$ coprime to $10$ there is a positive divisibility multiplier $m \\lt p$ which preserves divisibility by $p$ for the following function on any positive integer, $n$:\n\n$f(n) = (\\text{all but the last digit of }n) + (\\text{the last digit of }n) \\cdot m$.\n\nThat is, if $m$ is the divisibility multiplier for $p$, then $f(n)$ is divisible by $p$ if and only if $n$ is divisible by $p$.\n\n(When $n$ is much larger than $p$, $f(n)$ will be less than $n$ and repeated application of $f$ provides a multiplicative divisibility test for $p$.)\n\nFor example, the divisibility multiplier for $113$ is $34$.\n\n$f(76275) = 7627 + 5 \\cdot 34 = 7797$: $76275$ and $7797$ are both divisible by $113$.\n$f(12345) = 1234 + 5 \\cdot 34 = 1404$: $12345$ and $1404$ are both not divisible by $113$.\n\nThe sum of the divisibility multipliers for the primes that are coprime to $10$ and less than $1000$ is $39517$. What is the sum of the divisibility multipliers for the primes that are coprime to $10$ and less than $10^7$?", "raw_html": "

For each integer $p \\gt 1$ coprime to $10$ there is a positive divisibility multiplier $m \\lt p$ which preserves divisibility by $p$ for the following function on any positive integer, $n$:

\n\n

$f(n) = (\\text{all but the last digit of }n) + (\\text{the last digit of }n) \\cdot m$.

\n\n

That is, if $m$ is the divisibility multiplier for $p$, then $f(n)$ is divisible by $p$ if and only if $n$ is divisible by $p$.

\n\n

(When $n$ is much larger than $p$, $f(n)$ will be less than $n$ and repeated application of $f$ provides a multiplicative divisibility test for $p$.)

\n\n

For example, the divisibility multiplier for $113$ is $34$.

\n\n

$f(76275) = 7627 + 5 \\cdot 34 = 7797$: $76275$ and $7797$ are both divisible by $113$.
$f(12345) = 1234 + 5 \\cdot 34 = 1404$: $12345$ and $1404$ are both not divisible by $113$.

\n\n

The sum of the divisibility multipliers for the primes that are coprime to $10$ and less than $1000$ is $39517$. What is the sum of the divisibility multipliers for the primes that are coprime to $10$ and less than $10^7$?

", "url": "https://projecteuler.net/problem=274", "answer": "1601912348822"} {"id": 275, "problem": "Let us define a balanced sculpture of order $n$ as follows:\n\n- A polyominoAn arrangement of identical squares connected through shared edges; holes are allowed. made up of $n + 1$ tiles known as the blocks ($n$ tiles)\nand the plinth (remaining tile);\n\n- the plinth has its centre at position ($x = 0, y = 0$);\n\n- the blocks have $y$-coordinates greater than zero (so the plinth is the unique lowest tile);\n\n- the centre of mass of all the blocks, combined, has $x$-coordinate equal to zero.\n\nWhen counting the sculptures, any arrangements which are simply reflections about the $y$-axis, are not counted as distinct. For example, the $18$ balanced sculptures of order $6$ are shown below; note that each pair of mirror images (about the $y$-axis) is counted as one sculpture:\n\nThere are $964$ balanced sculptures of order $10$ and $360505$ of order $15$.\nHow many balanced sculptures are there of order $18$?", "raw_html": "

Let us define a balanced sculpture of order $n$ as follows:\n

When counting the sculptures, any arrangements which are simply reflections about the $y$-axis, are not counted as distinct. For example, the $18$ balanced sculptures of order $6$ are shown below; note that each pair of mirror images (about the $y$-axis) is counted as one sculpture:

\n
\"0275_sculptures2.gif\"
\n\n

There are $964$ balanced sculptures of order $10$ and $360505$ of order $15$.
How many balanced sculptures are there of order $18$?

", "url": "https://projecteuler.net/problem=275", "answer": "15030564"} {"id": 276, "problem": "Consider the triangles with integer sides $a$, $b$ and $c$ with $a \\le b \\le c$.\n\nAn integer sided triangle $(a,b,c)$ is called primitive if $\\gcd(a, b, c)$$\\gcd(a,b,c)=\\gcd(a,\\gcd(b,c))$$=1$.\n\nHow many primitive integer sided triangles exist with a perimeter not exceeding $10\\,000\\,000$?", "raw_html": "

Consider the triangles with integer sides $a$, $b$ and $c$ with $a \\le b \\le c$.
\nAn integer sided triangle $(a,b,c)$ is called primitive if $\\gcd(a, b, c)$$\\gcd(a,b,c)=\\gcd(a,\\gcd(b,c))$$=1$.
\nHow many primitive integer sided triangles exist with a perimeter not exceeding $10\\,000\\,000$?\n

", "url": "https://projecteuler.net/problem=276", "answer": "5777137137739632912"} {"id": 277, "problem": "A modified Collatz sequence of integers is obtained from a starting value $a_1$ in the following way:\n\n$a_{n+1} = \\, \\,\\, \\frac {a_n} 3 \\quad$ if $a_n$ is divisible by $3$. We shall denote this as a large downward step, \"D\".\n\n$a_{n+1} = \\frac {4 a_n+2} 3 \\, \\,$ if $a_n$ divided by $3$ gives a remainder of $1$. We shall denote this as an upward step, \"U\".\n\n$a_{n+1} = \\frac {2 a_n -1} 3 \\, \\,$ if $a_n$ divided by $3$ gives a remainder of $2$. We shall denote this as a small downward step, \"d\".\n\nThe sequence terminates when some $a_n = 1$.\n\nGiven any integer, we can list out the sequence of steps.\n\nFor instance if $a_1=231$, then the sequence $\\{a_n\\}=\\{231,77,51,17,11,7,10,14,9,3,1\\}$ corresponds to the steps \"DdDddUUdDD\".\n\nOf course, there are other sequences that begin with that same sequence \"DdDddUUdDD....\".\n\nFor instance, if $a_1=1004064$, then the sequence is DdDddUUdDDDdUDUUUdDdUUDDDUdDD.\n\nIn fact, $1004064$ is the smallest possible $a_1 > 10^6$ that begins with the sequence DdDddUUdDD.\n\nWhat is the smallest $a_1 > 10^{15}$ that begins with the sequence \"UDDDUdddDDUDDddDdDddDDUDDdUUDd\"?", "raw_html": "

\nA modified Collatz sequence of integers is obtained from a starting value $a_1$ in the following way:

\n

\n$a_{n+1} = \\, \\,\\, \\frac {a_n} 3 \\quad$ if $a_n$ is divisible by $3$. We shall denote this as a large downward step, \"D\".

\n

\n$a_{n+1} = \\frac {4 a_n+2} 3 \\, \\,$ if $a_n$ divided by $3$ gives a remainder of $1$. We shall denote this as an upward step, \"U\".\n

\n

\n$a_{n+1} = \\frac {2 a_n -1} 3 \\, \\,$ if $a_n$ divided by $3$ gives a remainder of $2$. We shall denote this as a small downward step, \"d\".\n

\n\n\n

\nThe sequence terminates when some $a_n = 1$.\n

\n

\nGiven any integer, we can list out the sequence of steps.
\nFor instance if $a_1=231$, then the sequence $\\{a_n\\}=\\{231,77,51,17,11,7,10,14,9,3,1\\}$ corresponds to the steps \"DdDddUUdDD\".\n

\n

\nOf course, there are other sequences that begin with that same sequence \"DdDddUUdDD....\".
\nFor instance, if $a_1=1004064$, then the sequence is DdDddUUdDDDdUDUUUdDdUUDDDUdDD.
\nIn fact, $1004064$ is the smallest possible $a_1 > 10^6$ that begins with the sequence DdDddUUdDD.\n

\n

\nWhat is the smallest $a_1 > 10^{15}$ that begins with the sequence \"UDDDUdddDDUDDddDdDddDDUDDdUUDd\"?\n

", "url": "https://projecteuler.net/problem=277", "answer": "1125977393124310"} {"id": 278, "problem": "Given the values of integers $1 < a_1 < a_2 < \\dots < a_n$, consider the linear combination\n\n$q_1 a_1+q_2 a_2 + \\dots + q_n a_n=b$, using only integer values $q_k \\ge 0$.\n\nNote that for a given set of $a_k$, it may be that not all values of $b$ are possible.\n\nFor instance, if $a_1=5$ and $a_2=7$, there are no $q_1 \\ge 0$ and $q_2 \\ge 0$ such that $b$ could be\n\n$1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18$ or $23$.\n\nIn fact, $23$ is the largest impossible value of $b$ for $a_1=5$ and $a_2=7$.\nWe therefore call $f(5, 7) = 23$.\nSimilarly, it can be shown that $f(6, 10, 15)=29$ and $f(14, 22, 77) = 195$.\n\nFind $\\displaystyle \\sum f( p\\, q,p \\, r, q \\, r)$, where $p$, $q$ and $r$ are prime numbers and $p < q < r < 5000$.", "raw_html": "

\nGiven the values of integers $1 < a_1 < a_2 < \\dots < a_n$, consider the linear combination
\n$q_1 a_1+q_2 a_2 + \\dots + q_n a_n=b$, using only integer values $q_k \\ge 0$. \n

\n

\nNote that for a given set of $a_k$, it may be that not all values of $b$ are possible.
\nFor instance, if $a_1=5$ and $a_2=7$, there are no $q_1 \\ge 0$ and $q_2 \\ge 0$ such that $b$ could be
\n$1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18$ or $23$.\n
\nIn fact, $23$ is the largest impossible value of $b$ for $a_1=5$ and $a_2=7$.
We therefore call $f(5, 7) = 23$.
Similarly, it can be shown that $f(6, 10, 15)=29$ and $f(14, 22, 77) = 195$.\n

\n

\nFind $\\displaystyle \\sum f( p\\, q,p \\, r, q \\, r)$, where $p$, $q$ and $r$ are prime numbers and $p < q < r < 5000$.\n

", "url": "https://projecteuler.net/problem=278", "answer": "1228215747273908452"} {"id": 279, "problem": "How many triangles are there with integral sides, at least one integral angle (measured in degrees), and a perimeter that does not exceed $10^8$?", "raw_html": "

\nHow many triangles are there with integral sides, at least one integral angle (measured in degrees), and a perimeter that does not exceed $10^8$?\n

", "url": "https://projecteuler.net/problem=279", "answer": "416577688"} {"id": 280, "problem": "A laborious ant walks randomly on a $5 \\times 5$ grid. The walk starts from the central square. At each step, the ant moves to an adjacent square at random, without leaving the grid; thus there are $2$, $3$ or $4$ possible moves at each step depending on the ant's position.\n\nAt the start of the walk, a seed is placed on each square of the lower row. When the ant isn't carrying a seed and reaches a square of the lower row containing a seed, it will start to carry the seed. The ant will drop the seed on the first empty square of the upper row it eventually reaches.\n\nWhat's the expected number of steps until all seeds have been dropped in the top row?\n\nGive your answer rounded to $6$ decimal places.", "raw_html": "

A laborious ant walks randomly on a $5 \\times 5$ grid. The walk starts from the central square. At each step, the ant moves to an adjacent square at random, without leaving the grid; thus there are $2$, $3$ or $4$ possible moves at each step depending on the ant's position.

\n\n

At the start of the walk, a seed is placed on each square of the lower row. When the ant isn't carrying a seed and reaches a square of the lower row containing a seed, it will start to carry the seed. The ant will drop the seed on the first empty square of the upper row it eventually reaches.

\n\n

What's the expected number of steps until all seeds have been dropped in the top row?
\nGive your answer rounded to $6$ decimal places.

", "url": "https://projecteuler.net/problem=280", "answer": "430.088247"} {"id": 281, "problem": "You are given a pizza (perfect circle) that has been cut into $m \\cdot n$ equal pieces and you want to have exactly one topping on each slice.\n\nLet $f(m, n)$ denote the number of ways you can have toppings on the pizza with $m$ different toppings ($m \\ge 2$), using each topping on exactly $n$ slices ($n \\ge 1$).\nReflections are considered distinct, rotations are not.\n\nThus, for instance, $f(2,1) = 1$, $f(2, 2) = f(3, 1) = 2$ and $f(3, 2) = 16$.\n$f(3, 2)$ is shown below:\n\nFind the sum of all $f(m, n)$ such that $f(m, n) \\le 10^{15}$.", "raw_html": "

You are given a pizza (perfect circle) that has been cut into $m \\cdot n$ equal pieces and you want to have exactly one topping on each slice.

\n\n

Let $f(m, n)$ denote the number of ways you can have toppings on the pizza with $m$ different toppings ($m \\ge 2$), using each topping on exactly $n$ slices ($n \\ge 1$).
Reflections are considered distinct, rotations are not.

\n\n

Thus, for instance, $f(2,1) = 1$, $f(2, 2) = f(3, 1) = 2$ and $f(3, 2) = 16$.
$f(3, 2)$ is shown below:

\n\n
\"0281_pizza.gif\"
\n\n

Find the sum of all $f(m, n)$ such that $f(m, n) \\le 10^{15}$.

", "url": "https://projecteuler.net/problem=281", "answer": "1485776387445623"} {"id": 282, "problem": "$\\def\\htmltext#1{\\style{font-family:inherit;}{\\text{#1}}}$\n\nFor non-negative integers $m$, $n$, the Ackermann function $A(m,n)$ is defined as follows:\n\n$$\nA(m,n) = \\cases{\nn+1 &$\\htmltext{ if }m=0$\\cr\nA(m-1,1) &$\\htmltext{ if }m>0 \\htmltext{ and } n=0$\\cr\nA(m-1,A(m,n-1)) &$\\htmltext{ if }m>0 \\htmltext{ and } n>0$\\cr\n}$$\n\nFor example $A(1,0) = 2$, $A(2,2) = 7$ and $A(3,4) = 125$.\n\nFind $\\displaystyle\\sum_{n=0}^6 A(n,n)$ and give your answer mod $14^8$.", "raw_html": "$\\def\\htmltext#1{\\style{font-family:inherit;}{\\text{#1}}}$\n

\nFor non-negative integers $m$, $n$, the Ackermann function $A(m,n)$ is defined as follows:\n\n$$\nA(m,n) = \\cases{\nn+1 &$\\htmltext{ if }m=0$\\cr\nA(m-1,1) &$\\htmltext{ if }m>0 \\htmltext{ and } n=0$\\cr\nA(m-1,A(m,n-1)) &$\\htmltext{ if }m>0 \\htmltext{ and } n>0$\\cr\n}$$\n

\n

\nFor example $A(1,0) = 2$, $A(2,2) = 7$ and $A(3,4) = 125$.\n

\n

\nFind $\\displaystyle\\sum_{n=0}^6 A(n,n)$ and give your answer mod $14^8$.

", "url": "https://projecteuler.net/problem=282", "answer": "1098988351"} {"id": 283, "problem": "Consider the triangle with sides $6$, $8$, and $10$. It can be seen that the perimeter and the area are both equal to $24$.\nSo the area/perimeter ratio is equal to $1$.\n\nConsider also the triangle with sides $13$, $14$ and $15$. The perimeter equals $42$ while the area is equal to $84$.\nSo for this triangle the area/perimeter ratio is equal to $2$.\n\nFind the sum of the perimeters of all integer sided triangles for which the area/perimeter ratios are equal to positive integers not exceeding $1000$.", "raw_html": "

\nConsider the triangle with sides $6$, $8$, and $10$. It can be seen that the perimeter and the area are both equal to $24$. \nSo the area/perimeter ratio is equal to $1$.
\nConsider also the triangle with sides $13$, $14$ and $15$. The perimeter equals $42$ while the area is equal to $84$. \nSo for this triangle the area/perimeter ratio is equal to $2$.\n

\n

\nFind the sum of the perimeters of all integer sided triangles for which the area/perimeter ratios are equal to positive integers not exceeding $1000$.\n

", "url": "https://projecteuler.net/problem=283", "answer": "28038042525570324"} {"id": 284, "problem": "The 3-digit number 376 in the decimal numbering system is an example of numbers with the special property that its square ends with the same digits: 3762 = 141376. Let's call a number with this property a steady square.\n\nSteady squares can also be observed in other numbering systems. In the base 14 numbering system, the 3-digit number c37 is also a steady square: c372 = aa0c37, and the sum of its digits is c+3+7=18 in the same numbering system. The letters a, b, c and d are used for the 10, 11, 12 and 13 digits respectively, in a manner similar to the hexadecimal numbering system.\n\nFor 1 ≤ n ≤ 9, the sum of the digits of all the n-digit steady squares in the base 14 numbering system is 2d8 (582 decimal). Steady squares with leading 0's are not allowed.\n\nFind the sum of the digits of all the n-digit steady squares in the base 14 numbering system for\n\n1 ≤ n ≤ 10000 (decimal) and give your answer in the base 14 system using lower case letters where necessary.", "raw_html": "

The 3-digit number 376 in the decimal numbering system is an example of numbers with the special property that its square ends with the same digits: 3762 = 141376. Let's call a number with this property a steady square.

\n\n

Steady squares can also be observed in other numbering systems. In the base 14 numbering system, the 3-digit number c37 is also a steady square: c372 = aa0c37, and the sum of its digits is c+3+7=18 in the same numbering system. The letters a, b, c and d are used for the 10, 11, 12 and 13 digits respectively, in a manner similar to the hexadecimal numbering system.

\n\n

For 1 ≤ n ≤ 9, the sum of the digits of all the n-digit steady squares in the base 14 numbering system is 2d8 (582 decimal). Steady squares with leading 0's are not allowed.

\n\n

Find the sum of the digits of all the n-digit steady squares in the base 14 numbering system for
\n1 ≤ n ≤ 10000 (decimal) and give your answer in the base 14 system using lower case letters where necessary.

", "url": "https://projecteuler.net/problem=284", "answer": "5a411d7b"} {"id": 285, "problem": "Albert chooses a positive integer $k$, then two real numbers $a, b$ are randomly chosen in the interval $[0,1]$ with uniform distribution.\n\nThe square root of the sum $(k \\cdot a + 1)^2 + (k \\cdot b + 1)^2$ is then computed and rounded to the nearest integer. If the result is equal to $k$, he scores $k$ points; otherwise he scores nothing.\n\nFor example, if $k = 6$, $a = 0.2$ and $b = 0.85$, then $(k \\cdot a + 1)^2 + (k \\cdot b + 1)^2 = 42.05$.\n\nThe square root of $42.05$ is $6.484\\cdots$ and when rounded to the nearest integer, it becomes $6$.\n\nThis is equal to $k$, so he scores $6$ points.\n\nIt can be shown that if he plays $10$ turns with $k = 1, k = 2, \\dots, k = 10$, the expected value of his total score, rounded to five decimal places, is $10.20914$.\n\nIf he plays $10^5$ turns with $k = 1, k = 2, k = 3, \\dots, k = 10^5$, what is the expected value of his total score, rounded to five decimal places?", "raw_html": "

Albert chooses a positive integer $k$, then two real numbers $a, b$ are randomly chosen in the interval $[0,1]$ with uniform distribution.
\nThe square root of the sum $(k \\cdot a + 1)^2 + (k \\cdot b + 1)^2$ is then computed and rounded to the nearest integer. If the result is equal to $k$, he scores $k$ points; otherwise he scores nothing.

\n\n

For example, if $k = 6$, $a = 0.2$ and $b = 0.85$, then $(k \\cdot a + 1)^2 + (k \\cdot b + 1)^2 = 42.05$.
\nThe square root of $42.05$ is $6.484\\cdots$ and when rounded to the nearest integer, it becomes $6$.
\nThis is equal to $k$, so he scores $6$ points.

\n\n

It can be shown that if he plays $10$ turns with $k = 1, k = 2, \\dots, k = 10$, the expected value of his total score, rounded to five decimal places, is $10.20914$.

\n\n

If he plays $10^5$ turns with $k = 1, k = 2, k = 3, \\dots, k = 10^5$, what is the expected value of his total score, rounded to five decimal places?

", "url": "https://projecteuler.net/problem=285", "answer": "157055.80999"} {"id": 286, "problem": "Barbara is a mathematician and a basketball player. She has found that the probability of scoring a point when shooting from a distance $x$ is exactly $(1 - x / q)$, where $q$ is a real constant greater than $50$.\n\nDuring each practice run, she takes shots from distances $x = 1, x = 2, \\dots, x = 50$ and, according to her records, she has precisely a $2\\%$ chance to score a total of exactly $20$ points.\n\nFind $q$ and give your answer rounded to $10$ decimal places.", "raw_html": "

Barbara is a mathematician and a basketball player. She has found that the probability of scoring a point when shooting from a distance $x$ is exactly $(1 - x / q)$, where $q$ is a real constant greater than $50$.

\n\n

During each practice run, she takes shots from distances $x = 1, x = 2, \\dots, x = 50$ and, according to her records, she has precisely a $2\\%$ chance to score a total of exactly $20$ points.

\n\n

Find $q$ and give your answer rounded to $10$ decimal places.

", "url": "https://projecteuler.net/problem=286", "answer": "52.6494571953"} {"id": 287, "problem": "The quadtree encoding allows us to describe a $2^N \\times 2^N$ black and white image as a sequence of bits (0 and 1). Those sequences are to be read from left to right like this:\n\n- the first bit deals with the complete $2^N \\times 2^N$ region;\n\n- \"0\" denotes a split:\n\nthe current $2^n \\times 2^n$ region is divided into $4$ sub-regions of dimension $2^{n - 1} \\times 2^{n - 1}$,\n\nthe next bits contains the description of the top left, top right, bottom left and bottom right sub-regions - in that order;\n\n- \"10\" indicates that the current region contains only black pixels;\n\n- \"11\" indicates that the current region contains only white pixels.\n\nConsider the following $4 \\times 4$ image (colored marks denote places where a split can occur):\n\nThis image can be described by several sequences, for example :\n\"001010101001011111011010101010\", of length $30$, or\n\n\"0100101111101110\", of length $16$, which is the minimal sequence for this image.\n\nFor a positive integer $N$, define $D_N$ as the $2^N \\times 2^N$ image with the following coloring scheme:\n\n- the pixel with coordinates $x = 0, y = 0$ corresponds to the bottom left pixel,\n\n- if $(x - 2^{N - 1})^2 + (y - 2^{N - 1})^2 \\le 2^{2N - 2}$ then the pixel is black,\n\n- otherwise the pixel is white.\n\nWhat is the length of the minimal sequence describing $D_{24}$?", "raw_html": "

The quadtree encoding allows us to describe a $2^N \\times 2^N$ black and white image as a sequence of bits (0 and 1). Those sequences are to be read from left to right like this:\n

Consider the following $4 \\times 4$ image (colored marks denote places where a split can occur):

\n\n
\"0287_quadtree.gif\"
\n\n

This image can be described by several sequences, for example :\n\"001010101001011111011010101010\", of length $30$, or
\n\"0100101111101110\", of length $16$, which is the minimal sequence for this image.

\n\n

For a positive integer $N$, define $D_N$ as the $2^N \\times 2^N$ image with the following coloring scheme:\n

What is the length of the minimal sequence describing $D_{24}$?

", "url": "https://projecteuler.net/problem=287", "answer": "313135496"} {"id": 288, "problem": "For any prime $p$ the number $N(p, q)$ is defined by\n$N(p, q) = \\sum_{n = 0}^q T_n \\cdot p^n$\n\nwith $T_n$ generated by the following random number generator:\n\n$S_0 = 290797$\n\n$S_{n + 1} = S_n^2 \\bmod 50515093$\n\n$T_n = S_n \\bmod p$\n\nLet $\\operatorname{Nfac}(p, q)$ be the factorial of $N(p, q)$.\n\nLet $\\operatorname{NF}(p, q)$ be the number of factors $p$ in $\\operatorname{Nfac}(p, q)$.\n\nYou are given that $\\operatorname{NF}(3,10000) \\bmod 3^{20} = 624955285$.\n\nFind $\\operatorname{NF}(61, 10^7) \\bmod 61^{10}$.", "raw_html": "

\nFor any prime $p$ the number $N(p, q)$ is defined by\n$N(p, q) = \\sum_{n = 0}^q T_n \\cdot p^n$
\nwith $T_n$ generated by the following random number generator:

\n

\n$S_0 = 290797$
\n$S_{n + 1} = S_n^2 \\bmod 50515093$
\n$T_n = S_n \\bmod p$\n

\n

\nLet $\\operatorname{Nfac}(p, q)$ be the factorial of $N(p, q)$.
\nLet $\\operatorname{NF}(p, q)$ be the number of factors $p$ in $\\operatorname{Nfac}(p, q)$.\n

\n

\nYou are given that $\\operatorname{NF}(3,10000) \\bmod 3^{20} = 624955285$.\n

\n

\nFind $\\operatorname{NF}(61, 10^7) \\bmod 61^{10}$.

", "url": "https://projecteuler.net/problem=288", "answer": "605857431263981935"} {"id": 289, "problem": "Let $C(x, y)$ be a circle passing through the points $(x, y)$, $(x, y + 1)$, $(x + 1, y)$ and $(x + 1, y + 1)$.\n\nFor positive integers $m$ and $n$, let $E(m, n)$ be a configuration which consists of the $m \\cdot n$ circles:\n\n$\\{ C(x, y): 0 \\le x \\lt m, 0 \\le y \\lt n, x \\text{ and } y \\text{ are integers} \\}$.\n\nAn Eulerian cycle on $E(m, n)$ is a closed path that passes through each arc exactly once.\n\nMany such paths are possible on $E(m, n)$, but we are only interested in those which are not self-crossing: a non-crossing path just touches itself at lattice points, but it never crosses itself.\n\nThe image below shows $E(3,3)$ and an example of an Eulerian non-crossing path.\n\nLet $L(m, n)$ be the number of Eulerian non-crossing paths on $E(m, n)$.\n\nFor example, $L(1,2) = 2$, $L(2,2) = 37$ and $L(3,3) = 104290$.\n\nFind $L(6,10) \\bmod 10^{10}$.", "raw_html": "

Let $C(x, y)$ be a circle passing through the points $(x, y)$, $(x, y + 1)$, $(x + 1, y)$ and $(x + 1, y + 1)$.

\n\n

For positive integers $m$ and $n$, let $E(m, n)$ be a configuration which consists of the $m \\cdot n$ circles:
\n$\\{ C(x, y): 0 \\le x \\lt m, 0 \\le y \\lt n, x \\text{ and } y \\text{ are integers} \\}$.

\n\n

An Eulerian cycle on $E(m, n)$ is a closed path that passes through each arc exactly once.
\nMany such paths are possible on $E(m, n)$, but we are only interested in those which are not self-crossing: a non-crossing path just touches itself at lattice points, but it never crosses itself.

\n\n

The image below shows $E(3,3)$ and an example of an Eulerian non-crossing path.

\"0289_euler.gif\"
\n\n

Let $L(m, n)$ be the number of Eulerian non-crossing paths on $E(m, n)$.
\nFor example, $L(1,2) = 2$, $L(2,2) = 37$ and $L(3,3) = 104290$.

\n\n

Find $L(6,10) \\bmod 10^{10}$.

", "url": "https://projecteuler.net/problem=289", "answer": "6567944538"} {"id": 290, "problem": "How many integers $0 \\le n \\lt 10^{18}$ have the property that the sum of the digits of $n$ equals the sum of digits of $137n$?", "raw_html": "

\nHow many integers $0 \\le n \\lt 10^{18}$ have the property that the sum of the digits of $n$ equals the sum of digits of $137n$?\n

", "url": "https://projecteuler.net/problem=290", "answer": "20444710234716473"} {"id": 291, "problem": "A prime number $p$ is called a Panaitopol prime if $p = \\dfrac{x^4 - y^4}{x^3 + y^3}$ for some positive integers $x$ and $y$.\n\nFind how many Panaitopol primes are less than $5 \\times 10^{15}$.", "raw_html": "

\nA prime number $p$ is called a Panaitopol prime if $p = \\dfrac{x^4 - y^4}{x^3 + y^3}$ for some positive integers $x$ and $y$.

\n

\nFind how many Panaitopol primes are less than $5 \\times 10^{15}$.\n

", "url": "https://projecteuler.net/problem=291", "answer": "4037526"} {"id": 292, "problem": "We shall define a pythagorean polygon to be a convex polygon with the following properties:\n\n- there are at least three vertices,\n\n- no three vertices are aligned,\n\n- each vertex has integer coordinates,\n\n- each edge has integer length.\n\nFor a given integer $n$, define $P(n)$ as the number of distinct pythagorean polygons for which the perimeter is $\\le n$.\n\nPythagorean polygons should be considered distinct as long as none is a translation of another.\n\nYou are given that $P(4) = 1$, $P(30) = 3655$ and $P(60) = 891045$.\n\nFind $P(120)$.", "raw_html": "

We shall define a pythagorean polygon to be a convex polygon with the following properties:

For a given integer $n$, define $P(n)$ as the number of distinct pythagorean polygons for which the perimeter is $\\le n$.
\nPythagorean polygons should be considered distinct as long as none is a translation of another.

\n\n

You are given that $P(4) = 1$, $P(30) = 3655$ and $P(60) = 891045$.
\nFind $P(120)$.

", "url": "https://projecteuler.net/problem=292", "answer": "3600060866"} {"id": 293, "problem": "An even positive integer $N$ will be called admissible, if it is a power of $2$ or its distinct prime factors are consecutive primes.\n\nThe first twelve admissible numbers are $2,4,6,8,12,16,18,24,30,32,36,48$.\n\nIf $N$ is admissible, the smallest integer $M \\gt 1$ such that $N+M$ is prime, will be called the pseudo-Fortunate number for $N$.\n\nFor example, $N=630$ is admissible since it is even and its distinct prime factors are the consecutive primes $2,3,5$ and $7$.\n\nThe next prime number after $631$ is $641$; hence, the pseudo-Fortunate number for $630$ is $M=11$.\n\nIt can also be seen that the pseudo-Fortunate number for $16$ is $3$.\n\nFind the sum of all distinct pseudo-Fortunate numbers for admissible numbers $N$ less than $10^9$.", "raw_html": "

\nAn even positive integer $N$ will be called admissible, if it is a power of $2$ or its distinct prime factors are consecutive primes.
\nThe first twelve admissible numbers are $2,4,6,8,12,16,18,24,30,32,36,48$.\n

\n

\nIf $N$ is admissible, the smallest integer $M \\gt 1$ such that $N+M$ is prime, will be called the pseudo-Fortunate number for $N$.\n

\n

\nFor example, $N=630$ is admissible since it is even and its distinct prime factors are the consecutive primes $2,3,5$ and $7$.
\nThe next prime number after $631$ is $641$; hence, the pseudo-Fortunate number for $630$ is $M=11$.
\nIt can also be seen that the pseudo-Fortunate number for $16$ is $3$.\n

\n

\nFind the sum of all distinct pseudo-Fortunate numbers for admissible numbers $N$ less than $10^9$.\n

", "url": "https://projecteuler.net/problem=293", "answer": "2209"} {"id": 294, "problem": "For a positive integer $k$, define $d(k)$ as the sum of the digits of $k$ in its usual decimal representation.\nThus $d(42) = 4+2 = 6$.\n\nFor a positive integer $n$, define $S(n)$ as the number of positive integers $k \\lt 10^n$ with the following properties :\n\n- $k$ is divisible by $23$ and\n\n- $d(k) = 23$.\n\nYou are given that $S(9) = 263626$ and $S(42) = 6377168878570056$.\n\nFind $S(11^{12})$ and give your answer mod $10^9$.", "raw_html": "

\nFor a positive integer $k$, define $d(k)$ as the sum of the digits of $k$ in its usual decimal representation.\nThus $d(42) = 4+2 = 6$.\n

\n

\nFor a positive integer $n$, define $S(n)$ as the number of positive integers $k \\lt 10^n$ with the following properties :\n

\nYou are given that $S(9) = 263626$ and $S(42) = 6377168878570056$.\n\n

\nFind $S(11^{12})$ and give your answer mod $10^9$.\n

", "url": "https://projecteuler.net/problem=294", "answer": "789184709"} {"id": 295, "problem": "We call the convex area enclosed by two circles a lenticular hole if:\n\n- The centres of both circles are on lattice points.\n\n- The two circles intersect at two distinct lattice points.\n\n- The interior of the convex area enclosed by both circles does not contain any lattice points.\n\nConsider the circles:\n\n$C_0$: $x^2 + y^2 = 25$\n\n$C_1$: $(x + 4)^2 + (y - 4)^2 = 1$\n\n$C_2$: $(x - 12)^2 + (y - 4)^2 = 65$\n\nThe circles $C_0$, $C_1$ and $C_2$ are drawn in the picture below.\n\n$C_0$ and $C_1$ form a lenticular hole, as well as $C_0$ and $C_2$.\n\nWe call an ordered pair of positive real numbers $(r_1, r_2)$ a lenticular pair if there exist two circles with radii $r_1$ and $r_2$ that form a lenticular hole.\nWe can verify that $(1, 5)$ and $(5, \\sqrt{65})$ are the lenticular pairs of the example above.\n\nLet $L(N)$ be the number of distinct lenticular pairs $(r_1, r_2)$ for which $0 \\lt r_1 \\le r_2 \\le N$.\n\nWe can verify that $L(10) = 30$ and $L(100) = 3442$.\n\nFind $L(100\\,000)$.", "raw_html": "

We call the convex area enclosed by two circles a lenticular hole if:\n

Consider the circles:
\n$C_0$: $x^2 + y^2 = 25$
\n$C_1$: $(x + 4)^2 + (y - 4)^2 = 1$
\n$C_2$: $(x - 12)^2 + (y - 4)^2 = 65$\n

\n

\nThe circles $C_0$, $C_1$ and $C_2$ are drawn in the picture below.

\n
\"0295_lenticular.gif\"
\n

\n$C_0$ and $C_1$ form a lenticular hole, as well as $C_0$ and $C_2$.

\n

\nWe call an ordered pair of positive real numbers $(r_1, r_2)$ a lenticular pair if there exist two circles with radii $r_1$ and $r_2$ that form a lenticular hole.\nWe can verify that $(1, 5)$ and $(5, \\sqrt{65})$ are the lenticular pairs of the example above.

\n

\nLet $L(N)$ be the number of distinct lenticular pairs $(r_1, r_2)$ for which $0 \\lt r_1 \\le r_2 \\le N$.
\nWe can verify that $L(10) = 30$ and $L(100) = 3442$.

\n

\nFind $L(100\\,000)$.\n

", "url": "https://projecteuler.net/problem=295", "answer": "4884650818"} {"id": 296, "problem": "Given is an integer sided triangle $ABC$ with $BC \\le AC \\le AB$.\n$k$ is the angular bisector of angle $ACB$.\n$m$ is the tangent at $C$ to the circumscribed circle of $ABC$.\n$n$ is a line parallel to $m$ through $B$.\n\nThe intersection of $n$ and $k$ is called $E$.\n\nHow many triangles $ABC$ with a perimeter not exceeding $100\\,000$ exist such that $BE$ has integral length?", "raw_html": "

\nGiven is an integer sided triangle $ABC$ with $BC \\le AC \\le AB$.
$k$ is the angular bisector of angle $ACB$.
$m$ is the tangent at $C$ to the circumscribed circle of $ABC$.
$n$ is a line parallel to $m$ through $B$.
\nThe intersection of $n$ and $k$ is called $E$.\n

\n
\"0296_bisector.gif\"
\n

\nHow many triangles $ABC$ with a perimeter not exceeding $100\\,000$ exist such that $BE$ has integral length?\n

", "url": "https://projecteuler.net/problem=296", "answer": "1137208419"} {"id": 297, "problem": "Each new term in the Fibonacci sequence is generated by adding the previous two terms.\n\nStarting with $1$ and $2$, the first $10$ terms will be: $1, 2, 3, 5, 8, 13, 21, 34, 55, 89$.\n\nEvery positive integer can be uniquely written as a sum of nonconsecutive terms of the Fibonacci sequence. For example, $100 = 3 + 8 + 89$.\n\nSuch a sum is called the Zeckendorf representation of the number.\n\nFor any integer $n \\gt 0$, let $z(n)$ be the number of terms in the Zeckendorf representation of $n$.\n\nThus, $z(5) = 1$, $z(14) = 2$, $z(100) = 3$ etc.\n\nAlso, for $0 \\lt n \\lt 10^6$, $\\sum z(n) = 7894453$.\n\nFind $\\sum z(n)$ for $0 \\lt n \\lt 10^{17}$.", "raw_html": "

Each new term in the Fibonacci sequence is generated by adding the previous two terms.
\nStarting with $1$ and $2$, the first $10$ terms will be: $1, 2, 3, 5, 8, 13, 21, 34, 55, 89$.

\n\n

Every positive integer can be uniquely written as a sum of nonconsecutive terms of the Fibonacci sequence. For example, $100 = 3 + 8 + 89$.
\nSuch a sum is called the Zeckendorf representation of the number.

\n\n

For any integer $n \\gt 0$, let $z(n)$ be the number of terms in the Zeckendorf representation of $n$.
\nThus, $z(5) = 1$, $z(14) = 2$, $z(100) = 3$ etc.
\nAlso, for $0 \\lt n \\lt 10^6$, $\\sum z(n) = 7894453$.

\n\n

Find $\\sum z(n)$ for $0 \\lt n \\lt 10^{17}$.

", "url": "https://projecteuler.net/problem=297", "answer": "2252639041804718029"} {"id": 298, "problem": "Larry and Robin play a memory game involving a sequence of random numbers between 1 and 10, inclusive, that are called out one at a time. Each player can remember up to 5 previous numbers. When the called number is in a player's memory, that player is awarded a point. If it's not, the player adds the called number to his memory, removing another number if his memory is full.\n\nBoth players start with empty memories. Both players always add new missed numbers to their memory but use a different strategy in deciding which number to remove:\n\nLarry's strategy is to remove the number that hasn't been called in the longest time.\n\nRobin's strategy is to remove the number that's been in the memory the longest time.\n\nExample game:\n\n| Turn | Callednumber | Larry'smemory | Larry'sscore | Robin'smemory | Robin'sscore |\n| --- | --- | --- | --- | --- | --- |\n| 1 | 1 | 1 | 0 | 1 | 0 |\n| 2 | 2 | 1,2 | 0 | 1,2 | 0 |\n| 3 | 4 | 1,2,4 | 0 | 1,2,4 | 0 |\n| 4 | 6 | 1,2,4,6 | 0 | 1,2,4,6 | 0 |\n| 5 | 1 | 1,2,4,6 | 1 | 1,2,4,6 | 1 |\n| 6 | 8 | 1,2,4,6,8 | 1 | 1,2,4,6,8 | 1 |\n| 7 | 10 | 1,4,6,8,10 | 1 | 2,4,6,8,10 | 1 |\n| 8 | 2 | 1,2,6,8,10 | 1 | 2,4,6,8,10 | 2 |\n| 9 | 4 | 1,2,4,8,10 | 1 | 2,4,6,8,10 | 3 |\n| 10 | 1 | 1,2,4,8,10 | 2 | 1,4,6,8,10 | 3 |\n\nDenoting Larry's score by L and Robin's score by R, what is the expected value of |L-R| after 50 turns? Give your answer rounded to eight decimal places using the format x.xxxxxxxx .", "raw_html": "

Larry and Robin play a memory game involving a sequence of random numbers between 1 and 10, inclusive, that are called out one at a time. Each player can remember up to 5 previous numbers. When the called number is in a player's memory, that player is awarded a point. If it's not, the player adds the called number to his memory, removing another number if his memory is full.

\n\n

Both players start with empty memories. Both players always add new missed numbers to their memory but use a different strategy in deciding which number to remove:
\nLarry's strategy is to remove the number that hasn't been called in the longest time.
\nRobin's strategy is to remove the number that's been in the memory the longest time.

\n\n

Example game:

\n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n\n
TurnCalled
number
Larry's
memory
Larry's
score
Robin's
memory
Robin's
score
111010
221,201,20
341,2,401,2,40
461,2,4,601,2,4,60
511,2,4,611,2,4,61
681,2,4,6,811,2,4,6,81
7101,4,6,8,1012,4,6,8,101
821,2,6,8,1012,4,6,8,102
941,2,4,8,1012,4,6,8,103
1011,2,4,8,1021,4,6,8,103
\n\n

Denoting Larry's score by L and Robin's score by R, what is the expected value of |L-R| after 50 turns? Give your answer rounded to eight decimal places using the format x.xxxxxxxx .

", "url": "https://projecteuler.net/problem=298", "answer": "1.76882294"} {"id": 299, "problem": "Four points with integer coordinates are selected:\n$A(a, 0)$, $B(b, 0)$, $C(0, c)$ and $D(0, d)$, with $0 \\lt a \\lt b$ and $0 \\lt c \\lt d$.\n\nPoint $P$, also with integer coordinates, is chosen on the line $AC$ so that the three triangles $ABP$, $CDP$ and $BDP$ are all similarHave equal angles.\n\nIt is easy to prove that the three triangles can be similar, only if $a = c$.\n\nSo, given that $a = c$, we are looking for triplets $(a, b, d)$ such that at least one point $P$ (with integer coordinates) exists on $AC$, making the three triangles $ABP$, $CDP$ and $BDP$ all similar.\n\nFor example, if $(a, b, d)=(2,3,4)$, it can be easily verified that point $P(1,1)$ satisfies the above condition.\nNote that the triplets $(2,3,4)$ and $(2,4,3)$ are considered as distinct, although point $P(1,1)$ is common for both.\n\nIf $b + d \\lt 100$, there are $92$ distinct triplets $(a, b, d)$ such that point $P$ exists.\n\nIf $b + d \\lt 100\\,000$, there are $320471$ distinct triplets $(a, b, d)$ such that point $P$ exists.\n\nIf $b + d \\lt 100\\,000\\,000$, how many distinct triplets $(a, b, d)$ are there such that point $P$ exists?", "raw_html": "

Four points with integer coordinates are selected:
$A(a, 0)$, $B(b, 0)$, $C(0, c)$ and $D(0, d)$, with $0 \\lt a \\lt b$ and $0 \\lt c \\lt d$.
\nPoint $P$, also with integer coordinates, is chosen on the line $AC$ so that the three triangles $ABP$, $CDP$ and $BDP$ are all similarHave equal angles.

\n
\"0299_ThreeSimTri.gif\"
\n

It is easy to prove that the three triangles can be similar, only if $a = c$.

\n\n

So, given that $a = c$, we are looking for triplets $(a, b, d)$ such that at least one point $P$ (with integer coordinates) exists on $AC$, making the three triangles $ABP$, $CDP$ and $BDP$ all similar.

\n\n

For example, if $(a, b, d)=(2,3,4)$, it can be easily verified that point $P(1,1)$ satisfies the above condition. \nNote that the triplets $(2,3,4)$ and $(2,4,3)$ are considered as distinct, although point $P(1,1)$ is common for both.

\n\n

If $b + d \\lt 100$, there are $92$ distinct triplets $(a, b, d)$ such that point $P$ exists.
\nIf $b + d \\lt 100\\,000$, there are $320471$ distinct triplets $(a, b, d)$ such that point $P$ exists.

\n

If $b + d \\lt 100\\,000\\,000$, how many distinct triplets $(a, b, d)$ are there such that point $P$ exists?

", "url": "https://projecteuler.net/problem=299", "answer": "549936643"} {"id": 300, "problem": "In a very simplified form, we can consider proteins as strings consisting of hydrophobic (H) and polar (P) elements, e.g. HHPPHHHPHHPH.\n\nFor this problem, the orientation of a protein is important; e.g. HPP is considered distinct from PPH. Thus, there are $2^n$ distinct proteins consisting of $n$ elements.\n\nWhen one encounters these strings in nature, they are always folded in such a way that the number of H-H contact points is as large as possible, since this is energetically advantageous.\n\nAs a result, the H-elements tend to accumulate in the inner part, with the P-elements on the outside.\n\nNatural proteins are folded in three dimensions of course, but we will only consider protein folding in two dimensions.\n\nThe figure below shows two possible ways that our example protein could be folded (H-H contact points are shown with red dots).\n\nThe folding on the left has only six H-H contact points, thus it would never occur naturally.\n\nOn the other hand, the folding on the right has nine H-H contact points, which is optimal for this string.\n\nAssuming that H and P elements are equally likely to occur in any position along the string, the average number of H-H contact points in an optimal folding of a random protein string of length $8$ turns out to be $850 / 2^8 = 3.3203125$.\n\nWhat is the average number of H-H contact points in an optimal folding of a random protein string of length $15$?\n\nGive your answer using as many decimal places as necessary for an exact result.", "raw_html": "

In a very simplified form, we can consider proteins as strings consisting of hydrophobic (H) and polar (P) elements, e.g. HHPPHHHPHHPH.
\nFor this problem, the orientation of a protein is important; e.g. HPP is considered distinct from PPH. Thus, there are $2^n$ distinct proteins consisting of $n$ elements.

\n\n

When one encounters these strings in nature, they are always folded in such a way that the number of H-H contact points is as large as possible, since this is energetically advantageous.
\nAs a result, the H-elements tend to accumulate in the inner part, with the P-elements on the outside.
\nNatural proteins are folded in three dimensions of course, but we will only consider protein folding in two dimensions.

\n\n

The figure below shows two possible ways that our example protein could be folded (H-H contact points are shown with red dots).

\n\n
\"0300_protein.gif\"
\n\n

The folding on the left has only six H-H contact points, thus it would never occur naturally.
\nOn the other hand, the folding on the right has nine H-H contact points, which is optimal for this string.

\n\n

Assuming that H and P elements are equally likely to occur in any position along the string, the average number of H-H contact points in an optimal folding of a random protein string of length $8$ turns out to be $850 / 2^8 = 3.3203125$.

\n\n

What is the average number of H-H contact points in an optimal folding of a random protein string of length $15$?
\nGive your answer using as many decimal places as necessary for an exact result.

", "url": "https://projecteuler.net/problem=300", "answer": "8.0540771484375"} {"id": 301, "problem": "Nim is a game played with heaps of stones, where two players take it in turn to remove any number of stones from any heap until no stones remain.\n\nWe'll consider the three-heap normal-play version of Nim, which works as follows:\n\n- At the start of the game there are three heaps of stones.\n\n- On each player's turn, the player may remove any positive number of stones from any single heap.\n\n- The first player unable to move (because no stones remain) loses.\n\nIf $(n_1,n_2,n_3)$ indicates a Nim position consisting of heaps of size $n_1$, $n_2$, and $n_3$, then there is a simple function, which you may look up or attempt to deduce for yourself, $X(n_1,n_2,n_3)$ that returns:\n\n- zero if, with perfect strategy, the player about to move will eventually lose; or\n\n- non-zero if, with perfect strategy, the player about to move will eventually win.\n\nFor example $X(1,2,3) = 0$ because, no matter what the current player does, the opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by the opponent until no stones remain; so the current player loses. To illustrate:\n\n- current player moves to $(1,2,1)$\n\n- opponent moves to $(1,0,1)$\n\n- current player moves to $(0,0,1)$\n\n- opponent moves to $(0,0,0)$, and so wins.\n\nFor how many positive integers $n \\le 2^{30}$ does $X(n,2n,3n) = 0$ ?", "raw_html": "

Nim is a game played with heaps of stones, where two players take it in turn to remove any number of stones from any heap until no stones remain.

\n\n

We'll consider the three-heap normal-play version of Nim, which works as follows:

\n\n\n

If $(n_1,n_2,n_3)$ indicates a Nim position consisting of heaps of size $n_1$, $n_2$, and $n_3$, then there is a simple function, which you may look up or attempt to deduce for yourself, $X(n_1,n_2,n_3)$ that returns:

\n\n\n\n

For example $X(1,2,3) = 0$ because, no matter what the current player does, the opponent can respond with a move that leaves two heaps of equal size, at which point every move by the current player can be mirrored by the opponent until no stones remain; so the current player loses. To illustrate:

\n\n\n\n

For how many positive integers $n \\le 2^{30}$ does $X(n,2n,3n) = 0$ ?

", "url": "https://projecteuler.net/problem=301", "answer": "2178309"} {"id": 302, "problem": "A positive integer $n$ is powerful if $p^2$ is a divisor of $n$ for every prime factor $p$ in $n$.\n\nA positive integer $n$ is a perfect power if $n$ can be expressed as a power of another positive integer.\n\nA positive integer $n$ is an Achilles number if $n$ is powerful but not a perfect power. For example, $864$ and $1800$ are Achilles numbers: $864 = 2^5 \\cdot 3^3$ and $1800 = 2^3 \\cdot 3^2 \\cdot 5^2$.\n\nWe shall call a positive integer $S$ a Strong Achilles number if both $S$ and $\\phi(S)$ are Achilles numbers.1\n\nFor example, $864$ is a Strong Achilles number: $\\phi(864) = 288 = 2^5 \\cdot 3^2$. However, $1800$ isn't a Strong Achilles number because: $\\phi(1800) = 480 = 2^5 \\cdot 3^1 \\cdot 5^1$.\n\nThere are $7$ Strong Achilles numbers below $10^4$ and $656$ below $10^8$.\n\nHow many Strong Achilles numbers are there below $10^{18}$?\n\n1 $\\phi$ denotes Euler's totient function.", "raw_html": "

\nA positive integer $n$ is powerful if $p^2$ is a divisor of $n$ for every prime factor $p$ in $n$.\n

\n

\nA positive integer $n$ is a perfect power if $n$ can be expressed as a power of another positive integer.\n

\n

\nA positive integer $n$ is an Achilles number if $n$ is powerful but not a perfect power. For example, $864$ and $1800$ are Achilles numbers: $864 = 2^5 \\cdot 3^3$ and $1800 = 2^3 \\cdot 3^2 \\cdot 5^2$.\n

\n

\nWe shall call a positive integer $S$ a Strong Achilles number if both $S$ and $\\phi(S)$ are Achilles numbers.1
\nFor example, $864$ is a Strong Achilles number: $\\phi(864) = 288 = 2^5 \\cdot 3^2$. However, $1800$ isn't a Strong Achilles number because: $\\phi(1800) = 480 = 2^5 \\cdot 3^1 \\cdot 5^1$.\n

\n

There are $7$ Strong Achilles numbers below $10^4$ and $656$ below $10^8$.\n

\n

\nHow many Strong Achilles numbers are there below $10^{18}$?\n

\n

\n1 $\\phi$ denotes Euler's totient function.\n

", "url": "https://projecteuler.net/problem=302", "answer": "1170060"} {"id": 303, "problem": "For a positive integer $n$, define $f(n)$ as the least positive multiple of $n$ that, written in base $10$, uses only digits $\\le 2$.\n\nThus $f(2)=2$, $f(3)=12$, $f(7)=21$, $f(42)=210$, $f(89)=1121222$.\n\nAlso, $\\sum \\limits_{n = 1}^{100} {\\dfrac{f(n)}{n}} = 11363107$.\n\nFind $\\sum \\limits_{n=1}^{10000} {\\dfrac{f(n)}{n}}$.", "raw_html": "

\nFor a positive integer $n$, define $f(n)$ as the least positive multiple of $n$ that, written in base $10$, uses only digits $\\le 2$.

\n

Thus $f(2)=2$, $f(3)=12$, $f(7)=21$, $f(42)=210$, $f(89)=1121222$.

\n

Also, $\\sum \\limits_{n = 1}^{100} {\\dfrac{f(n)}{n}} = 11363107$.

\n

\nFind $\\sum \\limits_{n=1}^{10000} {\\dfrac{f(n)}{n}}$.\n

", "url": "https://projecteuler.net/problem=303", "answer": "1111981904675169"} {"id": 304, "problem": "For any positive integer $n$ the function $\\operatorname{next\\_prime}(n)$ returns the smallest prime $p$ such that $p \\gt n$.\n\nThe sequence $a(n)$ is defined by:\n\n$a(1)=\\operatorname{next\\_prime}(10^{14})$ and $a(n)=\\operatorname{next\\_prime}(a(n-1))$ for $n \\gt 1$.\n\nThe Fibonacci sequence $f(n)$ is defined by:\n$f(0)=0$, $f(1)=1$ and $f(n)=f(n-1)+f(n-2)$ for $n \\gt 1$.\n\nThe sequence $b(n)$ is defined as $f(a(n))$.\n\nFind $\\sum b(n)$ for $1 \\le n \\le 100\\,000$.\nGive your answer mod $1234567891011$.", "raw_html": "

\nFor any positive integer $n$ the function $\\operatorname{next\\_prime}(n)$ returns the smallest prime $p$ such that $p \\gt n$.\n

\n

\nThe sequence $a(n)$ is defined by:
\n$a(1)=\\operatorname{next\\_prime}(10^{14})$ and $a(n)=\\operatorname{next\\_prime}(a(n-1))$ for $n \\gt 1$.\n

\n

\nThe Fibonacci sequence $f(n)$ is defined by:\n$f(0)=0$, $f(1)=1$ and $f(n)=f(n-1)+f(n-2)$ for $n \\gt 1$.\n

\n

\nThe sequence $b(n)$ is defined as $f(a(n))$.\n

\n

\nFind $\\sum b(n)$ for $1 \\le n \\le 100\\,000$. \nGive your answer mod $1234567891011$. \n

", "url": "https://projecteuler.net/problem=304", "answer": "283988410192"} {"id": 305, "problem": "Let's call $S$ the (infinite) string that is made by concatenating the consecutive positive integers (starting from $1$) written down in base $10$.\n\nThus, $S = 1234567891011121314151617181920212223242\\cdots$\n\nIt's easy to see that any number will show up an infinite number of times in $S$.\n\nLet's call $f(n)$ the starting position of the $n$th occurrence of $n$ in $S$.\n\nFor example, $f(1)=1$, $f(5)=81$, $f(12)=271$ and $f(7780)=111111365$.\n\nFind $\\sum f(3^k)$ for $1 \\le k \\le 13$.", "raw_html": "

\nLet's call $S$ the (infinite) string that is made by concatenating the consecutive positive integers (starting from $1$) written down in base $10$.
\nThus, $S = 1234567891011121314151617181920212223242\\cdots$\n

\n

\nIt's easy to see that any number will show up an infinite number of times in $S$.\n

\n

\nLet's call $f(n)$ the starting position of the $n$th occurrence of $n$ in $S$.
\nFor example, $f(1)=1$, $f(5)=81$, $f(12)=271$ and $f(7780)=111111365$.\n

\n

\nFind $\\sum f(3^k)$ for $1 \\le k \\le 13$.\n

", "url": "https://projecteuler.net/problem=305", "answer": "18174995535140"} {"id": 306, "problem": "The following game is a classic example of Combinatorial Game Theory:\n\nTwo players start with a strip of $n$ white squares and they take alternate turns.\n\nOn each turn, a player picks two contiguous white squares and paints them black.\n\nThe first player who cannot make a move loses.\n\n- $n = 1$: No valid moves, so the first player loses automatically.\n\n- $n = 2$: Only one valid move, after which the second player loses.\n\n- $n = 3$: Two valid moves, but both leave a situation where the second player loses.\n\n- $n = 4$: Three valid moves for the first player, who is able to win the game by painting the two middle squares.\n\n- $n = 5$: Four valid moves for the first player (shown below in red), but no matter what the player does, the second player (blue) wins.\n\nSo, for $1 \\le n \\le 5$, there are 3 values of $n$ for which the first player can force a win.\n\nSimilarly, for $1 \\le n \\le 50$, there are 40 values of $n$ for which the first player can force a win.\n\nFor $1 \\le n \\le 1 000 000$, how many values of $n$ are there for which the first player can force a win?", "raw_html": "

The following game is a classic example of Combinatorial Game Theory:

\n\n

Two players start with a strip of $n$ white squares and they take alternate turns.
\nOn each turn, a player picks two contiguous white squares and paints them black.
\nThe first player who cannot make a move loses.

\n\n\n\n
\"0306_pstrip.gif\"
\n\n

So, for $1 \\le n \\le 5$, there are 3 values of $n$ for which the first player can force a win.
\nSimilarly, for $1 \\le n \\le 50$, there are 40 values of $n$ for which the first player can force a win.

\n\n

For $1 \\le n \\le 1 000 000$, how many values of $n$ are there for which the first player can force a win?

", "url": "https://projecteuler.net/problem=306", "answer": "852938"} {"id": 307, "problem": "$k$ defects are randomly distributed amongst $n$ integrated-circuit chips produced by a factory (any number of defects may be found on a chip and each defect is independent of the other defects).\n\nLet $p(k, n)$ represent the probability that there is a chip with at least $3$ defects.\n\nFor instance $p(3,7) \\approx 0.0204081633$.\n\nFind $p(20\\,000, 1\\,000\\,000)$ and give your answer rounded to $10$ decimal places in the form 0.abcdefghij.", "raw_html": "

\n$k$ defects are randomly distributed amongst $n$ integrated-circuit chips produced by a factory (any number of defects may be found on a chip and each defect is independent of the other defects).\n

\n

\nLet $p(k, n)$ represent the probability that there is a chip with at least $3$ defects.
\nFor instance $p(3,7) \\approx 0.0204081633$.\n

\n

\nFind $p(20\\,000, 1\\,000\\,000)$ and give your answer rounded to $10$ decimal places in the form 0.abcdefghij.\n

", "url": "https://projecteuler.net/problem=307", "answer": "0.7311720251"} {"id": 308, "problem": "A program written in the programming language Fractran consists of a list of fractions.\n\nThe internal state of the Fractran Virtual Machine is a positive integer, which is initially set to a seed value. Each iteration of a Fractran program multiplies the state integer by the first fraction in the list which will leave it an integer.\n\nFor example, one of the Fractran programs that John Horton Conway wrote for prime-generation consists of the following 14 fractions:\n\n$$\\dfrac{17}{91}, \\dfrac{78}{85}, \\dfrac{19}{51}, \\dfrac{23}{38}, \\dfrac{29}{33}, \\dfrac{77}{29}, \\dfrac{95}{23}, \\dfrac{77}{19}, \\dfrac{1}{17}, \\dfrac{11}{13}, \\dfrac{13}{11}, \\dfrac{15}{2}, \\dfrac{1}{7}, \\dfrac{55}{1}$$\n\nStarting with the seed integer 2, successive iterations of the program produce the sequence:\n\n15, 825, 725, 1925, 2275, 425, ..., 68, 4, 30, ..., 136, 8, 60, ..., 544, 32, 240, ...\n\nThe powers of 2 that appear in this sequence are 22, 23, 25, ...\n\nIt can be shown that all the powers of 2 in this sequence have prime exponents and that all the primes appear as exponents of powers of 2, in proper order!\n\nIf someone uses the above Fractran program to solve Project Euler Problem 7 (find the 10001st prime), how many iterations would be needed until the program produces 210001st prime ?", "raw_html": "

A program written in the programming language Fractran consists of a list of fractions.

\n\n

The internal state of the Fractran Virtual Machine is a positive integer, which is initially set to a seed value. Each iteration of a Fractran program multiplies the state integer by the first fraction in the list which will leave it an integer.

\n\n

For example, one of the Fractran programs that John Horton Conway wrote for prime-generation consists of the following 14 fractions:

\n\n

$$\\dfrac{17}{91}, \\dfrac{78}{85}, \\dfrac{19}{51}, \\dfrac{23}{38}, \\dfrac{29}{33}, \\dfrac{77}{29}, \\dfrac{95}{23}, \\dfrac{77}{19}, \\dfrac{1}{17}, \\dfrac{11}{13}, \\dfrac{13}{11}, \\dfrac{15}{2}, \\dfrac{1}{7}, \\dfrac{55}{1}$$

\n\n

Starting with the seed integer 2, successive iterations of the program produce the sequence:
\n15, 825, 725, 1925, 2275, 425, ..., 68, 4, 30, ..., 136, 8, 60, ..., 544, 32, 240, ...

\n\n

The powers of 2 that appear in this sequence are 22, 23, 25, ...
\nIt can be shown that all the powers of 2 in this sequence have prime exponents and that all the primes appear as exponents of powers of 2, in proper order!

\n\n

If someone uses the above Fractran program to solve Project Euler Problem 7 (find the 10001st prime), how many iterations would be needed until the program produces 210001st prime ?

", "url": "https://projecteuler.net/problem=308", "answer": "1539669807660924"} {"id": 309, "problem": "In the classic \"Crossing Ladders\" problem, we are given the lengths $x$ and $y$ of two ladders resting on the opposite walls of a narrow, level street. We are also given the height $h$ above the street where the two ladders cross and we are asked to find the width of the street ($w$).\n\nHere, we are only concerned with instances where all four variables are positive integers.\n\nFor example, if $x = 70$, $y = 119$ and $h = 30$, we can calculate that $w = 56$.\n\nIn fact, for integer values $x$, $y$, $h$ and $0 \\lt x \\lt y \\lt 200$, there are only five triplets $(x, y, h)$ producing integer solutions for $w$:\n\n$(70, 119, 30)$, $(74, 182, 21)$, $(87, 105, 35)$, $(100, 116, 35)$ and $(119, 175, 40)$.\n\nFor integer values $x, y, h$ and $0 \\lt x \\lt y \\lt 1\\,000\\,000$, how many triplets $(x, y, h)$ produce integer solutions for $w$?", "raw_html": "

In the classic \"Crossing Ladders\" problem, we are given the lengths $x$ and $y$ of two ladders resting on the opposite walls of a narrow, level street. We are also given the height $h$ above the street where the two ladders cross and we are asked to find the width of the street ($w$).

\n\n
\"0309_ladders.gif\"
\n\n

Here, we are only concerned with instances where all four variables are positive integers.
\nFor example, if $x = 70$, $y = 119$ and $h = 30$, we can calculate that $w = 56$.

\n\n

In fact, for integer values $x$, $y$, $h$ and $0 \\lt x \\lt y \\lt 200$, there are only five triplets $(x, y, h)$ producing integer solutions for $w$:
\n$(70, 119, 30)$, $(74, 182, 21)$, $(87, 105, 35)$, $(100, 116, 35)$ and $(119, 175, 40)$.

\n\n

For integer values $x, y, h$ and $0 \\lt x \\lt y \\lt 1\\,000\\,000$, how many triplets $(x, y, h)$ produce integer solutions for $w$?

", "url": "https://projecteuler.net/problem=309", "answer": "210139"} {"id": 310, "problem": "Alice and Bob play the game Nim Square.\n\nNim Square is just like ordinary three-heap normal play Nim, but the players may only remove a square number of stones from a heap.\n\nThe number of stones in the three heaps is represented by the ordered triple $(a,b,c)$.\n\nIf $0 \\le a \\le b \\le c \\le 29$ then the number of losing positions for the next player is $1160$.\n\nFind the number of losing positions for the next player if $0 \\le a \\le b \\le c \\le 100\\,000$.", "raw_html": "

\nAlice and Bob play the game Nim Square.
\nNim Square is just like ordinary three-heap normal play Nim, but the players may only remove a square number of stones from a heap.
\nThe number of stones in the three heaps is represented by the ordered triple $(a,b,c)$.
\nIf $0 \\le a \\le b \\le c \\le 29$ then the number of losing positions for the next player is $1160$.\n

\n

\nFind the number of losing positions for the next player if $0 \\le a \\le b \\le c \\le 100\\,000$.\n

", "url": "https://projecteuler.net/problem=310", "answer": "2586528661783"} {"id": 311, "problem": "$ABCD$ is a convex, integer sided quadrilateral with $1 \\le AB \\lt BC \\lt CD \\lt AD$.\n\n$BD$ has integer length. $O$ is the midpoint of $BD$. $AO$ has integer length.\n\nWe'll call $ABCD$ a biclinic integral quadrilateral if $AO = CO \\le BO = DO$.\n\nFor example, the following quadrilateral is a biclinic integral quadrilateral:\n\n$AB = 19$, $BC = 29$, $CD = 37$, $AD = 43$, $BD = 48$ and $AO = CO = 23$.\n\nLet $B(N)$ be the number of distinct biclinic integral quadrilaterals $ABCD$ that satisfy $AB^2+BC^2+CD^2+AD^2 \\le N$.\n\nWe can verify that $B(10\\,000) = 49$ and $B(1\\,000\\,000) = 38239$.\n\nFind $B(10\\,000\\,000\\,000)$.", "raw_html": "

$ABCD$ is a convex, integer sided quadrilateral with $1 \\le AB \\lt BC \\lt CD \\lt AD$.
\n$BD$ has integer length. $O$ is the midpoint of $BD$. $AO$ has integer length.
\nWe'll call $ABCD$ a biclinic integral quadrilateral if $AO = CO \\le BO = DO$.

\n\n

For example, the following quadrilateral is a biclinic integral quadrilateral:
\n$AB = 19$, $BC = 29$, $CD = 37$, $AD = 43$, $BD = 48$ and $AO = CO = 23$.\n

\n\n
\"0311_biclinic.gif\"
\n\n

Let $B(N)$ be the number of distinct biclinic integral quadrilaterals $ABCD$ that satisfy $AB^2+BC^2+CD^2+AD^2 \\le N$.
\nWe can verify that $B(10\\,000) = 49$ and $B(1\\,000\\,000) = 38239$.\n

\n\n

Find $B(10\\,000\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=311", "answer": "2466018557"} {"id": 312, "problem": "- A Sierpiński graph of order-$1$ ($S_1$) is an equilateral triangle.\n\n- $S_{n + 1}$ is obtained from $S_n$ by positioning three copies of $S_n$ so that every pair of copies has one common corner.\n\nLet $C(n)$ be the number of cycles that pass exactly once through all the vertices of $S_n$.\n\nFor example, $C(3) = 8$ because eight such cycles can be drawn on $S_3$, as shown below:\n\nIt can also be verified that :\n\n$C(1) = C(2) = 1$\n\n$C(5) = 71328803586048$\n\n$C(10\\,000) \\bmod 10^8 = 37652224$\n\n$C(10\\,000) \\bmod 13^8 = 617720485$\n\nFind $C(C(C(10\\,000))) \\bmod 13^8$.", "raw_html": "

- A Sierpiński graph of order-$1$ ($S_1$) is an equilateral triangle.
\n- $S_{n + 1}$ is obtained from $S_n$ by positioning three copies of $S_n$ so that every pair of copies has one common corner.\n

\n\n
\"0312_sierpinskyAt.gif\"
\n\n

Let $C(n)$ be the number of cycles that pass exactly once through all the vertices of $S_n$.
\nFor example, $C(3) = 8$ because eight such cycles can be drawn on $S_3$, as shown below:\n

\n\n
\"0312_sierpinsky8t.gif\"
\n\n

It can also be verified that :
\n$C(1) = C(2) = 1$
\n$C(5) = 71328803586048$
\n$C(10\\,000) \\bmod 10^8 = 37652224$
\n$C(10\\,000) \\bmod 13^8 = 617720485$

\n\n

Find $C(C(C(10\\,000))) \\bmod 13^8$.\n

", "url": "https://projecteuler.net/problem=312", "answer": "324681947"} {"id": 313, "problem": "In a sliding game a counter may slide horizontally or vertically into an empty space. The objective of the game is to move the red counter from the top left corner of a grid to the bottom right corner; the space always starts in the bottom right corner. For example, the following sequence of pictures show how the game can be completed in five moves on a $2$ by $2$ grid.\n\nLet $S(m,n)$ represent the minimum number of moves to complete the game on an $m$ by $n$ grid. For example, it can be verified that $S(5,4) = 25$.\n\nThere are exactly $5482$ grids for which $S(m,n) = p^2$, where $p \\lt 100$ is prime.\n\nHow many grids does $S(m,n) = p^2$, where $p \\lt 10^6$ is prime?", "raw_html": "

In a sliding game a counter may slide horizontally or vertically into an empty space. The objective of the game is to move the red counter from the top left corner of a grid to the bottom right corner; the space always starts in the bottom right corner. For example, the following sequence of pictures show how the game can be completed in five moves on a $2$ by $2$ grid.

\n\n
\"0313_sliding_game_1.gif\"
\n\n

Let $S(m,n)$ represent the minimum number of moves to complete the game on an $m$ by $n$ grid. For example, it can be verified that $S(5,4) = 25$.

\n\n
\"0313_sliding_game_2.gif\"
\n\n

There are exactly $5482$ grids for which $S(m,n) = p^2$, where $p \\lt 100$ is prime.

\n\n

How many grids does $S(m,n) = p^2$, where $p \\lt 10^6$ is prime?

", "url": "https://projecteuler.net/problem=313", "answer": "2057774861813004"} {"id": 314, "problem": "The moon has been opened up, and land can be obtained for free, but there is a catch. You have to build a wall around the land that you stake out, and building a wall on the moon is expensive. Every country has been allotted a $\\pu{500 m}$ by $\\pu{500 m}$ square area, but they will possess only that area which they wall in. $251001$ posts have been placed in a rectangular grid with $1$ meter spacing. The wall must be a closed series of straight lines, each line running from post to post.\n\nThe bigger countries of course have built a $\\pu{2000 m}$ wall enclosing the entire $\\pu{250 000 m^2}$ area. The Duchy of Grand Fenwick, has a tighter budget, and has asked you (their Royal Programmer) to compute what shape would get best maximum enclosed-area/wall-length ratio.\n\nYou have done some preliminary calculations on a sheet of paper.\nFor a $2000$ meter wall enclosing the $\\pu{250 000 m^2}$ area the\nenclosed-area/wall-length ratio is $125$.\n\nAlthough not allowed , but to get an idea if this is anything better: if you place a circle inside the square area touching the four sides the area will be equal to $\\pi \\times \\pu{250^2 m^2}$ and the perimeter will be $\\pi \\times \\pu{500 m}$, so the enclosed-area/wall-length ratio will also be $125$.\n\nHowever, if you cut off from the square four triangles with sides $\\pu{75 m}$, $\\pu{75 m}$ and $75\\pu{\\sqrt 2 m}$ the total area becomes $\\pu{238750 m^2}$ and the perimeter becomes $1400+300\\pu{\\sqrt 2 m}$. So this gives an enclosed-area/wall-length ratio of $130.87$, which is significantly better.\n\nFind the maximum enclosed-area/wall-length ratio.\n\nGive your answer rounded to $8$ places behind the decimal point in the form abc.defghijk.", "raw_html": "

\nThe moon has been opened up, and land can be obtained for free, but there is a catch. You have to build a wall around the land that you stake out, and building a wall on the moon is expensive. Every country has been allotted a $\\pu{500 m}$ by $\\pu{500 m}$ square area, but they will possess only that area which they wall in. $251001$ posts have been placed in a rectangular grid with $1$ meter spacing. The wall must be a closed series of straight lines, each line running from post to post.\n

\n

\nThe bigger countries of course have built a $\\pu{2000 m}$ wall enclosing the entire $\\pu{250 000 m^2}$ area. The Duchy of Grand Fenwick, has a tighter budget, and has asked you (their Royal Programmer) to compute what shape would get best maximum enclosed-area/wall-length ratio.\n

\n

\nYou have done some preliminary calculations on a sheet of paper.\nFor a $2000$ meter wall enclosing the $\\pu{250 000 m^2}$ area the\nenclosed-area/wall-length ratio is $125$.
\nAlthough not allowed , but to get an idea if this is anything better: if you place a circle inside the square area touching the four sides the area will be equal to $\\pi \\times \\pu{250^2 m^2}$ and the perimeter will be $\\pi \\times \\pu{500 m}$, so the enclosed-area/wall-length ratio will also be $125$.\n

\n

\nHowever, if you cut off from the square four triangles with sides $\\pu{75 m}$, $\\pu{75 m}$ and $75\\pu{\\sqrt 2 m}$ the total area becomes $\\pu{238750 m^2}$ and the perimeter becomes $1400+300\\pu{\\sqrt 2 m}$. So this gives an enclosed-area/wall-length ratio of $130.87$, which is significantly better.\n

\n
\"0314_landgrab.gif\"
\n

\nFind the maximum enclosed-area/wall-length ratio.
\nGive your answer rounded to $8$ places behind the decimal point in the form abc.defghijk.\n

", "url": "https://projecteuler.net/problem=314", "answer": "132.52756426"} {"id": 315, "problem": "Sam and Max are asked to transform two digital clocks into two \"digital root\" clocks.\n\nA digital root clock is a digital clock that calculates digital roots step by step.\n\nWhen a clock is fed a number, it will show it and then it will start the calculation, showing all the intermediate values until it gets to the result.\n\nFor example, if the clock is fed the number 137, it will show: \"137\" → \"11\" → \"2\" and then it will go black, waiting for the next number.\n\nEvery digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right).\n\nNumber \"1\" is made of vertical top-right and bottom-right, number \"4\" is made by middle horizontal and vertical top-left, top-right and bottom-right. Number \"8\" lights them all.\n\nThe clocks consume energy only when segments are turned on/off.\n\nTo turn on a \"2\" will cost 5 transitions, while a \"7\" will cost only 4 transitions.\n\nSam and Max built two different clocks.\n\nSam's clock is fed e.g. number 137: the clock shows \"137\", then the panel is turned off, then the next number (\"11\") is turned on, then the panel is turned off again and finally the last number (\"2\") is turned on and, after some time, off.\n\nFor the example, with number 137, Sam's clock requires:\n\n| \"137\" | : | (2 + 5 + 4) × 2 = 22 transitions (\"137\" on/off). |\n| \"11\" | : | (2 + 2) × 2 = 8 transitions (\"11\" on/off). |\n| \"2\" | : | (5) × 2 = 10 transitions (\"2\" on/off). |\n\nFor a grand total of 40 transitions.\n\nMax's clock works differently. Instead of turning off the whole panel, it is smart enough to turn off only those segments that won't be needed for the next number.\n\nFor number 137, Max's clock requires:\n\n| \"137\" | : | 2 + 5 + 4 = 11 transitions (\"137\" on)\n7 transitions (to turn off the segments that are not needed for number \"11\"). |\n| \"11\" | : | 0 transitions (number \"11\" is already turned on correctly)\n3 transitions (to turn off the first \"1\" and the bottom part of the second \"1\";\nthe top part is common with number \"2\"). |\n| \"2\" | : | 4 transitions (to turn on the remaining segments in order to get a \"2\")\n5 transitions (to turn off number \"2\"). |\n\nFor a grand total of 30 transitions.\n\nOf course, Max's clock consumes less power than Sam's one.\n\nThe two clocks are fed all the prime numbers between A = 107 and B = 2×107.\n\nFind the difference between the total number of transitions needed by Sam's clock and that needed by Max's one.", "raw_html": "

\"0315_clocks.gif\"
\n\n

Sam and Max are asked to transform two digital clocks into two \"digital root\" clocks.
\nA digital root clock is a digital clock that calculates digital roots step by step.

\n\n

When a clock is fed a number, it will show it and then it will start the calculation, showing all the intermediate values until it gets to the result.
\nFor example, if the clock is fed the number 137, it will show: \"137\" → \"11\" → \"2\" and then it will go black, waiting for the next number.

\n\n

Every digital number consists of some light segments: three horizontal (top, middle, bottom) and four vertical (top-left, top-right, bottom-left, bottom-right).
\nNumber \"1\" is made of vertical top-right and bottom-right, number \"4\" is made by middle horizontal and vertical top-left, top-right and bottom-right. Number \"8\" lights them all.

\n\n

The clocks consume energy only when segments are turned on/off.
\nTo turn on a \"2\" will cost 5 transitions, while a \"7\" will cost only 4 transitions.

\n\n

Sam and Max built two different clocks.

\n\n

Sam's clock is fed e.g. number 137: the clock shows \"137\", then the panel is turned off, then the next number (\"11\") is turned on, then the panel is turned off again and finally the last number (\"2\") is turned on and, after some time, off.
\nFor the example, with number 137, Sam's clock requires:

\n\n\n\n\n\n\n\n\n
\"137\":(2 + 5 + 4) × 2 = 22 transitions (\"137\" on/off).
\"11\":(2 + 2) × 2 = 8 transitions (\"11\" on/off).
\"2\":(5) × 2 = 10 transitions (\"2\" on/off).
\nFor a grand total of 40 transitions.\n\n

Max's clock works differently. Instead of turning off the whole panel, it is smart enough to turn off only those segments that won't be needed for the next number.
\nFor number 137, Max's clock requires:

\n\n\n\n\n\n\n\n\n
\"137\"

:

2 + 5 + 4 = 11 transitions (\"137\" on)
\n7 transitions (to turn off the segments that are not needed for number \"11\").
\"11\"


:


0 transitions (number \"11\" is already turned on correctly)
\n3 transitions (to turn off the first \"1\" and the bottom part of the second \"1\";
\nthe top part is common with number \"2\").
\"2\"

:

4 transitions (to turn on the remaining segments in order to get a \"2\")
\n5 transitions (to turn off number \"2\").
\nFor a grand total of 30 transitions.\n\n

Of course, Max's clock consumes less power than Sam's one.
\nThe two clocks are fed all the prime numbers between A = 107 and B = 2×107.
\nFind the difference between the total number of transitions needed by Sam's clock and that needed by Max's one.

", "url": "https://projecteuler.net/problem=315", "answer": "13625242"} {"id": 316, "problem": "Let $p = p_1 p_2 p_3 \\cdots$ be an infinite sequence of random digits, selected from $\\{0,1,2,3,4,5,6,7,8,9\\}$ with equal probability.\n\nIt can be seen that $p$ corresponds to the real number $0.p_1 p_2 p_3 \\cdots$\n\nIt can also be seen that choosing a random real number from the interval $[0,1)$ is equivalent to choosing an infinite sequence of random digits selected from $\\{0,1,2,3,4,5,6,7,8,9\\}$ with equal probability.\n\nFor any positive integer $n$ with $d$ decimal digits, let $k$ be the smallest index such that $p_k, p_{k + 1}, \\dots, p_{k + d - 1}$ are the decimal digits of $n$, in the same order.\n\nAlso, let $g(n)$ be the expected value of $k$; it can be proven that $g(n)$ is always finite and, interestingly, always an integer number.\n\nFor example, if $n = 535$, then\n\nfor $p = 31415926\\mathbf{535}897\\cdots$, we get $k = 9$\n\nfor $p = 35528714365004956000049084876408468\\mathbf{535}4\\cdots$, we get $k = 36$\n\netc and we find that $g(535) = 1008$.\n\nGiven that $\\displaystyle\\sum_{n = 2}^{999} g \\left(\\left\\lfloor\\frac{10^6} n \\right\\rfloor\\right) = 27280188$, find $\\displaystyle\\sum_{n = 2}^{999999} g \\left(\\left\\lfloor\\frac{10^{16}} n \\right\\rfloor\\right)$.\n\nNote: $\\lfloor x \\rfloor$ represents the floor function.", "raw_html": "

Let $p = p_1 p_2 p_3 \\cdots$ be an infinite sequence of random digits, selected from $\\{0,1,2,3,4,5,6,7,8,9\\}$ with equal probability.
\nIt can be seen that $p$ corresponds to the real number $0.p_1 p_2 p_3 \\cdots$
\nIt can also be seen that choosing a random real number from the interval $[0,1)$ is equivalent to choosing an infinite sequence of random digits selected from $\\{0,1,2,3,4,5,6,7,8,9\\}$ with equal probability.

\n\n

For any positive integer $n$ with $d$ decimal digits, let $k$ be the smallest index such that $p_k, p_{k + 1}, \\dots, p_{k + d - 1}$ are the decimal digits of $n$, in the same order.
\nAlso, let $g(n)$ be the expected value of $k$; it can be proven that $g(n)$ is always finite and, interestingly, always an integer number.

\n\n

For example, if $n = 535$, then
\nfor $p = 31415926\\mathbf{535}897\\cdots$, we get $k = 9$
\nfor $p = 35528714365004956000049084876408468\\mathbf{535}4\\cdots$, we get $k = 36$
\netc and we find that $g(535) = 1008$.

\n\n

Given that $\\displaystyle\\sum_{n = 2}^{999} g \\left(\\left\\lfloor\\frac{10^6} n \\right\\rfloor\\right) = 27280188$, find $\\displaystyle\\sum_{n = 2}^{999999} g \\left(\\left\\lfloor\\frac{10^{16}} n \\right\\rfloor\\right)$.

\n\nNote: $\\lfloor x \\rfloor$ represents the floor function.", "url": "https://projecteuler.net/problem=316", "answer": "542934735751917735"} {"id": 317, "problem": "A firecracker explodes at a height of $\\pu{100 m}$ above level ground. It breaks into a large number of very small fragments, which move in every direction; all of them have the same initial velocity of $\\pu{20 m/s}$.\n\nWe assume that the fragments move without air resistance, in a uniform gravitational field with $g=\\pu{9.81 m/s^2}$.\n\nFind the volume (in $\\pu{m^3}$) of the region through which the fragments move before reaching the ground.\nGive your answer rounded to four decimal places.", "raw_html": "

\nA firecracker explodes at a height of $\\pu{100 m}$ above level ground. It breaks into a large number of very small fragments, which move in every direction; all of them have the same initial velocity of $\\pu{20 m/s}$.\n

\n

\nWe assume that the fragments move without air resistance, in a uniform gravitational field with $g=\\pu{9.81 m/s^2}$.\n

\n

\nFind the volume (in $\\pu{m^3}$) of the region through which the fragments move before reaching the ground. \nGive your answer rounded to four decimal places.\n

", "url": "https://projecteuler.net/problem=317", "answer": "1856532.8455"} {"id": 318, "problem": "Consider the real number $\\sqrt 2 + \\sqrt 3$.\n\nWhen we calculate the even powers of $\\sqrt 2 + \\sqrt 3$\nwe get:\n\n$(\\sqrt 2 + \\sqrt 3)^2 = 9.898979485566356 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^4 = 97.98979485566356 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^6 = 969.998969071069263 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^8 = 9601.99989585502907 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^{10} = 95049.999989479221 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^{12} = 940897.9999989371855 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^{14} = 9313929.99999989263 \\cdots $\n\n$(\\sqrt 2 + \\sqrt 3)^{16} = 92198401.99999998915 \\cdots $\n\nIt looks as if the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing.\n\nIn fact it can be proven that the fractional part of $(\\sqrt 2 + \\sqrt 3)^{2 n}$ approaches $1$ for large $n$.\n\nConsider all real numbers of the form $\\sqrt p + \\sqrt q$ with $p$ and $q$ positive integers and $p < q$, such that the fractional part\nof $(\\sqrt p + \\sqrt q)^{ 2 n}$ approaches $1$ for large $n$.\n\nLet $C(p,q,n)$ be the number of consecutive nines at the beginning of the fractional part of $(\\sqrt p + \\sqrt q)^{ 2 n}$.\n\nLet $N(p,q)$ be the minimal value of $n$ such that $C(p,q,n) \\ge 2011$.\n\nFind $\\displaystyle \\sum N(p,q) \\,\\, \\text{ for } p+q \\le 2011$.", "raw_html": "

\nConsider the real number $\\sqrt 2 + \\sqrt 3$.
\nWhen we calculate the even powers of $\\sqrt 2 + \\sqrt 3$\nwe get:
\n$(\\sqrt 2 + \\sqrt 3)^2 = 9.898979485566356 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^4 = 97.98979485566356 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^6 = 969.998969071069263 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^8 = 9601.99989585502907 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^{10} = 95049.999989479221 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^{12} = 940897.9999989371855 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^{14} = 9313929.99999989263 \\cdots $
\n$(\\sqrt 2 + \\sqrt 3)^{16} = 92198401.99999998915 \\cdots $

\n

\nIt looks as if the number of consecutive nines at the beginning of the fractional part of these powers is non-decreasing.
\nIn fact it can be proven that the fractional part of $(\\sqrt 2 + \\sqrt 3)^{2 n}$ approaches $1$ for large $n$.\n

\n

\nConsider all real numbers of the form $\\sqrt p + \\sqrt q$ with $p$ and $q$ positive integers and $p < q$, such that the fractional part \nof $(\\sqrt p + \\sqrt q)^{ 2 n}$ approaches $1$ for large $n$.\n

\n

\nLet $C(p,q,n)$ be the number of consecutive nines at the beginning of the fractional part of $(\\sqrt p + \\sqrt q)^{ 2 n}$.\n

\n

\nLet $N(p,q)$ be the minimal value of $n$ such that $C(p,q,n) \\ge 2011$.\n

\n

\nFind $\\displaystyle \\sum N(p,q) \\,\\, \\text{ for } p+q \\le 2011$.\n

", "url": "https://projecteuler.net/problem=318", "answer": "709313889"} {"id": 319, "problem": "Let $x_1, x_2, \\dots, x_n$ be a sequence of length $n$ such that:\n\n- $x_1 = 2$\n\n- for all $1 \\lt i \\le n$: $x_{i - 1} \\lt x_i$\n\n- for all $i$ and $j$ with $1 \\le i, j \\le n$: $(x_i)^j \\lt (x_j + 1)^i$.\n\nThere are only five such sequences of length $2$, namely:\n$\\{2,4\\}$, $\\{2,5\\}$, $\\{2,6\\}$, $\\{2,7\\}$ and $\\{2,8\\}$.\n\nThere are $293$ such sequences of length $5$; three examples are given below:\n\n$\\{2,5,11,25,55\\}$, $\\{2,6,14,36,88\\}$, $\\{2,8,22,64,181\\}$.\n\nLet $t(n)$ denote the number of such sequences of length $n$.\n\nYou are given that $t(10) = 86195$ and $t(20) = 5227991891$.\n\nFind $t(10^{10})$ and give your answer modulo $10^9$.", "raw_html": "

\nLet $x_1, x_2, \\dots, x_n$ be a sequence of length $n$ such that:\n

\nThere are only five such sequences of length $2$, namely:\n$\\{2,4\\}$, $\\{2,5\\}$, $\\{2,6\\}$, $\\{2,7\\}$ and $\\{2,8\\}$.
\nThere are $293$ such sequences of length $5$; three examples are given below:
\n$\\{2,5,11,25,55\\}$, $\\{2,6,14,36,88\\}$, $\\{2,8,22,64,181\\}$.\n

\n

\nLet $t(n)$ denote the number of such sequences of length $n$.
\nYou are given that $t(10) = 86195$ and $t(20) = 5227991891$.\n

\n

\nFind $t(10^{10})$ and give your answer modulo $10^9$.\n

", "url": "https://projecteuler.net/problem=319", "answer": "268457129"} {"id": 320, "problem": "Let $N(i)$ be the smallest integer $n$ such that $n!$ is divisible by $(i!)^{1234567890}$\n\nLet $S(u)=\\sum N(i)$ for $10 \\le i \\le u$.\n\n$S(1000)=614538266565663$.\n\nFind $S(1\\,000\\,000) \\bmod 10^{18}$.", "raw_html": "

\nLet $N(i)$ be the smallest integer $n$ such that $n!$ is divisible by $(i!)^{1234567890}$

\n

\nLet $S(u)=\\sum N(i)$ for $10 \\le i \\le u$.\n

\n

\n$S(1000)=614538266565663$.\n

\n

\nFind $S(1\\,000\\,000) \\bmod 10^{18}$.\n

", "url": "https://projecteuler.net/problem=320", "answer": "278157919195482643"} {"id": 321, "problem": "A horizontal row comprising of $2n + 1$ squares has $n$ red counters placed at one end and $n$ blue counters at the other end, being separated by a single empty square in the centre. For example, when $n = 3$.\n\nA counter can move from one square to the next (slide) or can jump over another counter (hop) as long as the square next to that counter is unoccupied.\n\nLet $M(n)$ represent the minimum number of moves/actions to completely reverse the positions of the coloured counters; that is, move all the red counters to the right and all the blue counters to the left.\n\nIt can be verified $M(3) = 15$, which also happens to be a triangle number.\n\nIf we create a sequence based on the values of $n$ for which $M(n)$ is a triangle number then the first five terms would be:\n\n$1$, $3$, $10$, $22$, and $63$, and their sum would be $99$.\n\nFind the sum of the first forty terms of this sequence.", "raw_html": "

A horizontal row comprising of $2n + 1$ squares has $n$ red counters placed at one end and $n$ blue counters at the other end, being separated by a single empty square in the centre. For example, when $n = 3$.

\n\n

\"0321_swapping_counters_1.gif\"
\n\n

A counter can move from one square to the next (slide) or can jump over another counter (hop) as long as the square next to that counter is unoccupied.

\n\n

\"0321_swapping_counters_2.gif\"
\n\n

Let $M(n)$ represent the minimum number of moves/actions to completely reverse the positions of the coloured counters; that is, move all the red counters to the right and all the blue counters to the left.

\n

It can be verified $M(3) = 15$, which also happens to be a triangle number.

\n\n

If we create a sequence based on the values of $n$ for which $M(n)$ is a triangle number then the first five terms would be:\n
$1$, $3$, $10$, $22$, and $63$, and their sum would be $99$.

\n\n

Find the sum of the first forty terms of this sequence.

", "url": "https://projecteuler.net/problem=321", "answer": "2470433131948040"} {"id": 322, "problem": "Let $T(m, n)$ be the number of the binomial coefficients $^iC_n$ that are divisible by $10$ for $n \\le i \\lt m$ ($i$, $m$ and $n$ are positive integers).\n\nYou are given that $T(10^9, 10^7-10) = 989697000$.\n\nFind $T(10^{18}, 10^{12}-10)$.", "raw_html": "

\nLet $T(m, n)$ be the number of the binomial coefficients $^iC_n$ that are divisible by $10$ for $n \\le i \\lt m$ ($i$, $m$ and $n$ are positive integers).
\nYou are given that $T(10^9, 10^7-10) = 989697000$.\n

\n

\nFind $T(10^{18}, 10^{12}-10)$.\n

", "url": "https://projecteuler.net/problem=322", "answer": "999998760323313995"} {"id": 323, "problem": "Let $y_0, y_1, y_2, \\dots$ be a sequence of random unsigned $32$-bit integers\n\n(i.e. $0 \\le y_i \\lt 2^{32}$, every value equally likely).\n\nFor the sequence $x_i$ the following recursion is given:\n\n- $x_0 = 0$ and\n\n- $x_i = x_{i - 1} \\boldsymbol \\mid y_{i - 1}$, for $i \\gt 0$. ($\\boldsymbol \\mid$ is the bitwise-OR operator).\n\nIt can be seen that eventually there will be an index $N$ such that $x_i = 2^{32} - 1$ (a bit-pattern of all ones) for all $i \\ge N$.\n\nFind the expected value of $N$.\n\nGive your answer rounded to $10$ digits after the decimal point.", "raw_html": "

Let $y_0, y_1, y_2, \\dots$ be a sequence of random unsigned $32$-bit integers
\n(i.e. $0 \\le y_i \\lt 2^{32}$, every value equally likely).

\n

For the sequence $x_i$ the following recursion is given:

It can be seen that eventually there will be an index $N$ such that $x_i = 2^{32} - 1$ (a bit-pattern of all ones) for all $i \\ge N$.

\n\n

Find the expected value of $N$.
\nGive your answer rounded to $10$ digits after the decimal point.

", "url": "https://projecteuler.net/problem=323", "answer": "6.3551758451"} {"id": 324, "problem": "Let $f(n)$ represent the number of ways one can fill a $3 \\times 3 \\times n$ tower with blocks of $2 \\times 1 \\times 1$.\nYou're allowed to rotate the blocks in any way you like; however, rotations, reflections etc of the tower itself are counted as distinct.\n\nFor example (with $q = 100000007$):\n$f(2) = 229$,\n$f(4) = 117805$,\n$f(10) \\bmod q = 96149360$,\n$f(10^3) \\bmod q = 24806056$,\n$f(10^6) \\bmod q = 30808124$.\n\nFind $f(10^{10000}) \\bmod 100000007$.", "raw_html": "

Let $f(n)$ represent the number of ways one can fill a $3 \\times 3 \\times n$ tower with blocks of $2 \\times 1 \\times 1$.
You're allowed to rotate the blocks in any way you like; however, rotations, reflections etc of the tower itself are counted as distinct.

\n

For example (with $q = 100000007$):
$f(2) = 229$,
$f(4) = 117805$,
$f(10) \\bmod q = 96149360$,
$f(10^3) \\bmod q = 24806056$,
$f(10^6) \\bmod q = 30808124$.

\n\n

Find $f(10^{10000}) \\bmod 100000007$.

", "url": "https://projecteuler.net/problem=324", "answer": "96972774"} {"id": 325, "problem": "A game is played with two piles of stones and two players.\n\nOn each player's turn, the player may remove a number of stones from the larger pile.\n\nThe number of stones removed must be a positive multiple of the number of stones in the smaller pile.\n\nE.g. Let the ordered pair $(6,14)$ describe a configuration with $6$ stones in the smaller pile and $14$ stones in the larger pile, then the first player can remove $6$ or $12$ stones from the larger pile.\n\nThe player taking all the stones from a pile wins the game.\n\nA winning configuration is one where the first player can force a win. For example, $(1,5)$, $(2,6)$, and $(3,12)$ are winning configurations because the first player can immediately remove all stones in the second pile.\n\nA losing configuration is one where the second player can force a win, no matter what the first player does. For example, $(2,3)$ and $(3,4)$ are losing configurations: any legal move leaves a winning configuration for the second player.\n\nDefine $S(N)$ as the sum of $(x_i + y_i)$ for all losing configurations $(x_i, y_i), 0 \\lt x_i \\lt y_i \\le N$.\n\nWe can verify that $S(10) = 211$ and $S(10^4) = 230312207313$.\n\nFind $S(10^{16}) \\bmod 7^{10}$.", "raw_html": "

A game is played with two piles of stones and two players.
\nOn each player's turn, the player may remove a number of stones from the larger pile.
\nThe number of stones removed must be a positive multiple of the number of stones in the smaller pile.

\n\n

E.g. Let the ordered pair $(6,14)$ describe a configuration with $6$ stones in the smaller pile and $14$ stones in the larger pile, then the first player can remove $6$ or $12$ stones from the larger pile.

\n\n

The player taking all the stones from a pile wins the game.

\n\n

A winning configuration is one where the first player can force a win. For example, $(1,5)$, $(2,6)$, and $(3,12)$ are winning configurations because the first player can immediately remove all stones in the second pile.

\n\n

A losing configuration is one where the second player can force a win, no matter what the first player does. For example, $(2,3)$ and $(3,4)$ are losing configurations: any legal move leaves a winning configuration for the second player.

\n\n

Define $S(N)$ as the sum of $(x_i + y_i)$ for all losing configurations $(x_i, y_i), 0 \\lt x_i \\lt y_i \\le N$.
\nWe can verify that $S(10) = 211$ and $S(10^4) = 230312207313$.

\n\n

Find $S(10^{16}) \\bmod 7^{10}$.

", "url": "https://projecteuler.net/problem=325", "answer": "54672965"} {"id": 326, "problem": "Let $a_n$ be a sequence recursively defined by:$\\quad a_1=1,\\quad\\displaystyle a_n=\\biggl(\\sum_{k=1}^{n-1}k\\cdot a_k\\biggr)\\bmod n$.\n\nSo the first $10$ elements of $a_n$ are: $1,1,0,3,0,3,5,4,1,9$.\n\nLet $f(N, M)$ represent the number of pairs $(p, q)$ such that:\n\n$$\n\\def\\htmltext#1{\\style{font-family:inherit;}{\\text{#1}}}\n1\\le p\\le q\\le N \\quad\\htmltext{and}\\quad\\biggl(\\sum_{i=p}^qa_i\\biggr)\\bmod M=0\n$$\n\nIt can be seen that $f(10,10)=4$ with the pairs $(3,3)$, $(5,5)$, $(7,9)$ and $(9,10)$.\n\nYou are also given that $f(10^4,10^3)=97158$.\n\nFind $f(10^{12},10^6)$.", "raw_html": "

\nLet $a_n$ be a sequence recursively defined by:$\\quad a_1=1,\\quad\\displaystyle a_n=\\biggl(\\sum_{k=1}^{n-1}k\\cdot a_k\\biggr)\\bmod n$.\n

\n

\nSo the first $10$ elements of $a_n$ are: $1,1,0,3,0,3,5,4,1,9$.\n

\n

Let $f(N, M)$ represent the number of pairs $(p, q)$ such that:

\n

\n$$\n\\def\\htmltext#1{\\style{font-family:inherit;}{\\text{#1}}}\n1\\le p\\le q\\le N \\quad\\htmltext{and}\\quad\\biggl(\\sum_{i=p}^qa_i\\biggr)\\bmod M=0\n$$\n

\n

\nIt can be seen that $f(10,10)=4$ with the pairs $(3,3)$, $(5,5)$, $(7,9)$ and $(9,10)$.\n

\n

\nYou are also given that $f(10^4,10^3)=97158$.

\n

\nFind $f(10^{12},10^6)$.\n

", "url": "https://projecteuler.net/problem=326", "answer": "1966666166408794329"} {"id": 327, "problem": "A series of three rooms are connected to each other by automatic doors.\n\nEach door is operated by a security card. Once you enter a room the door automatically closes and that security card cannot be used again. A machine at the start will dispense an unlimited number of cards, but each room (including the starting room) contains scanners and if they detect that you are holding more than three security cards or if they detect an unattended security card on the floor, then all the doors will become permanently locked. However, each room contains a box where you may safely store any number of security cards for use at a later stage.\n\nIf you simply tried to travel through the rooms one at a time then as you entered room 3 you would have used all three cards and would be trapped in that room forever!\n\nHowever, if you make use of the storage boxes, then escape is possible. For example, you could enter room 1 using your first card, place one card in the storage box, and use your third card to exit the room back to the start. Then after collecting three more cards from the dispensing machine you could use one to enter room 1 and collect the card you placed in the box a moment ago. You now have three cards again and will be able to travel through the remaining three doors. This method allows you to travel through all three rooms using six security cards in total.\n\nIt is possible to travel through six rooms using a total of $123$ security cards while carrying a maximum of $3$ cards.\n\nLet $C$ be the maximum number of cards which can be carried at any time.\n\nLet $R$ be the number of rooms to travel through.\n\nLet $M(C,R)$ be the minimum number of cards required from the dispensing machine to travel through $R$ rooms carrying up to a maximum of $C$ cards at any time.\n\nFor example, $M(3,6)=123$ and $M(4,6)=23$.\nAnd, $\\sum M(C, 6) = 146$ for $3 \\le C \\le 4$.\n\nYou are given that $\\sum M(C,10)=10382$ for $3 \\le C \\le 10$.\n\nFind $\\sum M(C,30)$ for $3 \\le C \\le 40$.", "raw_html": "

A series of three rooms are connected to each other by automatic doors.

\n\n
\"0327_rooms_of_doom.gif\"
\n\n

Each door is operated by a security card. Once you enter a room the door automatically closes and that security card cannot be used again. A machine at the start will dispense an unlimited number of cards, but each room (including the starting room) contains scanners and if they detect that you are holding more than three security cards or if they detect an unattended security card on the floor, then all the doors will become permanently locked. However, each room contains a box where you may safely store any number of security cards for use at a later stage.

\n\n

If you simply tried to travel through the rooms one at a time then as you entered room 3 you would have used all three cards and would be trapped in that room forever!

\n\n

However, if you make use of the storage boxes, then escape is possible. For example, you could enter room 1 using your first card, place one card in the storage box, and use your third card to exit the room back to the start. Then after collecting three more cards from the dispensing machine you could use one to enter room 1 and collect the card you placed in the box a moment ago. You now have three cards again and will be able to travel through the remaining three doors. This method allows you to travel through all three rooms using six security cards in total.

\n\n

It is possible to travel through six rooms using a total of $123$ security cards while carrying a maximum of $3$ cards.

\n\n

Let $C$ be the maximum number of cards which can be carried at any time.

\n

Let $R$ be the number of rooms to travel through.

\n

Let $M(C,R)$ be the minimum number of cards required from the dispensing machine to travel through $R$ rooms carrying up to a maximum of $C$ cards at any time.

\n\n

For example, $M(3,6)=123$ and $M(4,6)=23$.
And, $\\sum M(C, 6) = 146$ for $3 \\le C \\le 4$.

\n\n\n

You are given that $\\sum M(C,10)=10382$ for $3 \\le C \\le 10$.

\n\n

Find $\\sum M(C,30)$ for $3 \\le C \\le 40$.

", "url": "https://projecteuler.net/problem=327", "answer": "34315549139516"} {"id": 328, "problem": "We are trying to find a hidden number selected from the set of integers $\\{1, 2, \\dots, n\\}$ by asking questions.\nEach number (question) we ask, has a cost equal to the number asked and we get one of three possible answers:\n\n- \"Your guess is lower than the hidden number\", or\n\n- \"Yes, that's it!\", or\n\n- \"Your guess is higher than the hidden number\".\n\nGiven the value of $n$, an optimal strategy minimizes the total cost (i.e. the sum of all the questions asked) for the worst possible case. E.g.\n\nIf $n=3$, the best we can do is obviously to ask the number \"2\". The answer will immediately lead us to find the hidden number (at a total cost $= 2$).\n\nIf $n=8$, we might decide to use a \"binary search\" type of strategy: Our first question would be \"$\\mathbf 4$\" and if the hidden number is higher than $4$ we will need one or two additional questions.\n\nLet our second question be \"$\\mathbf 6$\". If the hidden number is still higher than $6$, we will need a third question in order to discriminate between $7$ and $8$.\n\nThus, our third question will be \"$\\mathbf 7$\" and the total cost for this worst-case scenario will be $4+6+7={\\color{red}\\mathbf{17}}$.\n\nWe can improve considerably the worst-case cost for $n=8$, by asking \"$\\mathbf 5$\" as our first question.\n\nIf we are told that the hidden number is higher than $5$, our second question will be \"$\\mathbf 7$\", then we'll know for certain what the hidden number is (for a total cost of $5+7={\\color{blue}\\mathbf{12}}$).\n\nIf we are told that the hidden number is lower than $5$, our second question will be \"$\\mathbf 3$\" and if the hidden number is lower than $3$ our third question will be \"$\\mathbf 1$\", giving a total cost of $5+3+1={\\color{blue}\\mathbf 9}$.\n\nSince ${\\color{blue}\\mathbf{12}} \\gt {\\color{blue}\\mathbf 9}$, the worst-case cost for this strategy is ${\\color{red}\\mathbf{12}}$. That's better than what we achieved previously with the \"binary search\" strategy; it is also better than or equal to any other strategy.\n\nSo, in fact, we have just described an optimal strategy for $n=8$.\n\nLet $C(n)$ be the worst-case cost achieved by an optimal strategy for $n$, as described above.\n\nThus $C(1) = 0$, $C(2) = 1$, $C(3) = 2$ and $C(8) = 12$.\n\nSimilarly, $C(100) = 400$ and $\\sum \\limits_{n = 1}^{100} C(n) = 17575$.\n\nFind $\\sum \\limits_{n = 1}^{200000} C(n)$.", "raw_html": "

We are trying to find a hidden number selected from the set of integers $\\{1, 2, \\dots, n\\}$ by asking questions. \nEach number (question) we ask, has a cost equal to the number asked and we get one of three possible answers:

Given the value of $n$, an optimal strategy minimizes the total cost (i.e. the sum of all the questions asked) for the worst possible case. E.g.

\n\n

If $n=3$, the best we can do is obviously to ask the number \"2\". The answer will immediately lead us to find the hidden number (at a total cost $= 2$).

\n\n

If $n=8$, we might decide to use a \"binary search\" type of strategy: Our first question would be \"$\\mathbf 4$\" and if the hidden number is higher than $4$ we will need one or two additional questions.
\nLet our second question be \"$\\mathbf 6$\". If the hidden number is still higher than $6$, we will need a third question in order to discriminate between $7$ and $8$.
\nThus, our third question will be \"$\\mathbf 7$\" and the total cost for this worst-case scenario will be $4+6+7={\\color{red}\\mathbf{17}}$.

\n\n

We can improve considerably the worst-case cost for $n=8$, by asking \"$\\mathbf 5$\" as our first question.
\nIf we are told that the hidden number is higher than $5$, our second question will be \"$\\mathbf 7$\", then we'll know for certain what the hidden number is (for a total cost of $5+7={\\color{blue}\\mathbf{12}}$).
\nIf we are told that the hidden number is lower than $5$, our second question will be \"$\\mathbf 3$\" and if the hidden number is lower than $3$ our third question will be \"$\\mathbf 1$\", giving a total cost of $5+3+1={\\color{blue}\\mathbf 9}$.
\nSince ${\\color{blue}\\mathbf{12}} \\gt {\\color{blue}\\mathbf 9}$, the worst-case cost for this strategy is ${\\color{red}\\mathbf{12}}$. That's better than what we achieved previously with the \"binary search\" strategy; it is also better than or equal to any other strategy.
\nSo, in fact, we have just described an optimal strategy for $n=8$.

\n\n

Let $C(n)$ be the worst-case cost achieved by an optimal strategy for $n$, as described above.
\nThus $C(1) = 0$, $C(2) = 1$, $C(3) = 2$ and $C(8) = 12$.
\nSimilarly, $C(100) = 400$ and $\\sum \\limits_{n = 1}^{100} C(n) = 17575$.

\n\n

Find $\\sum \\limits_{n = 1}^{200000} C(n)$.

", "url": "https://projecteuler.net/problem=328", "answer": "260511850222"} {"id": 329, "problem": "Susan has a prime frog.\n\nHer frog is jumping around over $500$ squares numbered $1$ to $500$.\nHe can only jump one square to the left or to the right, with equal probability, and he cannot jump outside the range $[1;500]$.\n(if it lands at either end, it automatically jumps to the only available square on the next move.)\n\nWhen he is on a square with a prime number on it, he croaks 'P' (PRIME) with probability $2/3$ or 'N' (NOT PRIME) with probability $1/3$ just before jumping to the next square.\n\nWhen he is on a square with a number on it that is not a prime he croaks 'P' with probability $1/3$ or 'N' with probability $2/3$ just before jumping to the next square.\n\nGiven that the frog's starting position is random with the same probability for every square, and given that she listens to his first $15$ croaks, what is the probability that she hears the sequence PPPPNNPPPNPPNPN?\n\nGive your answer as a fraction $p/q$ in reduced form.", "raw_html": "

Susan has a prime frog.
\nHer frog is jumping around over $500$ squares numbered $1$ to $500$.\nHe can only jump one square to the left or to the right, with equal probability, and he cannot jump outside the range $[1;500]$.
(if it lands at either end, it automatically jumps to the only available square on the next move.)\n

\n

\nWhen he is on a square with a prime number on it, he croaks 'P' (PRIME) with probability $2/3$ or 'N' (NOT PRIME) with probability $1/3$ just before jumping to the next square.
\nWhen he is on a square with a number on it that is not a prime he croaks 'P' with probability $1/3$ or 'N' with probability $2/3$ just before jumping to the next square.\n

\n

\nGiven that the frog's starting position is random with the same probability for every square, and given that she listens to his first $15$ croaks, what is the probability that she hears the sequence PPPPNNPPPNPPNPN?\n

\nGive your answer as a fraction $p/q$ in reduced form.", "url": "https://projecteuler.net/problem=329", "answer": "199740353/29386561536000"} {"id": 330, "problem": "An infinite sequence of real numbers $a(n)$ is defined for all integers $n$ as follows:\n$$a(n) = \\begin{cases}\n1 & n \\lt 0\\\\\n\\sum \\limits_{i = 1}^{\\infty}{\\dfrac{a(n - i)}{i!}} & n \\ge 0\n\\end{cases}$$\n\nFor example,\n\n$a(0) = \\dfrac{1}{1!} + \\dfrac{1}{2!} + \\dfrac{1}{3!} + \\cdots = e - 1$\n\n$a(1) = \\dfrac{e - 1}{1!} + \\dfrac{1}{2!} + \\dfrac{1}{3!} + \\cdots = 2e - 3$\n\n$a(2) = \\dfrac{2e - 3}{1!} + \\dfrac{e - 1}{2!} + \\dfrac{1}{3!} + \\cdots = \\dfrac{7}{2}e - 6$\n\nwith $e = 2.7182818...$ being Euler's constant.\n\nIt can be shown that $a(n)$ is of the form $\\dfrac{A(n)e + B(n)}{n!}$ for integers $A(n)$ and $B(n)$.\n\nFor example, $a(10) = \\dfrac{328161643e - 652694486}{10!}$.\n\nFind $A(10^9) + B(10^9)$ and give your answer mod $77\\,777\\,777$.", "raw_html": "An infinite sequence of real numbers $a(n)$ is defined for all integers $n$ as follows:\n$$a(n) = \\begin{cases}\n1 & n \\lt 0\\\\\n\\sum \\limits_{i = 1}^{\\infty}{\\dfrac{a(n - i)}{i!}} & n \\ge 0\n\\end{cases}$$\n\n

For example,

\n\n

$a(0) = \\dfrac{1}{1!} + \\dfrac{1}{2!} + \\dfrac{1}{3!} + \\cdots = e - 1$
\n$a(1) = \\dfrac{e - 1}{1!} + \\dfrac{1}{2!} + \\dfrac{1}{3!} + \\cdots = 2e - 3$
\n$a(2) = \\dfrac{2e - 3}{1!} + \\dfrac{e - 1}{2!} + \\dfrac{1}{3!} + \\cdots = \\dfrac{7}{2}e - 6$

\n\n

with $e = 2.7182818...$ being Euler's constant.

\n\n

It can be shown that $a(n)$ is of the form $\\dfrac{A(n)e + B(n)}{n!}$ for integers $A(n)$ and $B(n)$.

\n\n

For example, $a(10) = \\dfrac{328161643e - 652694486}{10!}$.

\n\n

Find $A(10^9) + B(10^9)$ and give your answer mod $77\\,777\\,777$.

", "url": "https://projecteuler.net/problem=330", "answer": "15955822"} {"id": 331, "problem": "$N \\times N$ disks are placed on a square game board. Each disk has a black side and white side.\n\nAt 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 \\times N - 1$ disks are flipped. The game ends when all disks show their white side. The following example shows a game on a $5 \\times 5$ board.\n\nIt can be proven that $3$ is the minimal number of turns to finish this game.\n\nThe bottom left disk on the $N \\times N$ board has coordinates $(0,0)$;\n\nthe bottom right disk has coordinates $(N-1,0)$ and the top left disk has coordinates $(0,N-1)$.\n\nLet $C_N$ be the following configuration of a board with $N \\times N$ disks:\n\nA disk at $(x, y)$ satisfying $N - 1 \\le \\sqrt{x^2 + y^2} \\lt N$, shows its black side; otherwise, it shows its white side. $C_5$ is shown above.\n\nLet $T(N)$ be the minimal number of turns to finish a game starting from configuration $C_N$ or $0$ if configuration $C_N$ is unsolvable.\n\nWe have shown that $T(5)=3$. You are also given that $T(10)=29$ and $T(1\\,000)=395253$.\n\nFind $\\sum \\limits_{i = 3}^{31} T(2^i - i)$.", "raw_html": "

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

\n\n

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 \\times N - 1$ disks are flipped. The game ends when all disks show their white side. The following example shows a game on a $5 \\times 5$ board.

\n\n
\"0331_crossflips3.gif\"
\n\n

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

\n\n

The bottom left disk on the $N \\times N$ board has coordinates $(0,0)$;
\nthe bottom right disk has coordinates $(N-1,0)$ and the top left disk has coordinates $(0,N-1)$.

\n\n

Let $C_N$ be the following configuration of a board with $N \\times N$ disks:
\nA disk at $(x, y)$ satisfying $N - 1 \\le \\sqrt{x^2 + y^2} \\lt N$, shows its black side; otherwise, it shows its white side. $C_5$ is shown above.

\n\n

Let $T(N)$ be the minimal number of turns to finish a game starting from configuration $C_N$ or $0$ if configuration $C_N$ is unsolvable.
\nWe have shown that $T(5)=3$. You are also given that $T(10)=29$ and $T(1\\,000)=395253$.

\n\n

Find $\\sum \\limits_{i = 3}^{31} T(2^i - i)$.

", "url": "https://projecteuler.net/problem=331", "answer": "467178235146843549"} {"id": 332, "problem": "A spherical triangle is a figure formed on the surface of a sphere by three great circular arcs intersecting pairwise in three vertices.\n\nLet $C(r)$ be the sphere with the centre $(0,0,0)$ and radius $r$.\n\nLet $Z(r)$ be the set of points on the surface of $C(r)$ with integer coordinates.\n\nLet $T(r)$ be the set of spherical triangles with vertices in $Z(r)$.\nDegenerate spherical triangles, formed by three points on the same great arc, are not included in $T(r)$.\n\nLet $A(r)$ be the area of the smallest spherical triangle in $T(r)$.\n\nFor example $A(14)$ is $3.294040$ rounded to six decimal places.\n\nFind $\\sum \\limits_{r = 1}^{50} A(r)$. Give your answer rounded to six decimal places.", "raw_html": "

A spherical triangle is a figure formed on the surface of a sphere by three great circular arcs intersecting pairwise in three vertices.

\n\n
\"0332_spherical.jpg\"
\n\n\n

Let $C(r)$ be the sphere with the centre $(0,0,0)$ and radius $r$.
\nLet $Z(r)$ be the set of points on the surface of $C(r)$ with integer coordinates.
\nLet $T(r)$ be the set of spherical triangles with vertices in $Z(r)$.\nDegenerate spherical triangles, formed by three points on the same great arc, are not included in $T(r)$.
\nLet $A(r)$ be the area of the smallest spherical triangle in $T(r)$.

\n\n

For example $A(14)$ is $3.294040$ rounded to six decimal places.

\n\n

Find $\\sum \\limits_{r = 1}^{50} A(r)$. Give your answer rounded to six decimal places.

", "url": "https://projecteuler.net/problem=332", "answer": "2717.751525"} {"id": 333, "problem": "All positive integers can be partitioned in such a way that each and every term of the partition can be expressed as $2^i \\times 3^j$, where $i,j \\ge 0$.\n\nLet's consider only such partitions where none of the terms can divide any of the other terms.\n\nFor example, the partition of $17 = 2 + 6 + 9 = (2^1 \\times 3^0 + 2^1 \\times 3^1 + 2^0 \\times 3^2)$ would not be valid since $2$ can divide $6$. Neither would the partition $17 = 16 + 1 = (2^4 \\times 3^0 + 2^0 \\times 3^0)$ since $1$ can divide $16$. The only valid partition of $17$ would be $8 + 9 = (2^3 \\times 3^0 + 2^0 \\times 3^2)$.\n\nMany integers have more than one valid partition, the first being $11$ having the following two partitions.\n\n$11 = 2 + 9 = (2^1 \\times 3^0 + 2^0 \\times 3^2)$\n\n$11 = 8 + 3 = (2^3 \\times 3^0 + 2^0 \\times 3^1)$\n\nLet's define $P(n)$ as the number of valid partitions of $n$. For example, $P(11) = 2$.\n\nLet's consider only the prime integers $q$ which would have a single valid partition such as $P(17)$.\n\nThe sum of the primes $q \\lt 100$ such that $P(q)=1$ equals $233$.\n\nFind the sum of the primes $q \\lt 1000000$ such that $P(q)=1$.", "raw_html": "

All positive integers can be partitioned in such a way that each and every term of the partition can be expressed as $2^i \\times 3^j$, where $i,j \\ge 0$.

\n\n

Let's consider only such partitions where none of the terms can divide any of the other terms.\n
For example, the partition of $17 = 2 + 6 + 9 = (2^1 \\times 3^0 + 2^1 \\times 3^1 + 2^0 \\times 3^2)$ would not be valid since $2$ can divide $6$. Neither would the partition $17 = 16 + 1 = (2^4 \\times 3^0 + 2^0 \\times 3^0)$ since $1$ can divide $16$. The only valid partition of $17$ would be $8 + 9 = (2^3 \\times 3^0 + 2^0 \\times 3^2)$.

\n\n

Many integers have more than one valid partition, the first being $11$ having the following two partitions.\n
$11 = 2 + 9 = (2^1 \\times 3^0 + 2^0 \\times 3^2)$\n
$11 = 8 + 3 = (2^3 \\times 3^0 + 2^0 \\times 3^1)$

\n\n

Let's define $P(n)$ as the number of valid partitions of $n$. For example, $P(11) = 2$.

\n\n

Let's consider only the prime integers $q$ which would have a single valid partition such as $P(17)$.

\n\n

The sum of the primes $q \\lt 100$ such that $P(q)=1$ equals $233$.

\n\n

Find the sum of the primes $q \\lt 1000000$ such that $P(q)=1$.

", "url": "https://projecteuler.net/problem=333", "answer": "3053105"} {"id": 334, "problem": "In Plato's heaven, there exist an infinite number of bowls in a straight line.\n\nEach bowl either contains some or none of a finite number of beans.\n\nA child plays a game, which allows only one kind of move: removing two beans from any bowl, and putting one in each of the two adjacent bowls.\nThe game ends when each bowl contains either one or no beans.\n\nFor example, consider two adjacent bowls containing $2$ and $3$ beans respectively, all other bowls being empty. The following eight moves will finish the game:\n\nYou are given the following sequences:\n\n$\\def\\htmltext#1{\\style{font-family:inherit;}{\\text{#1}}}$\n$\n\\begin{align}\n\\qquad t_0 &= 123456,\\cr\n\\qquad t_i &= \\cases{\n\\;\\;\\frac{t_{i-1}}{2},&$\\htmltext{if }t_{i-1}\\htmltext{ is even}$\\cr\n\\left\\lfloor\\frac{t_{i-1}}{2}\\right\\rfloor\\oplus 926252,&$\\htmltext{if }t_{i-1}\\htmltext{ is odd}$\\cr}\\cr\n&\\qquad\\htmltext{where }\\lfloor x\\rfloor\\htmltext{ is the floor function }\\cr\n&\\qquad\\!\\htmltext{and }\\oplus\\htmltext{is the bitwise XOR operator.}\\cr\n\\qquad b_i &= (t_i\\bmod2^{11}) + 1.\\cr\n\\end{align}\n$\n\nThe first two terms of the last sequence are $b_1 = 289$ and $b_2 = 145$.\n\nIf we start with $b_1$ and $b_2$ beans in two adjacent bowls, $3419100$ moves would be required to finish the game.\n\nConsider now $1500$ adjacent bowls containing $b_1, b_2, \\ldots, b_{1500}$ beans respectively, all other bowls being empty. Find how many moves it takes before the game ends.", "raw_html": "

In Plato's heaven, there exist an infinite number of bowls in a straight line.
\nEach bowl either contains some or none of a finite number of beans.
\nA child plays a game, which allows only one kind of move: removing two beans from any bowl, and putting one in each of the two adjacent bowls.
The game ends when each bowl contains either one or no beans.

\n\n

For example, consider two adjacent bowls containing $2$ and $3$ beans respectively, all other bowls being empty. The following eight moves will finish the game:

\n\n
\"0334_beans.gif\"
\n\n

You are given the following sequences:

\n\n

\n$\\def\\htmltext#1{\\style{font-family:inherit;}{\\text{#1}}}$\n$\n\\begin{align}\n\\qquad t_0 &= 123456,\\cr\n\\qquad t_i &= \\cases{\n\\;\\;\\frac{t_{i-1}}{2},&$\\htmltext{if }t_{i-1}\\htmltext{ is even}$\\cr\n\\left\\lfloor\\frac{t_{i-1}}{2}\\right\\rfloor\\oplus 926252,&$\\htmltext{if }t_{i-1}\\htmltext{ is odd}$\\cr}\\cr\n&\\qquad\\htmltext{where }\\lfloor x\\rfloor\\htmltext{ is the floor function }\\cr\n&\\qquad\\!\\htmltext{and }\\oplus\\htmltext{is the bitwise XOR operator.}\\cr\n\\qquad b_i &= (t_i\\bmod2^{11}) + 1.\\cr\n\\end{align}\n$\n

\n\n

The first two terms of the last sequence are $b_1 = 289$ and $b_2 = 145$.
\nIf we start with $b_1$ and $b_2$ beans in two adjacent bowls, $3419100$ moves would be required to finish the game.

\n\n

Consider now $1500$ adjacent bowls containing $b_1, b_2, \\ldots, b_{1500}$ beans respectively, all other bowls being empty. Find how many moves it takes before the game ends.

", "url": "https://projecteuler.net/problem=334", "answer": "150320021261690835"} {"id": 335, "problem": "Whenever Peter feels bored, he places some bowls, containing one bean each, in a circle. After this, he takes all the beans out of a certain bowl and drops them one by one in the bowls going clockwise. He repeats this, starting from the bowl he dropped the last bean in, until the initial situation appears again. For example with 5 bowls he acts as follows:\n\nSo with $5$ bowls it takes Peter $15$ moves to return to the initial situation.\n\nLet $M(x)$ represent the number of moves required to return to the initial situation, starting with $x$ bowls. Thus, $M(5) = 15$. It can also be verified that $M(100) = 10920$.\n\nFind $\\displaystyle \\sum_{k=0}^{10^{18}} M(2^k + 1)$. Give your answer modulo $7^9$.", "raw_html": "

Whenever Peter feels bored, he places some bowls, containing one bean each, in a circle. After this, he takes all the beans out of a certain bowl and drops them one by one in the bowls going clockwise. He repeats this, starting from the bowl he dropped the last bean in, until the initial situation appears again. For example with 5 bowls he acts as follows:

\n\n
\"0335_mancala.gif\"
\n\n

So with $5$ bowls it takes Peter $15$ moves to return to the initial situation.

\n\n

Let $M(x)$ represent the number of moves required to return to the initial situation, starting with $x$ bowls. Thus, $M(5) = 15$. It can also be verified that $M(100) = 10920$.

\n\n

Find $\\displaystyle \\sum_{k=0}^{10^{18}} M(2^k + 1)$. Give your answer modulo $7^9$.

", "url": "https://projecteuler.net/problem=335", "answer": "5032316"} {"id": 336, "problem": "A train is used to transport four carriages in the order: ABCD. However, sometimes when the train arrives to collect the carriages they are not in the correct order.\n\nTo rearrange the carriages they are all shunted on to a large rotating turntable. After the carriages are uncoupled at a specific point the train moves off the turntable pulling the carriages still attached with it. The remaining carriages are rotated 180 degrees. All of the carriages are then rejoined and this process is repeated as often as necessary in order to obtain the least number of uses of the turntable.\n\nSome arrangements, such as ADCB, can be solved easily: the carriages are separated between A and D, and after DCB are rotated the correct order has been achieved.\n\nHowever, Simple Simon, the train driver, is not known for his efficiency, so he always solves the problem by initially getting carriage A in the correct place, then carriage B, and so on.\n\nUsing four carriages, the worst possible arrangements for Simon, which we shall call maximix arrangements, are DACB and DBAC; each requiring him five rotations (although, using the most efficient approach, they could be solved using just three rotations). The process he uses for DACB is shown below.\n\nIt can be verified that there are 24 maximix arrangements for six carriages, of which the tenth lexicographic maximix arrangement is DFAECB.\n\nFind the 2011th lexicographic maximix arrangement for eleven carriages.", "raw_html": "

A train is used to transport four carriages in the order: ABCD. However, sometimes when the train arrives to collect the carriages they are not in the correct order.
\nTo rearrange the carriages they are all shunted on to a large rotating turntable. After the carriages are uncoupled at a specific point the train moves off the turntable pulling the carriages still attached with it. The remaining carriages are rotated 180 degrees. All of the carriages are then rejoined and this process is repeated as often as necessary in order to obtain the least number of uses of the turntable.
\nSome arrangements, such as ADCB, can be solved easily: the carriages are separated between A and D, and after DCB are rotated the correct order has been achieved.

\n\n

However, Simple Simon, the train driver, is not known for his efficiency, so he always solves the problem by initially getting carriage A in the correct place, then carriage B, and so on.

\n\n

Using four carriages, the worst possible arrangements for Simon, which we shall call maximix arrangements, are DACB and DBAC; each requiring him five rotations (although, using the most efficient approach, they could be solved using just three rotations). The process he uses for DACB is shown below.

\n\n
\"0336_maximix.gif\"
\n\n\n

It can be verified that there are 24 maximix arrangements for six carriages, of which the tenth lexicographic maximix arrangement is DFAECB.

\n\n

Find the 2011th lexicographic maximix arrangement for eleven carriages.

", "url": "https://projecteuler.net/problem=336", "answer": "CAGBIHEFJDK"} {"id": 337, "problem": "Let $\\{a_1, a_2, \\dots, a_n\\}$ be an integer sequence of length $n$ such that:\n\n- $a_1 = 6$\n\n- for all $1 \\le i \\lt n$: $\\phi(a_i) \\lt \\phi(a_{i + 1}) \\lt a_i \\lt a_{i + 1}$.1\n\nLet $S(N)$ be the number of such sequences with $a_n \\le N$.\n\nFor example, $S(10) = 4$: $\\{6\\}$, $\\{6, 8\\}$, $\\{6, 8, 9\\}$ and $\\{6, 10\\}$.\n\nWe can verify that $S(100) = 482073668$ and $S(10\\,000) \\bmod 10^8 = 73808307$.\n\nFind $S(20\\,000\\,000) \\bmod 10^8$.\n\n1 $\\phi$ denotes Euler's totient function.", "raw_html": "

Let $\\{a_1, a_2, \\dots, a_n\\}$ be an integer sequence of length $n$ such that:

\n

Let $S(N)$ be the number of such sequences with $a_n \\le N$.
\nFor example, $S(10) = 4$: $\\{6\\}$, $\\{6, 8\\}$, $\\{6, 8, 9\\}$ and $\\{6, 10\\}$.
\nWe can verify that $S(100) = 482073668$ and $S(10\\,000) \\bmod 10^8 = 73808307$.

\n\n

Find $S(20\\,000\\,000) \\bmod 10^8$.

\n\n

1 $\\phi$ denotes Euler's totient function.

", "url": "https://projecteuler.net/problem=337", "answer": "85068035"} {"id": 338, "problem": "A rectangular sheet of grid paper with integer dimensions $w \\times h$ is given. Its grid spacing is $1$.\n\nWhen we cut the sheet along the grid lines into two pieces and rearrange those pieces without overlap, we can make new rectangles with different dimensions.\n\nFor example, from a sheet with dimensions $9 \\times 4$, we can make rectangles with dimensions $18 \\times 2$, $12 \\times 3$ and $6 \\times 6$ by cutting and rearranging as below:\n\nSimilarly, from a sheet with dimensions $9 \\times 8$, we can make rectangles with dimensions $18 \\times 4$ and $12 \\times 6$.\n\nFor a pair $w$ and $h$, let $F(w, h)$ be the number of distinct rectangles that can be made from a sheet with dimensions $w \\times h$.\n\nFor example, $F(2,1) = 0$, $F(2,2) = 1$, $F(9,4) = 3$ and $F(9,8) = 2$.\n\nNote that rectangles congruent to the initial one are not counted in $F(w, h)$.\n\nNote also that rectangles with dimensions $w \\times h$ and dimensions $h \\times w$ are not considered distinct.\n\nFor an integer $N$, let $G(N)$ be the sum of $F(w, h)$ for all pairs $w$ and $h$ which satisfy $0 \\lt h \\le w \\le N$.\n\nWe can verify that $G(10) = 55$, $G(10^3) = 971745$ and $G(10^5) = 9992617687$.\n\nFind $G(10^{12})$. Give your answer modulo $10^8$.", "raw_html": "

A rectangular sheet of grid paper with integer dimensions $w \\times h$ is given. Its grid spacing is $1$.
\nWhen we cut the sheet along the grid lines into two pieces and rearrange those pieces without overlap, we can make new rectangles with different dimensions.

\n

For example, from a sheet with dimensions $9 \\times 4$, we can make rectangles with dimensions $18 \\times 2$, $12 \\times 3$ and $6 \\times 6$ by cutting and rearranging as below:

\n\n
\n\"0338_gridpaper.gif\"
\n\n

Similarly, from a sheet with dimensions $9 \\times 8$, we can make rectangles with dimensions $18 \\times 4$ and $12 \\times 6$.

\n\n

For a pair $w$ and $h$, let $F(w, h)$ be the number of distinct rectangles that can be made from a sheet with dimensions $w \\times h$.
\nFor example, $F(2,1) = 0$, $F(2,2) = 1$, $F(9,4) = 3$ and $F(9,8) = 2$.
\nNote that rectangles congruent to the initial one are not counted in $F(w, h)$.
\nNote also that rectangles with dimensions $w \\times h$ and dimensions $h \\times w$ are not considered distinct.

\n\n

For an integer $N$, let $G(N)$ be the sum of $F(w, h)$ for all pairs $w$ and $h$ which satisfy $0 \\lt h \\le w \\le N$.
\nWe can verify that $G(10) = 55$, $G(10^3) = 971745$ and $G(10^5) = 9992617687$.

\n\n

Find $G(10^{12})$. Give your answer modulo $10^8$.

", "url": "https://projecteuler.net/problem=338", "answer": "15614292"} {"id": 339, "problem": "\"And he came towards a valley, through which ran a river; and the borders of the valley were wooded, and on each side of the river were level meadows. And on one side of the river he saw a flock of white sheep, and on the other a flock of black sheep. And whenever one of the white sheep bleated, one of the black sheep would cross over and become white; and when one of the black sheep bleated, one of the white sheep would cross over and become black.\"\nen.wikisource.org\n\nInitially each flock consists of $n$ sheep. Each sheep (regardless of colour) is equally likely to be the next sheep to bleat. After a sheep has bleated and a sheep from the other flock has crossed over, Peredur may remove a number of white sheep in order to maximize the expected final number of black sheep. Let $E(n)$ be the expected final number of black sheep if Peredur uses an optimal strategy.\n\nYou are given that $E(5) = 6.871346$ rounded to $6$ places behind the decimal point.\n\nFind $E(10\\,000)$ and give your answer rounded to $6$ places behind the decimal point.", "raw_html": "

\n\"And he came towards a valley, through which ran a river; and the borders of the valley were wooded, and on each side of the river were level meadows. And on one side of the river he saw a flock of white sheep, and on the other a flock of black sheep. And whenever one of the white sheep bleated, one of the black sheep would cross over and become white; and when one of the black sheep bleated, one of the white sheep would cross over and become black.\"
en.wikisource.org\n

\n

\n\nInitially each flock consists of $n$ sheep. Each sheep (regardless of colour) is equally likely to be the next sheep to bleat. After a sheep has bleated and a sheep from the other flock has crossed over, Peredur may remove a number of white sheep in order to maximize the expected final number of black sheep. Let $E(n)$ be the expected final number of black sheep if Peredur uses an optimal strategy.\n

\n

\n\nYou are given that $E(5) = 6.871346$ rounded to $6$ places behind the decimal point.
\nFind $E(10\\,000)$ and give your answer rounded to $6$ places behind the decimal point.\n

", "url": "https://projecteuler.net/problem=339", "answer": "19823.542204"} {"id": 340, "problem": "For fixed integers $a, b, c$, define the crazy function $F(n)$ as follows:\n\n$F(n) = n - c$ for all $n \\gt b$\n\n$F(n) = F(a + F(a + F(a + F(a + n))))$ for all $n \\le b$.\n\nAlso, define $S(a, b, c) = \\sum \\limits_{n = 0}^b F(n)$.\n\nFor example, if $a = 50$, $b = 2000$ and $c = 40$, then $F(0) = 3240$ and $F(2000) = 2040$.\n\nAlso, $S(50, 2000, 40) = 5204240$.\n\nFind the last $9$ digits of $S(21^7, 7^{21}, 12^7)$.", "raw_html": "

\nFor fixed integers $a, b, c$, define the crazy function $F(n)$ as follows:
\n$F(n) = n - c$ for all $n \\gt b$
\n$F(n) = F(a + F(a + F(a + F(a + n))))$ for all $n \\le b$.\n

\n

Also, define $S(a, b, c) = \\sum \\limits_{n = 0}^b F(n)$.

\n

\nFor example, if $a = 50$, $b = 2000$ and $c = 40$, then $F(0) = 3240$ and $F(2000) = 2040$.
\nAlso, $S(50, 2000, 40) = 5204240$.\n

\n

\nFind the last $9$ digits of $S(21^7, 7^{21}, 12^7)$.\n

", "url": "https://projecteuler.net/problem=340", "answer": "291504964"} {"id": 341, "problem": "The Golomb's self-describing sequence $(G(n))$ is the only nondecreasing sequence of natural numbers such that $n$ appears exactly $G(n)$ times in the sequence. The values of $G(n)$ for the first few $n$ are\n\n$$\n\\begin{matrix}\nn & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & \\ldots \\\\\nG(n) & 1 & 2 & 2 & 3 & 3 & 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 & 6 & \\ldots\n\\end{matrix}\n$$\n\nYou are given that $G(10^3) = 86$, $G(10^6) = 6137$.\n\nYou are also given that $\\sum G(n^3) = 153506976$ for $1 \\le n \\lt 10^3$.\n\nFind $\\sum G(n^3)$ for $1 \\le n \\lt 10^6$.", "raw_html": "

The Golomb's self-describing sequence $(G(n))$ is the only nondecreasing sequence of natural numbers such that $n$ appears exactly $G(n)$ times in the sequence. The values of $G(n)$ for the first few $n$ are

\n\n

\n$$\n\\begin{matrix}\nn & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & \\ldots \\\\\nG(n) & 1 & 2 & 2 & 3 & 3 & 4 & 4 & 4 & 5 & 5 & 5 & 6 & 6 & 6 & 6 & \\ldots\n\\end{matrix}\n$$\n
\n\n

You are given that $G(10^3) = 86$, $G(10^6) = 6137$.
\nYou are also given that $\\sum G(n^3) = 153506976$ for $1 \\le n \\lt 10^3$.

\n\n

Find $\\sum G(n^3)$ for $1 \\le n \\lt 10^6$.

", "url": "https://projecteuler.net/problem=341", "answer": "56098610614277014"} {"id": 342, "problem": "Consider the number $50$.\n\n$50^2 = 2500 = 2^2 \\times 5^4$, so $\\phi(2500) = 2 \\times 4 \\times 5^3 = 8 \\times 5^3 = 2^3 \\times 5^3$. 1\n\nSo $2500$ is a square and $\\phi(2500)$ is a cube.\n\nFind the sum of all numbers $n$, $1 \\lt n \\lt 10^{10}$ such that $\\phi(n^2)$ is a cube.\n\n1 $\\phi$ denotes Euler's totient function.", "raw_html": "

\nConsider the number $50$.
\n$50^2 = 2500 = 2^2 \\times 5^4$, so $\\phi(2500) = 2 \\times 4 \\times 5^3 = 8 \\times 5^3 = 2^3 \\times 5^3$. 1
\nSo $2500$ is a square and $\\phi(2500)$ is a cube.\n

\n

\nFind the sum of all numbers $n$, $1 \\lt n \\lt 10^{10}$ such that $\\phi(n^2)$ is a cube.\n

\n

\n1 $\\phi$ denotes Euler's totient function.\n

", "url": "https://projecteuler.net/problem=342", "answer": "5943040885644"} {"id": 343, "problem": "For any positive integer $k$, a finite sequence $a_i$ of fractions $x_i/y_i$ is defined by:\n\n$a_1 = 1/k$ and\n\n$a_i = (x_{i - 1} + 1) / (y_{i - 1} - 1)$ reduced to lowest terms for $i \\gt 1$.\n\nWhen $a_i$ reaches some integer $n$, the sequence stops. (That is, when $y_i = 1$.)\n\nDefine $f(k) = n$.\n\nFor example, for $k = 20$:\n\n$1/20 \\to 2/19 \\to 3/18 = 1/6 \\to 2/5 \\to 3/4 \\to 4/3 \\to 5/2 \\to 6/1 = 6$\n\nSo $f(20) = 6$.\n\nAlso $f(1) = 1$, $f(2) = 2$, $f(3) = 1$ and $\\sum f(k^3) = 118937$ for $1 \\le k \\le 100$.\n\nFind $\\sum f(k^3)$ for $1 \\le k \\le 2 \\times 10^6$.", "raw_html": "

For any positive integer $k$, a finite sequence $a_i$ of fractions $x_i/y_i$ is defined by:
\n$a_1 = 1/k$ and
\n$a_i = (x_{i - 1} + 1) / (y_{i - 1} - 1)$ reduced to lowest terms for $i \\gt 1$.
\nWhen $a_i$ reaches some integer $n$, the sequence stops. (That is, when $y_i = 1$.)
\nDefine $f(k) = n$.
\nFor example, for $k = 20$:\n

\n\n

\n$1/20 \\to 2/19 \\to 3/18 = 1/6 \\to 2/5 \\to 3/4 \\to 4/3 \\to 5/2 \\to 6/1 = 6$\n

\n\n

\nSo $f(20) = 6$.\n

\n\n

\nAlso $f(1) = 1$, $f(2) = 2$, $f(3) = 1$ and $\\sum f(k^3) = 118937$ for $1 \\le k \\le 100$.\n

\n\n

\nFind $\\sum f(k^3)$ for $1 \\le k \\le 2 \\times 10^6$.\n

", "url": "https://projecteuler.net/problem=343", "answer": "269533451410884183"} {"id": 344, "problem": "One variant of N.G. de Bruijn's silver dollar game can be described as follows:\n\nOn 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.\n\nA 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.\n\nAlternatively, 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.\n\nThe winner is the player who pockets the silver dollar.\n\nA 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.\n\nLet $W(n,c)$ be the number of winning configurations for a strip of $n$ squares, $c$ worthless coins and one silver dollar.\n\nYou are given that $W(10,2) = 324$ and $W(100,10) = 1514704946113500$.\n\nFind $W(1\\,000\\,000, 100)$ modulo the semiprime $1000\\,036\\,000\\,099$ ($= 1\\,000\\,003 \\cdot 1\\,000\\,033$).", "raw_html": "

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

\n\n

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.

\n\n

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.

\n\n

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.

\n\n

The winner is the player who pockets the silver dollar.

\n\n\n
\n\"0344_silverdollar.gif\"
\n\n

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.

\n\n

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

\n\n

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

\n\n

Find $W(1\\,000\\,000, 100)$ modulo the semiprime $1000\\,036\\,000\\,099$ ($= 1\\,000\\,003 \\cdot 1\\,000\\,033$).\n

", "url": "https://projecteuler.net/problem=344", "answer": "65579304332"} {"id": 345, "problem": "We define the Matrix Sum of a matrix as the maximum possible sum of matrix elements such that none of the selected elements share the same row or column.\n\nFor example, the Matrix Sum of the matrix below equals 3315 ( = 863 + 383 + 343 + 959 + 767):\n\n7  53 183 439 863\n\n497 383 563  79 973\n\n287  63 343 169 583\n\n627 343 773 959 943\n767 473 103 699 303\n\nFind the Matrix Sum of:\n\n7  53 183 439 863 497 383 563  79 973 287  63 343 169 583\n\n627 343 773 959 943 767 473 103 699 303 957 703 583 639 913\n\n447 283 463  29  23 487 463 993 119 883 327 493 423 159 743\n\n217 623   3 399 853 407 103 983  89 463 290 516 212 462 350\n\n960 376 682 962 300 780 486 502 912 800 250 346 172 812 350\n\n870 456 192 162 593 473 915  45 989 873 823 965 425 329 803\n\n973 965 905 919 133 673 665 235 509 613 673 815 165 992 326\n\n322 148 972 962 286 255 941 541 265 323 925 281 601  95 973\n\n445 721  11 525 473  65 511 164 138 672  18 428 154 448 848\n\n414 456 310 312 798 104 566 520 302 248 694 976 430 392 198\n\n184 829 373 181 631 101 969 613 840 740 778 458 284 760 390\n\n821 461 843 513  17 901 711 993 293 157 274  94 192 156 574\n\n34 124   4 878 450 476 712 914 838 669 875 299 823 329 699\n\n815 559 813 459 522 788 168 586 966 232 308 833 251 631 107\n\n813 883 451 509 615  77 281 613 459 205 380 274 302  35 805", "raw_html": "

We define the Matrix Sum of a matrix as the maximum possible sum of matrix elements such that none of the selected elements share the same row or column.

\n\n

For example, the Matrix Sum of the matrix below equals 3315 ( = 863 + 383 + 343 + 959 + 767):

\n\n

\n  7  53 183 439 863
\n497 383 563  79 973
\n287  63 343 169 583
\n627 343 773 959 943
767 473 103 699 303

\n\n

\nFind the Matrix Sum of:

\n

\n  7  53 183 439 863 497 383 563  79 973 287  63 343 169 583
\n627 343 773 959 943 767 473 103 699 303 957 703 583 639 913
\n447 283 463  29  23 487 463 993 119 883 327 493 423 159 743
\n217 623   3 399 853 407 103 983  89 463 290 516 212 462 350
\n960 376 682 962 300 780 486 502 912 800 250 346 172 812 350
\n870 456 192 162 593 473 915  45 989 873 823 965 425 329 803
\n973 965 905 919 133 673 665 235 509 613 673 815 165 992 326
\n322 148 972 962 286 255 941 541 265 323 925 281 601  95 973
\n445 721  11 525 473  65 511 164 138 672  18 428 154 448 848
\n414 456 310 312 798 104 566 520 302 248 694 976 430 392 198
\n184 829 373 181 631 101 969 613 840 740 778 458 284 760 390
\n821 461 843 513  17 901 711 993 293 157 274  94 192 156 574
\n 34 124   4 878 450 476 712 914 838 669 875 299 823 329 699
\n815 559 813 459 522 788 168 586 966 232 308 833 251 631 107
\n813 883 451 509 615  77 281 613 459 205 380 274 302  35 805

", "url": "https://projecteuler.net/problem=345", "answer": "13938"} {"id": 346, "problem": "The number $7$ is special, because $7$ is $111$ written in base $2$, and $11$ written in base $6$ (i.e. $7_{10} = 11_6 = 111_2$). In other words, $7$ is a repunit in at least two bases $b \\gt 1$.\n\nWe shall call a positive integer with this property a strong repunit. It can be verified that there are $8$ strong repunits below $50$: $\\{1,7,13,15,21,31,40,43\\}$.\n\nFurthermore, the sum of all strong repunits below $1000$ equals $15864$.\n\nFind the sum of all strong repunits below $10^{12}$.", "raw_html": "

\nThe number $7$ is special, because $7$ is $111$ written in base $2$, and $11$ written in base $6$ (i.e. $7_{10} = 11_6 = 111_2$). In other words, $7$ is a repunit in at least two bases $b \\gt 1$. \n

\n

\nWe shall call a positive integer with this property a strong repunit. It can be verified that there are $8$ strong repunits below $50$: $\\{1,7,13,15,21,31,40,43\\}$.
\nFurthermore, the sum of all strong repunits below $1000$ equals $15864$.\n

\nFind the sum of all strong repunits below $10^{12}$.", "url": "https://projecteuler.net/problem=346", "answer": "336108797689259276"} {"id": 347, "problem": "The largest integer $\\le 100$ that is only divisible by both the primes $2$ and $3$ is $96$, as $96=32\\times 3=2^5 \\times 3$.\nFor two distinct primes $p$ and $q$ let $M(p,q,N)$ be the largest positive integer $\\le N$ only divisible by both $p$ and $q$ and $M(p,q,N)=0$ if such a positive integer does not exist.\n\nE.g. $M(2,3,100)=96$.\n\n$M(3,5,100)=75$ and not $90$ because $90$ is divisible by $2$, $3$ and $5$.\n\nAlso $M(2,73,100)=0$ because there does not exist a positive integer $\\le 100$ that is divisible by both $2$ and $73$.\n\nLet $S(N)$ be the sum of all distinct $M(p,q,N)$.\n$S(100)=2262$.\n\nFind $S(10\\,000\\,000)$.", "raw_html": "

\nThe largest integer $\\le 100$ that is only divisible by both the primes $2$ and $3$ is $96$, as $96=32\\times 3=2^5 \\times 3$.\nFor two distinct primes $p$ and $q$ let $M(p,q,N)$ be the largest positive integer $\\le N$ only divisible by both $p$ and $q$ and $M(p,q,N)=0$ if such a positive integer does not exist.\n

\n

\nE.g. $M(2,3,100)=96$.
\n$M(3,5,100)=75$ and not $90$ because $90$ is divisible by $2$, $3$ and $5$.
\nAlso $M(2,73,100)=0$ because there does not exist a positive integer $\\le 100$ that is divisible by both $2$ and $73$.\n

\n

\nLet $S(N)$ be the sum of all distinct $M(p,q,N)$.\n$S(100)=2262$.\n

\n

\nFind $S(10\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=347", "answer": "11109800204052"} {"id": 348, "problem": "Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.\n\nConsider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than $1$, in exactly $4$ different ways.\n\nFor example, $5229225$ is a palindromic number and it can be expressed in exactly $4$ different ways:\n\n$2285^2 + 20^3$\n\n$2223^2 + 66^3$\n\n$1810^2 + 125^3$\n\n$1197^2 + 156^3$\n\n\nFind the sum of the five smallest such palindromic numbers.", "raw_html": "

Many numbers can be expressed as the sum of a square and a cube. Some of them in more than one way.

\n\n

Consider the palindromic numbers that can be expressed as the sum of a square and a cube, both greater than $1$, in exactly $4$ different ways.
\nFor example, $5229225$ is a palindromic number and it can be expressed in exactly $4$ different ways:

\n

$2285^2 + 20^3$
\n$2223^2 + 66^3$
\n$1810^2 + 125^3$
\n$1197^2 + 156^3$

\n \n

Find the sum of the five smallest such palindromic numbers.

", "url": "https://projecteuler.net/problem=348", "answer": "1004195061"} {"id": 349, "problem": "An ant moves on a regular grid of squares that are coloured either black or white.\n\nThe ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules:\n\n- if it is on a black square, it flips the colour of the square to white, rotates $90$ degrees counterclockwise and moves forward one square.\n\n- if it is on a white square, it flips the colour of the square to black, rotates $90$ degrees clockwise and moves forward one square.\n\nStarting with a grid that is entirely white, how many squares are black after $10^{18}$ moves of the ant?", "raw_html": "

\nAn ant moves on a regular grid of squares that are coloured either black or white.
\nThe ant is always oriented in one of the cardinal directions (left, right, up or down) and moves from square to adjacent square according to the following rules:
\n- if it is on a black square, it flips the colour of the square to white, rotates $90$ degrees counterclockwise and moves forward one square.
\n- if it is on a white square, it flips the colour of the square to black, rotates $90$ degrees clockwise and moves forward one square.

\n

\nStarting with a grid that is entirely white, how many squares are black after $10^{18}$ moves of the ant?\n

", "url": "https://projecteuler.net/problem=349", "answer": "115384615384614952"} {"id": 350, "problem": "A list of size $n$ is a sequence of $n$ natural numbers.\nExamples are $(2,4,6)$, $(2,6,4)$, $(10,6,15,6)$, and $(11)$.\n\nThe greatest common divisor, or $\\gcd$, of a list is the largest natural number that divides all entries of the list.\nExamples: $\\gcd(2,6,4) = 2$, $\\gcd(10,6,15,6) = 1$ and $\\gcd(11) = 11$.\n\nThe least common multiple, or $\\operatorname{lcm}$, of a list is the smallest natural number divisible by each entry of the list.\nExamples: $\\operatorname{lcm}(2,6,4) = 12$, $\\operatorname{lcm}(10,6,15,6) = 30$ and $\\operatorname{lcm}(11) = 11$.\n\nLet $f(G, L, N)$ be the number of lists of size $N$ with $\\gcd \\ge G$ and $\\operatorname{lcm} \\le L$. For example:\n\n$f(10, 100, 1) = 91$.\n\n$f(10, 100, 2) = 327$.\n\n$f(10, 100, 3) = 1135$.\n\n$f(10, 100, 1000) \\bmod 101^4 = 3286053$.\n\nFind $f(10^6, 10^{12}, 10^{18}) \\bmod 101^4$.", "raw_html": "

A list of size $n$ is a sequence of $n$ natural numbers.
Examples are $(2,4,6)$, $(2,6,4)$, $(10,6,15,6)$, and $(11)$.\n

\nThe greatest common divisor, or $\\gcd$, of a list is the largest natural number that divides all entries of the list.
Examples: $\\gcd(2,6,4) = 2$, $\\gcd(10,6,15,6) = 1$ and $\\gcd(11) = 11$.\n

\nThe least common multiple, or $\\operatorname{lcm}$, of a list is the smallest natural number divisible by each entry of the list.
Examples: $\\operatorname{lcm}(2,6,4) = 12$, $\\operatorname{lcm}(10,6,15,6) = 30$ and $\\operatorname{lcm}(11) = 11$.\n

\nLet $f(G, L, N)$ be the number of lists of size $N$ with $\\gcd \\ge G$ and $\\operatorname{lcm} \\le L$. For example:\n

\n$f(10, 100, 1) = 91$.
\n$f(10, 100, 2) = 327$.
\n$f(10, 100, 3) = 1135$.
\n$f(10, 100, 1000) \\bmod 101^4 = 3286053$.\n

\nFind $f(10^6, 10^{12}, 10^{18}) \\bmod 101^4$.\n

", "url": "https://projecteuler.net/problem=350", "answer": "84664213"} {"id": 351, "problem": "A hexagonal orchard of order $n$ is a triangular lattice made up of points within a regular hexagon with side $n$. The following is an example of a hexagonal orchard of order $5$:\n\nHighlighted in green are the points which are hidden from the center by a point closer to it. It can be seen that for a hexagonal orchard of order $5$, $30$ points are hidden from the center.\n\nLet $H(n)$ be the number of points hidden from the center in a hexagonal orchard of order $n$.\n\n$H(5) = 30$. $H(10) = 138$. $H(1\\,000) = 1177848$.\n\nFind $H(100\\,000\\,000)$.", "raw_html": "

A hexagonal orchard of order $n$ is a triangular lattice made up of points within a regular hexagon with side $n$. The following is an example of a hexagonal orchard of order $5$:\n

\n\n
\n\"0351_hexorchard.png\"
\n\n

\nHighlighted in green are the points which are hidden from the center by a point closer to it. It can be seen that for a hexagonal orchard of order $5$, $30$ points are hidden from the center.\n

\n\n

\nLet $H(n)$ be the number of points hidden from the center in a hexagonal orchard of order $n$.\n

\n\n

\n$H(5) = 30$. $H(10) = 138$. $H(1\\,000) = 1177848$.\n

\n\n

\nFind $H(100\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=351", "answer": "11762187201804552"} {"id": 352, "problem": "Each one of the $25$ sheep in a flock must be tested for a rare virus, known to affect $2\\%$ of the sheep population.\nAn accurate and extremely sensitive PCR test exists for blood samples, producing a clear positive / negative result, but it is very time-consuming and expensive.\n\nBecause of the high cost, the vet-in-charge suggests that instead of performing $25$ separate tests, the following procedure can be used instead:\n\nThe sheep are split into $5$ groups of $5$ sheep in each group.\nFor each group, the $5$ samples are mixed together and a single test is performed. Then,\n\n- If the result is negative, all the sheep in that group are deemed to be virus-free.\n\n- If the result is positive, $5$ additional tests will be performed (a separate test for each animal) to determine the affected individual(s).\n\nSince the probability of infection for any specific animal is only $0.02$, the first test (on the pooled samples) for each group will be:\n\n- Negative (and no more tests needed) with probability $0.98^5 = 0.9039207968$.\n\n- Positive ($5$ additional tests needed) with probability $1 - 0.9039207968 = 0.0960792032$.\n\nThus, the expected number of tests for each group is $1 + 0.0960792032 \\times 5 = 1.480396016$.\n\nConsequently, all $5$ groups can be screened using an average of only $1.480396016 \\times 5 = \\mathbf{7.40198008}$ tests, which represents a huge saving of more than $70\\%$!\n\nAlthough the scheme we have just described seems to be very efficient, it can still be improved considerably (always assuming that the test is sufficiently sensitive and that there are no adverse effects caused by mixing different samples). E.g.:\n\n- We may start by running a test on a mixture of all the $25$ samples. It can be verified that in about $60.35\\%$ of the cases this test will be negative, thus no more tests will be needed. Further testing will only be required for the remaining $39.65\\%$ of the cases.\n\n- If we know that at least one animal in a group of $5$ is infected and the first $4$ individual tests come out negative, there is no need to run a test on the fifth animal (we know that it must be infected).\n\n- We can try a different number of groups / different number of animals in each group, adjusting those numbers at each level so that the total expected number of tests will be minimised.\n\nTo simplify the very wide range of possibilities, there is one restriction we place when devising the most cost-efficient testing scheme: whenever we start with a mixed sample, all the sheep contributing to that sample must be fully screened (i.e. a verdict of infected / virus-free must be reached for all of them) before we start examining any other animals.\n\nFor the current example, it turns out that the most cost-efficient testing scheme (we'll call it the optimal strategy) requires an average of just $\\mathbf{4.155452}$ tests!\n\nUsing the optimal strategy, let $T(s,p)$ represent the average number of tests needed to screen a flock of $s$ sheep for a virus having probability $p$ to be present in any individual.\n\nThus, rounded to six decimal places, $T(25, 0.02) = 4.155452$ and $T(25, 0.10) = 12.702124$.\n\nFind $\\sum T(10000, p)$ for $p=0.01, 0.02, 0.03, \\dots 0.50$.\n\nGive your answer rounded to six decimal places.", "raw_html": "

\nEach one of the $25$ sheep in a flock must be tested for a rare virus, known to affect $2\\%$ of the sheep population.\nAn accurate and extremely sensitive PCR test exists for blood samples, producing a clear positive / negative result, but it is very time-consuming and expensive.\n

\n\n

\nBecause of the high cost, the vet-in-charge suggests that instead of performing $25$ separate tests, the following procedure can be used instead:

\nThe sheep are split into $5$ groups of $5$ sheep in each group. \nFor each group, the $5$ samples are mixed together and a single test is performed. Then,\n

\nSince the probability of infection for any specific animal is only $0.02$, the first test (on the pooled samples) for each group will be:\n

\nThus, the expected number of tests for each group is $1 + 0.0960792032 \\times 5 = 1.480396016$.
\nConsequently, all $5$ groups can be screened using an average of only $1.480396016 \\times 5 = \\mathbf{7.40198008}$ tests, which represents a huge saving of more than $70\\%$!\n

\n\n

\nAlthough the scheme we have just described seems to be very efficient, it can still be improved considerably (always assuming that the test is sufficiently sensitive and that there are no adverse effects caused by mixing different samples). E.g.:\n

\nTo simplify the very wide range of possibilities, there is one restriction we place when devising the most cost-efficient testing scheme: whenever we start with a mixed sample, all the sheep contributing to that sample must be fully screened (i.e. a verdict of infected / virus-free must be reached for all of them) before we start examining any other animals.\n

\nFor the current example, it turns out that the most cost-efficient testing scheme (we'll call it the optimal strategy) requires an average of just $\\mathbf{4.155452}$ tests!\n\n\n

\nUsing the optimal strategy, let $T(s,p)$ represent the average number of tests needed to screen a flock of $s$ sheep for a virus having probability $p$ to be present in any individual.
\nThus, rounded to six decimal places, $T(25, 0.02) = 4.155452$ and $T(25, 0.10) = 12.702124$.\n

\n\n

\nFind $\\sum T(10000, p)$ for $p=0.01, 0.02, 0.03, \\dots 0.50$.
\nGive your answer rounded to six decimal places.\n

", "url": "https://projecteuler.net/problem=352", "answer": "378563.260589"} {"id": 353, "problem": "A moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$.\n\nThere are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.\n\nAll stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If d is the length of the road between two stations, $\\left(\\frac{d}{\\pi r}\\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.\n\nA direct journey from the North Pole station to the South Pole station has the length $\\pi r$ and risk $1$. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:\n\n$$\n\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2+\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2=0.5\n$$\n\nThe minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.\n\nYou are given that $M(7)=0.1784943998$ rounded to $10$ digits behind the decimal point.\n\nFind $\\displaystyle{\\sum_{n=1}^{15}M(2^n-1)}$.\n\nGive your answer rounded to $10$ digits behind the decimal point in the form a.bcdefghijk.", "raw_html": "

\nA moon could be described by the sphere $C(r)$ with centre $(0,0,0)$ and radius $r$. \n

\n\n

\nThere are stations on the moon at the points on the surface of $C(r)$ with integer coordinates. The station at $(0,0,r)$ is called North Pole station, the station at $(0,0,-r)$ is called South Pole station.\n

\n\n

\nAll stations are connected with each other via the shortest road on the great arc through the stations. A journey between two stations is risky. If d is the length of the road between two stations, $\\left(\\frac{d}{\\pi r}\\right)^2$ is a measure for the risk of the journey (let us call it the risk of the road). If the journey includes more than two stations, the risk of the journey is the sum of risks of the used roads.\n

\n\n

\nA direct journey from the North Pole station to the South Pole station has the length $\\pi r$ and risk $1$. The journey from the North Pole station to the South Pole station via $(0,r,0)$ has the same length, but a smaller risk:

\n$$\n\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2+\\left(\\frac{\\frac{1}{2}\\pi r}{\\pi r}\\right)^2=0.5\n$$\n\n

\nThe minimal risk of a journey from the North Pole station to the South Pole station on $C(r)$ is $M(r)$.\n

\n\n

\nYou are given that $M(7)=0.1784943998$ rounded to $10$ digits behind the decimal point. \n

\n\n

\nFind $\\displaystyle{\\sum_{n=1}^{15}M(2^n-1)}$.\n

\n\n

\nGive your answer rounded to $10$ digits behind the decimal point in the form a.bcdefghijk.\n

", "url": "https://projecteuler.net/problem=353", "answer": "1.2759860331"} {"id": 354, "problem": "Consider a honey bee's honeycomb where each cell is a perfect regular hexagon with side length $1$.\n\nOne particular cell is occupied by the queen bee.\n\nFor a positive real number $L$, let $\\text{B}(L)$ count the cells with distance $L$ from the queen bee cell (all distances are measured from centre to centre); you may assume that the honeycomb is large enough to accommodate for any distance we wish to consider.\n\nFor example, $\\text{B}(\\sqrt 3)=6$, $\\text{B}(\\sqrt {21}) = 12$ and $\\text{B}(111\\,111\\,111) = 54$.\n\nFind the number of $L \\le 5 \\times 10^{11}$ such that $\\text{B}(L) = 450$.", "raw_html": "

Consider a honey bee's honeycomb where each cell is a perfect regular hexagon with side length $1$.

\n\n
\n\"0354_bee_honeycomb.png\"
\n\n\n

\nOne particular cell is occupied by the queen bee.
\nFor a positive real number $L$, let $\\text{B}(L)$ count the cells with distance $L$ from the queen bee cell (all distances are measured from centre to centre); you may assume that the honeycomb is large enough to accommodate for any distance we wish to consider.
\nFor example, $\\text{B}(\\sqrt 3)=6$, $\\text{B}(\\sqrt {21}) = 12$ and $\\text{B}(111\\,111\\,111) = 54$.

\n\n

Find the number of $L \\le 5 \\times 10^{11}$ such that $\\text{B}(L) = 450$.

", "url": "https://projecteuler.net/problem=354", "answer": "58065134"} {"id": 355, "problem": "Define $\\operatorname{Co}(n)$ to be the maximal possible sum of a set of mutually co-prime elements from $\\{1,2,\\dots,n\\}$.\nFor example $\\operatorname{Co}(10)$ is $30$ and hits that maximum on the subset $\\{1,5,7,8,9\\}$.\n\nYou are given that $\\operatorname{Co}(30) = 193$ and $\\operatorname{Co}(100) = 1356$.\n\nFind $\\operatorname{Co}(200000)$.", "raw_html": "

\nDefine $\\operatorname{Co}(n)$ to be the maximal possible sum of a set of mutually co-prime elements from $\\{1,2,\\dots,n\\}$.
For example $\\operatorname{Co}(10)$ is $30$ and hits that maximum on the subset $\\{1,5,7,8,9\\}$.\n

\n\n

\nYou are given that $\\operatorname{Co}(30) = 193$ and $\\operatorname{Co}(100) = 1356$. \n

\n\n

Find $\\operatorname{Co}(200000)$.\n

", "url": "https://projecteuler.net/problem=355", "answer": "1726545007"} {"id": 356, "problem": "Let $a_n$ be the largest real root of a polynomial $g(x) = x^3 - 2^n \\cdot x^2 + n$.\n\nFor example, $a_2 = 3.86619826\\cdots$\n\nFind the last eight digits of $\\sum \\limits_{i = 1}^{30} \\lfloor a_i^{987654321} \\rfloor$.\n\nNote: $\\lfloor a \\rfloor$ represents the floor function.", "raw_html": "

\nLet $a_n$ be the largest real root of a polynomial $g(x) = x^3 - 2^n \\cdot x^2 + n$.
\nFor example, $a_2 = 3.86619826\\cdots$

\n\n

\nFind the last eight digits of $\\sum \\limits_{i = 1}^{30} \\lfloor a_i^{987654321} \\rfloor$.

\n\n

\nNote: $\\lfloor a \\rfloor$ represents the floor function.

", "url": "https://projecteuler.net/problem=356", "answer": "28010159"} {"id": 357, "problem": "Consider the divisors of $30$: $1,2,3,5,6,10,15,30$.\n\nIt can be seen that for every divisor $d$ of $30$, $d + 30 / d$ is prime.\n\nFind the sum of all positive integers $n$ not exceeding $100\\,000\\,000$\nsuch that for every divisor $d$ of $n$, $d + n / d$ is prime.", "raw_html": "

\nConsider the divisors of $30$: $1,2,3,5,6,10,15,30$.
\nIt can be seen that for every divisor $d$ of $30$, $d + 30 / d$ is prime.\n

\n

\nFind the sum of all positive integers $n$ not exceeding $100\\,000\\,000$
such that for every divisor $d$ of $n$, $d + n / d$ is prime.\n

", "url": "https://projecteuler.net/problem=357", "answer": "1739023853137"} {"id": 358, "problem": "A cyclic number with $n$ digits has a very interesting property:\n\nWhen it is multiplied by $1, 2, 3, 4, \\dots, n$, all the products have exactly the same digits, in the same order, but rotated in a circular fashion!\n\nThe smallest cyclic number is the $6$-digit number $142857$:\n\n$142857 \\times 1 = 142857$\n\n$142857 \\times 2 = 285714$\n\n$142857 \\times 3 = 428571$\n\n$142857 \\times 4 = 571428$\n\n$142857 \\times 5 = 714285$\n\n$142857 \\times 6 = 857142$\n\nThe next cyclic number is $0588235294117647$ with $16$ digits :\n\n$0588235294117647 \\times 1 = 0588235294117647$\n\n$0588235294117647 \\times 2 = 1176470588235294$\n\n$0588235294117647 \\times 3 = 1764705882352941$\n\n$\\dots$\n\n$0588235294117647 \\times 16 = 9411764705882352$\n\nNote that for cyclic numbers, leading zeros are important.\n\nThere is only one cyclic number for which, the eleven leftmost digits are $00000000137$ and the five rightmost digits are $56789$ (i.e., it has the form $00000000137 \\cdots 56789$ with an unknown number of digits in the middle). Find the sum of all its digits.", "raw_html": "

A cyclic number with $n$ digits has a very interesting property:
\nWhen it is multiplied by $1, 2, 3, 4, \\dots, n$, all the products have exactly the same digits, in the same order, but rotated in a circular fashion!\n

\n\n

\nThe smallest cyclic number is the $6$-digit number $142857$:
\n$142857 \\times 1 = 142857$
\n$142857 \\times 2 = 285714$
\n$142857 \\times 3 = 428571$
\n$142857 \\times 4 = 571428$
\n$142857 \\times 5 = 714285$
\n$142857 \\times 6 = 857142$\n

\n\n

\nThe next cyclic number is $0588235294117647$ with $16$ digits :
\n$0588235294117647 \\times 1 = 0588235294117647$
\n$0588235294117647 \\times 2 = 1176470588235294$
\n$0588235294117647 \\times 3 = 1764705882352941$
\n$\\dots$
\n$0588235294117647 \\times 16 = 9411764705882352$\n

\n\n

\nNote that for cyclic numbers, leading zeros are important.\n

\n\n

\nThere is only one cyclic number for which, the eleven leftmost digits are $00000000137$ and the five rightmost digits are $56789$ (i.e., it has the form $00000000137 \\cdots 56789$ with an unknown number of digits in the middle). Find the sum of all its digits.\n

", "url": "https://projecteuler.net/problem=358", "answer": "3284144505"} {"id": 359, "problem": "An infinite number of people (numbered $1$, $2$, $3$, etc.) are lined up to get a room at Hilbert's newest infinite hotel. The hotel contains an infinite number of floors (numbered $1$, $2$, $3$, etc.), and each floor contains an infinite number of rooms (numbered $1$, $2$, $3$, etc.).\n\nInitially the hotel is empty. Hilbert declares a rule on how the $n$th person is assigned a room: person $n$ gets the first vacant room in the lowest numbered floor satisfying either of the following:\n\n- the floor is empty\n\n- the floor is not empty, and if the latest person taking a room in that floor is person $m$, then $m + n$ is a perfect square\n\nPerson $1$ gets room $1$ in floor $1$ since floor $1$ is empty.\n\nPerson $2$ does not get room $2$ in floor $1$ since $1 + 2 = 3$ is not a perfect square.\n\nPerson $2$ instead gets room $1$ in floor $2$ since floor $2$ is empty.\n\nPerson $3$ gets room $2$ in floor $1$ since $1 + 3 = 4$ is a perfect square.\n\nEventually, every person in the line gets a room in the hotel.\n\nDefine $P(f, r)$ to be $n$ if person $n$ occupies room $r$ in floor $f$, and $0$ if no person occupies the room. Here are a few examples:\n\n$P(1, 1) = 1$\n\n$P(1, 2) = 3$\n\n$P(2, 1) = 2$\n\n$P(10, 20) = 440$\n\n$P(25, 75) = 4863$\n\n$P(99, 100) = 19454$\n\nFind the sum of all $P(f, r)$ for all positive $f$ and $r$ such that $f \\times r = 71328803586048$ and give the last $8$ digits as your answer.", "raw_html": "

\nAn infinite number of people (numbered $1$, $2$, $3$, etc.) are lined up to get a room at Hilbert's newest infinite hotel. The hotel contains an infinite number of floors (numbered $1$, $2$, $3$, etc.), and each floor contains an infinite number of rooms (numbered $1$, $2$, $3$, etc.). \n

\n\n

\nInitially the hotel is empty. Hilbert declares a rule on how the $n$th person is assigned a room: person $n$ gets the first vacant room in the lowest numbered floor satisfying either of the following:\n

\nPerson $1$ gets room $1$ in floor $1$ since floor $1$ is empty.\n
Person $2$ does not get room $2$ in floor $1$ since $1 + 2 = 3$ is not a perfect square.\n
Person $2$ instead gets room $1$ in floor $2$ since floor $2$ is empty.\n
Person $3$ gets room $2$ in floor $1$ since $1 + 3 = 4$ is a perfect square.\n

\n\n

\nEventually, every person in the line gets a room in the hotel.\n

\n\n

\nDefine $P(f, r)$ to be $n$ if person $n$ occupies room $r$ in floor $f$, and $0$ if no person occupies the room. Here are a few examples:\n
$P(1, 1) = 1$\n
$P(1, 2) = 3$\n
$P(2, 1) = 2$\n
$P(10, 20) = 440$\n
$P(25, 75) = 4863$\n
$P(99, 100) = 19454$\n

\n\n

\nFind the sum of all $P(f, r)$ for all positive $f$ and $r$ such that $f \\times r = 71328803586048$ and give the last $8$ digits as your answer.\n

", "url": "https://projecteuler.net/problem=359", "answer": "40632119"} {"id": 360, "problem": "Given two points $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$ in three dimensional space, the Manhattan distance between those points is defined as\n$|x_1 - x_2| + |y_1 - y_2| + |z_1 - z_2|$.\n\nLet $C(r)$ be a sphere with radius $r$ and center in the origin $O(0,0,0)$.\n\nLet $I(r)$ be the set of all points with integer coordinates on the surface of $C(r)$.\n\nLet $S(r)$ be the sum of the Manhattan distances of all elements of $I(r)$ to the origin $O$.\n\nE.g. $S(45)=34518$.\n\nFind $S(10^{10})$.", "raw_html": "

\nGiven two points $(x_1, y_1, z_1)$ and $(x_2, y_2, z_2)$ in three dimensional space, the Manhattan distance between those points is defined as
$|x_1 - x_2| + |y_1 - y_2| + |z_1 - z_2|$.\n

\n

\nLet $C(r)$ be a sphere with radius $r$ and center in the origin $O(0,0,0)$.
\nLet $I(r)$ be the set of all points with integer coordinates on the surface of $C(r)$.
\nLet $S(r)$ be the sum of the Manhattan distances of all elements of $I(r)$ to the origin $O$.\n

\n

\nE.g. $S(45)=34518$.\n

\n

\nFind $S(10^{10})$.\n

", "url": "https://projecteuler.net/problem=360", "answer": "878825614395267072"} {"id": 361, "problem": "The Thue-Morse sequence $\\{T_n\\}$ is a binary sequence satisfying:\n\n- $T_0 = 0$\n\n- $T_{2n} = T_n$\n\n- $T_{2n + 1} = 1 - T_n$\n\nThe first several terms of $\\{T_n\\}$ are given as follows:\n\n$01101001{\\color{red}10010}1101001011001101001\\cdots$\n\nWe define $\\{A_n\\}$ as the sorted sequence of integers such that the binary expression of each element appears as a subsequence in $\\{T_n\\}$.\n\nFor example, the decimal number $18$ is expressed as $10010$ in binary. $10010$ appears in $\\{T_n\\}$ ($T_8$ to $T_{12}$), so $18$ is an element of $\\{A_n\\}$.\n\nThe decimal number $14$ is expressed as $1110$ in binary. $1110$ never appears in $\\{T_n\\}$, so $14$ is not an element of $\\{A_n\\}$.\n\nThe first several terms of $\\{A_n\\}$ are given as follows:\n\n| $n$ | $0$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ | $8$ | $9$ | $10$ | $11$ | $12$ | $\\cdots$ |\n| $A_n$ | $0$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $9$ | $10$ | $11$ | $12$ | $13$ | $18$ | $\\cdots$ |\n\nWe can also verify that $A_{100} = 3251$ and $A_{1000} = 80852364498$.\n\nFind the last $9$ digits of $\\sum \\limits_{k = 1}^{18} A_{10^k}$.", "raw_html": "

The Thue-Morse sequence $\\{T_n\\}$ is a binary sequence satisfying:

\n

\nThe first several terms of $\\{T_n\\}$ are given as follows:
\n$01101001{\\color{red}10010}1101001011001101001\\cdots$\n

\n\n

\nWe define $\\{A_n\\}$ as the sorted sequence of integers such that the binary expression of each element appears as a subsequence in $\\{T_n\\}$.
\nFor example, the decimal number $18$ is expressed as $10010$ in binary. $10010$ appears in $\\{T_n\\}$ ($T_8$ to $T_{12}$), so $18$ is an element of $\\{A_n\\}$.
\nThe decimal number $14$ is expressed as $1110$ in binary. $1110$ never appears in $\\{T_n\\}$, so $14$ is not an element of $\\{A_n\\}$.\n

\n\n

\nThe first several terms of $\\{A_n\\}$ are given as follows:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$n$$0$$1$$2$$3$$4$$5$$6$$7$$8$$9$$10$$11$$12$$\\cdots$
$A_n$$0$$1$$2$$3$$4$$5$$6$$9$$10$$11$$12$$13$$18$$\\cdots$
\n\n

\nWe can also verify that $A_{100} = 3251$ and $A_{1000} = 80852364498$.\n

\n\n

\nFind the last $9$ digits of $\\sum \\limits_{k = 1}^{18} A_{10^k}$.\n

", "url": "https://projecteuler.net/problem=361", "answer": "178476944"} {"id": 362, "problem": "Consider the number $54$.\n\n$54$ can be factored in $7$ distinct ways into one or more factors larger than $1$:\n\n$54$, $2 \\times 27$, $3 \\times 18$, $6 \\times 9$, $3 \\times 3 \\times 6$, $2 \\times 3 \\times 9$ and $2 \\times 3 \\times 3 \\times 3$.\n\nIf we require that the factors are all squarefree only two ways remain: $3 \\times 3 \\times 6$ and $2 \\times 3 \\times 3 \\times 3$.\n\nLet's call $\\operatorname{Fsf}(n)$ the number of ways $n$ can be factored into one or more squarefree factors larger than $1$, so\n$\\operatorname{Fsf}(54)=2$.\n\nLet $S(n)$ be $\\sum \\operatorname{Fsf}(k)$ for $k=2$ to $n$.\n\n$S(100)=193$.\n\nFind $S(10\\,000\\,000\\,000)$.", "raw_html": "

\nConsider the number $54$.
\n$54$ can be factored in $7$ distinct ways into one or more factors larger than $1$:
\n$54$, $2 \\times 27$, $3 \\times 18$, $6 \\times 9$, $3 \\times 3 \\times 6$, $2 \\times 3 \\times 9$ and $2 \\times 3 \\times 3 \\times 3$.
\nIf we require that the factors are all squarefree only two ways remain: $3 \\times 3 \\times 6$ and $2 \\times 3 \\times 3 \\times 3$.\n

\n

\nLet's call $\\operatorname{Fsf}(n)$ the number of ways $n$ can be factored into one or more squarefree factors larger than $1$, so\n$\\operatorname{Fsf}(54)=2$.\n

\n

\nLet $S(n)$ be $\\sum \\operatorname{Fsf}(k)$ for $k=2$ to $n$.\n

\n

\n$S(100)=193$.\n

\n

\nFind $S(10\\,000\\,000\\,000)$. \n

", "url": "https://projecteuler.net/problem=362", "answer": "457895958010"} {"id": 363, "problem": "A cubic Bézier curve is defined by four points: $P_0, P_1, P_2,$ and $P_3$.\n\nThe curve is constructed as follows:\n\nOn the segments $P_0 P_1$, $P_1 P_2$, and $P_2 P_3$ the points $Q_0, Q_1,$ and $Q_2$ are drawn such that $\\dfrac{P_0 Q_0}{P_0 P_1} = \\dfrac{P_1 Q_1}{P_1 P_2} = \\dfrac{P_2 Q_2}{P_2 P_3} = t$, with $t$ in $[0, 1]$.\n\nOn the segments $Q_0 Q_1$ and $Q_1 Q_2$ the points $R_0$ and $R_1$ are drawn such that\n\n$\\dfrac{Q_0 R_0}{Q_0 Q_1} = \\dfrac{Q_1 R_1}{Q_1 Q_2} = t$ for the same value of $t$.\n\nOn the segment $R_0 R_1$ the point $B$ is drawn such that $\\dfrac{R_0 B}{R_0 R_1} = t$ for the same value of $t$.\n\nThe Bézier curve defined by the points $P_0, P_1, P_2, P_3$ is the locus of $B$ as $Q_0$ takes all possible positions on the segment $P_0 P_1$.\n\n(Please note that for all points the value of $t$ is the same.)\n\nFrom the construction it is clear that the Bézier curve will be tangent to the segments $P_0 P_1$ in $P_0$ and $P_2 P_3$ in $P_3$.\n\nA cubic Bézier curve with $P_0 = (1, 0), P_1 = (1, v), P_2 = (v, 1),$ and $P_3 = (0, 1)$ is used to approximate a quarter circle.\n\nThe value $v \\gt 0$ is chosen such that the area enclosed by the lines $O P_0, OP_3$ and the curve is equal to $\\dfrac{\\pi}{4}$ (the area of the quarter circle).\n\nBy how many percent does the length of the curve differ from the length of the quarter circle?\n\nThat is, if $L$ is the length of the curve, calculate $100 \\times \\dfrac{L - \\frac{\\pi}{2}}{\\frac{\\pi}{2}}$\n\nGive your answer rounded to 10 digits behind the decimal point.", "raw_html": "

A cubic Bézier curve is defined by four points: $P_0, P_1, P_2,$ and $P_3$.

\n\n
\"0363_bezier.png\"
\n\n

The curve is constructed as follows:

\n\n

On the segments $P_0 P_1$, $P_1 P_2$, and $P_2 P_3$ the points $Q_0, Q_1,$ and $Q_2$ are drawn such that $\\dfrac{P_0 Q_0}{P_0 P_1} = \\dfrac{P_1 Q_1}{P_1 P_2} = \\dfrac{P_2 Q_2}{P_2 P_3} = t$, with $t$ in $[0, 1]$.

\n\n

On the segments $Q_0 Q_1$ and $Q_1 Q_2$ the points $R_0$ and $R_1$ are drawn such that
\n$\\dfrac{Q_0 R_0}{Q_0 Q_1} = \\dfrac{Q_1 R_1}{Q_1 Q_2} = t$ for the same value of $t$.

\n\n

On the segment $R_0 R_1$ the point $B$ is drawn such that $\\dfrac{R_0 B}{R_0 R_1} = t$ for the same value of $t$.

\n\n

The Bézier curve defined by the points $P_0, P_1, P_2, P_3$ is the locus of $B$ as $Q_0$ takes all possible positions on the segment $P_0 P_1$.
\n(Please note that for all points the value of $t$ is the same.)

\n\n\n\n

From the construction it is clear that the Bézier curve will be tangent to the segments $P_0 P_1$ in $P_0$ and $P_2 P_3$ in $P_3$.

\n\n

A cubic Bézier curve with $P_0 = (1, 0), P_1 = (1, v), P_2 = (v, 1),$ and $P_3 = (0, 1)$ is used to approximate a quarter circle.
\nThe value $v \\gt 0$ is chosen such that the area enclosed by the lines $O P_0, OP_3$ and the curve is equal to $\\dfrac{\\pi}{4}$ (the area of the quarter circle).

\n\n

By how many percent does the length of the curve differ from the length of the quarter circle?
\nThat is, if $L$ is the length of the curve, calculate $100 \\times \\dfrac{L - \\frac{\\pi}{2}}{\\frac{\\pi}{2}}$
\nGive your answer rounded to 10 digits behind the decimal point.

", "url": "https://projecteuler.net/problem=363", "answer": "0.0000372091"} {"id": 364, "problem": "There are $N$ seats in a row. $N$ people come after each other to fill the seats according to the following rules:\n\n- If there is any seat whose adjacent seat(s) are not occupied take such a seat.\n\n- If there is no such seat and there is any seat for which only one adjacent seat is occupied take such a seat.\n\n- Otherwise take one of the remaining available seats.\n\nLet $T(N)$ be the number of possibilities that $N$ seats are occupied by $N$ people with the given rules.\nThe following figure shows $T(4)=8$.\n\nWe can verify that $T(10) = 61632$ and $T(1\\,000) \\bmod 100\\,000\\,007 = 47255094$.\n\nFind $T(1\\,000\\,000) \\bmod 100\\,000\\,007$.", "raw_html": "

\nThere are $N$ seats in a row. $N$ people come after each other to fill the seats according to the following rules:\n

  1. If there is any seat whose adjacent seat(s) are not occupied take such a seat.
  2. \n
  3. If there is no such seat and there is any seat for which only one adjacent seat is occupied take such a seat.
  4. \n
  5. Otherwise take one of the remaining available seats.
  6. \n
\nLet $T(N)$ be the number of possibilities that $N$ seats are occupied by $N$ people with the given rules.
The following figure shows $T(4)=8$.\n\n\n
\n\"0364_comf_dist.gif\"
\n\n

We can verify that $T(10) = 61632$ and $T(1\\,000) \\bmod 100\\,000\\,007 = 47255094$.

\n

Find $T(1\\,000\\,000) \\bmod 100\\,000\\,007$.

", "url": "https://projecteuler.net/problem=364", "answer": "44855254"} {"id": 365, "problem": "The binomial coefficient $\\displaystyle{\\binom{10^{18}}{10^9}}$ is a number with more than $9$ billion ($9\\times 10^9$) digits.\n\nLet $M(n,k,m)$ denote the binomial coefficient $\\displaystyle{\\binom{n}{k}}$ modulo $m$.\n\nCalculate $\\displaystyle{\\sum M(10^{18},10^9,p\\cdot q\\cdot r)}$ for $1000\\lt p\\lt q\\lt r\\lt 5000$ and $p$,$q$,$r$ prime.", "raw_html": "

\nThe binomial coefficient $\\displaystyle{\\binom{10^{18}}{10^9}}$ is a number with more than $9$ billion ($9\\times 10^9$) digits.\n

\n

\nLet $M(n,k,m)$ denote the binomial coefficient $\\displaystyle{\\binom{n}{k}}$ modulo $m$.\n

\n

\nCalculate $\\displaystyle{\\sum M(10^{18},10^9,p\\cdot q\\cdot r)}$ for $1000\\lt p\\lt q\\lt r\\lt 5000$ and $p$,$q$,$r$ prime.\n

", "url": "https://projecteuler.net/problem=365", "answer": "162619462356610313"} {"id": 366, "problem": "Two players, Anton and Bernhard, are playing the following game.\n\nThere is one pile of $n$ stones.\n\nThe first player may remove any positive number of stones, but not the whole pile.\n\nThereafter, each player may remove at most twice the number of stones his opponent took on the previous move.\n\nThe player who removes the last stone wins.\n\nE.g. $n=5$.\n\nIf the first player takes anything more than one stone the next player will be able to take all remaining stones.\n\nIf the first player takes one stone, leaving four, his opponent will take also one stone, leaving three stones.\n\nThe first player cannot take all three because he may take at most $2 \\times 1=2$ stones. So let's say he takes also one stone, leaving $2$. The second player can take the two remaining stones and wins.\n\nSo $5$ is a losing position for the first player.\n\nFor some winning positions there is more than one possible move for the first player.\n\nE.g. when $n=17$ the first player can remove one or four stones.\n\nLet $M(n)$ be the maximum number of stones the first player can take from a winning position at his first turn and $M(n)=0$ for any other position.\n\n$\\sum M(n)$ for $n \\le 100$ is $728$.\n\nFind $\\sum M(n)$ for $n \\le 10^{18}$.\nGive your answer modulo $10^8$.", "raw_html": "

\nTwo players, Anton and Bernhard, are playing the following game.
\nThere is one pile of $n$ stones.
\nThe first player may remove any positive number of stones, but not the whole pile.
\nThereafter, each player may remove at most twice the number of stones his opponent took on the previous move.
\nThe player who removes the last stone wins.\n

\n

\nE.g. $n=5$.
\nIf the first player takes anything more than one stone the next player will be able to take all remaining stones.
\nIf the first player takes one stone, leaving four, his opponent will take also one stone, leaving three stones.
\nThe first player cannot take all three because he may take at most $2 \\times 1=2$ stones. So let's say he takes also one stone, leaving $2$. The second player can take the two remaining stones and wins.
\nSo $5$ is a losing position for the first player.
\nFor some winning positions there is more than one possible move for the first player.
\nE.g. when $n=17$ the first player can remove one or four stones.\n

\n

\nLet $M(n)$ be the maximum number of stones the first player can take from a winning position at his first turn and $M(n)=0$ for any other position.\n

\n

\n$\\sum M(n)$ for $n \\le 100$ is $728$.\n

\n

\nFind $\\sum M(n)$ for $n \\le 10^{18}$.\nGive your answer modulo $10^8$.\n

", "url": "https://projecteuler.net/problem=366", "answer": "88351299"} {"id": 367, "problem": "Bozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence is sorted and if not swapping randomly two elements. This is repeated until eventually the sequence is sorted.\n\nIf we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of swaps, averaged over all $4!$ input sequences is $24.75$.\n\nThe already sorted sequence takes $0$ steps.\n\nIn this problem we consider the following variant on bozo sort.\n\nIf the sequence is not in order we pick three elements at random and shuffle these three elements randomly.\n\nAll $3!=6$ permutations of those three elements are equally likely.\n\nThe already sorted sequence will take $0$ steps.\n\nIf we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of shuffles, averaged over all $4!$ input sequences is $27.5$.\n\nConsider as input sequences the permutations of the first $11$ natural numbers.\n\nAveraged over all $11!$ input sequences, what is the expected number of shuffles this sorting algorithm will perform?\n\nGive your answer rounded to the nearest integer.", "raw_html": "

\nBozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence is sorted and if not swapping randomly two elements. This is repeated until eventually the sequence is sorted.\n

\n

\nIf we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of swaps, averaged over all $4!$ input sequences is $24.75$.
\nThe already sorted sequence takes $0$ steps. \n

\n

\nIn this problem we consider the following variant on bozo sort.
\nIf the sequence is not in order we pick three elements at random and shuffle these three elements randomly.
\nAll $3!=6$ permutations of those three elements are equally likely.
\nThe already sorted sequence will take $0$ steps.
\nIf we consider all permutations of the first $4$ natural numbers as input the expectation value of the number of shuffles, averaged over all $4!$ input sequences is $27.5$.
\nConsider as input sequences the permutations of the first $11$ natural numbers.
\nAveraged over all $11!$ input sequences, what is the expected number of shuffles this sorting algorithm will perform?\n

\n

\nGive your answer rounded to the nearest integer.\n

", "url": "https://projecteuler.net/problem=367", "answer": "48271207"} {"id": 368, "problem": "The harmonic series $1 + \\frac 1 2 + \\frac 1 3 + \\frac 1 4 + \\cdots$ is well known to be divergent.\n\nIf we however omit from this series every term where the denominator has a $9$ in it, the series remarkably enough converges to approximately $22.9206766193$.\n\nThis modified harmonic series is called the Kempner series.\n\nLet us now consider another modified harmonic series by omitting from the harmonic series every term where the denominator has $3$ or more equal consecutive digits.\nOne can verify that out of the first $1200$ terms of the harmonic series, only $20$ terms will be omitted.\n\nThese $20$ omitted terms are:\n\n$$\\frac 1 {111}, \\frac 1 {222}, \\frac 1 {333}, \\frac 1 {444}, \\frac 1 {555}, \\frac 1 {666}, \\frac 1 {777}, \\frac 1 {888}, \\frac 1 {999}, \\frac 1 {1000}, \\frac 1 {1110},$$\n$$\\frac 1 {1111}, \\frac 1 {1112}, \\frac 1 {1113}, \\frac 1 {1114}, \\frac 1 {1115}, \\frac 1 {1116}, \\frac 1 {1117}, \\frac 1 {1118}, \\frac 1 {1119}.$$\n\nThis series converges as well.\n\nFind the value the series converges to.\n\nGive your answer rounded to $10$ digits behind the decimal point.", "raw_html": "

The harmonic series $1 + \\frac 1 2 + \\frac 1 3 + \\frac 1 4 + \\cdots$ is well known to be divergent.

\n\n

If we however omit from this series every term where the denominator has a $9$ in it, the series remarkably enough converges to approximately $22.9206766193$.
\nThis modified harmonic series is called the Kempner series.

\n\n

Let us now consider another modified harmonic series by omitting from the harmonic series every term where the denominator has $3$ or more equal consecutive digits.\nOne can verify that out of the first $1200$ terms of the harmonic series, only $20$ terms will be omitted.
\nThese $20$ omitted terms are:

\n

$$\\frac 1 {111}, \\frac 1 {222}, \\frac 1 {333}, \\frac 1 {444}, \\frac 1 {555}, \\frac 1 {666}, \\frac 1 {777}, \\frac 1 {888}, \\frac 1 {999}, \\frac 1 {1000}, \\frac 1 {1110},$$\n$$\\frac 1 {1111}, \\frac 1 {1112}, \\frac 1 {1113}, \\frac 1 {1114}, \\frac 1 {1115}, \\frac 1 {1116}, \\frac 1 {1117}, \\frac 1 {1118}, \\frac 1 {1119}.$$

\n\n

This series converges as well.

\n\n

Find the value the series converges to.
\nGive your answer rounded to $10$ digits behind the decimal point.

", "url": "https://projecteuler.net/problem=368", "answer": "253.6135092068"} {"id": 369, "problem": "In a standard $52$ card deck of playing cards, a set of $4$ cards is a Badugi if it contains $4$ cards with no pairs and no two cards of the same suit.\n\nLet $f(n)$ be the number of ways to choose $n$ cards with a $4$ card subset that is a Badugi. For example, there are $2598960$ ways to choose five cards from a standard $52$ card deck, of which $514800$ contain a $4$ card subset that is a Badugi, so $f(5) = 514800$.\n\nFind $\\sum f(n)$ for $4 \\le n \\le 13$.", "raw_html": "

In a standard $52$ card deck of playing cards, a set of $4$ cards is a Badugi if it contains $4$ cards with no pairs and no two cards of the same suit.

\n\n

Let $f(n)$ be the number of ways to choose $n$ cards with a $4$ card subset that is a Badugi. For example, there are $2598960$ ways to choose five cards from a standard $52$ card deck, of which $514800$ contain a $4$ card subset that is a Badugi, so $f(5) = 514800$.

\n\n

Find $\\sum f(n)$ for $4 \\le n \\le 13$.

", "url": "https://projecteuler.net/problem=369", "answer": "862400558448"} {"id": 370, "problem": "Let us define a geometric triangle as an integer sided triangle with sides $a \\le b \\le c$ so that its sides form a geometric progression, i.e. $b^2 = a \\cdot c$\n\n\n\nAn example of such a geometric triangle is the triangle with sides $a = 144$, $b = 156$ and $c = 169$.\n\nThere are $861805$ geometric triangles with perimeter $\\le 10^6$.\n\nHow many geometric triangles exist with perimeter $\\le 2.5 \\cdot 10^{13}$?", "raw_html": "

Let us define a geometric triangle as an integer sided triangle with sides $a \\le b \\le c$ so that its sides form a geometric progression, i.e. $b^2 = a \\cdot c$

\n\n

An example of such a geometric triangle is the triangle with sides $a = 144$, $b = 156$ and $c = 169$.

\n\n

There are $861805$ geometric triangles with perimeter $\\le 10^6$.

\n\n

How many geometric triangles exist with perimeter $\\le 2.5 \\cdot 10^{13}$?

", "url": "https://projecteuler.net/problem=370", "answer": "41791929448408"} {"id": 371, "problem": "Oregon licence plates consist of three letters followed by a three digit number (each digit can be from [0..9]).\n\nWhile driving to work Seth plays the following game:\n\nWhenever the numbers of two licence plates seen on his trip add to 1000 that's a win.\n\nE.g. MIC-012 and HAN-988 is a win and RYU-500 and SET-500 too (as long as he sees them in the same trip).\n\nFind the expected number of plates he needs to see for a win.\n\nGive your answer rounded to 8 decimal places behind the decimal point.\n\nNote: We assume that each licence plate seen is equally likely to have any three digit number on it.", "raw_html": "

\nOregon licence plates consist of three letters followed by a three digit number (each digit can be from [0..9]).
\nWhile driving to work Seth plays the following game:
\nWhenever the numbers of two licence plates seen on his trip add to 1000 that's a win.\n

\n

\nE.g. MIC-012 and HAN-988 is a win and RYU-500 and SET-500 too (as long as he sees them in the same trip). \n

\n

\nFind the expected number of plates he needs to see for a win.
\nGive your answer rounded to 8 decimal places behind the decimal point.\n

\n

\nNote: We assume that each licence plate seen is equally likely to have any three digit number on it.\n

", "url": "https://projecteuler.net/problem=371", "answer": "40.66368097"} {"id": 372, "problem": "Let $R(M, N)$ be the number of lattice points $(x, y)$ which satisfy $M\\!\\lt\\!x\\!\\le\\!N$, $M\\!\\lt\\!y\\!\\le\\!N$ and $\\large\\left\\lfloor\\!\\frac{y^2}{x^2}\\!\\right\\rfloor$ is odd.\n\nWe can verify that $R(0, 100) = 3019$ and $R(100, 10000) = 29750422$.\n\nFind $R(2\\cdot10^6, 10^9)$.\n\nNote: $\\lfloor x\\rfloor$ represents the floor function.", "raw_html": "

\nLet $R(M, N)$ be the number of lattice points $(x, y)$ which satisfy $M\\!\\lt\\!x\\!\\le\\!N$, $M\\!\\lt\\!y\\!\\le\\!N$ and $\\large\\left\\lfloor\\!\\frac{y^2}{x^2}\\!\\right\\rfloor$ is odd.
\nWe can verify that $R(0, 100) = 3019$ and $R(100, 10000) = 29750422$.
\nFind $R(2\\cdot10^6, 10^9)$.\n

\n\n

\nNote: $\\lfloor x\\rfloor$ represents the floor function.

", "url": "https://projecteuler.net/problem=372", "answer": "301450082318807027"} {"id": 373, "problem": "Every triangle has a circumscribed circle that goes through the three vertices.\nConsider all integer sided triangles for which the radius of the circumscribed circle is integral as well.\n\nLet $S(n)$ be the sum of the radii of the circumscribed circles of all such triangles for which the radius does not exceed $n$.\n\n$S(100)=4950$ and $S(1200)=1653605$.\n\nFind $S(10^7)$.", "raw_html": "

\nEvery triangle has a circumscribed circle that goes through the three vertices.\nConsider all integer sided triangles for which the radius of the circumscribed circle is integral as well.\n

\n

\nLet $S(n)$ be the sum of the radii of the circumscribed circles of all such triangles for which the radius does not exceed $n$.\n

\n

$S(100)=4950$ and $S(1200)=1653605$.\n

\n

\nFind $S(10^7)$.\n

", "url": "https://projecteuler.net/problem=373", "answer": "727227472448913"} {"id": 374, "problem": "An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers.\n\nPartitions that differ only in the order of their summands are considered the same.\nA partition of $n$ into distinct parts is a partition of $n$ in which every part occurs at most once.\n\nThe partitions of $5$ into distinct parts are:\n\n$5$, $4+1$ and $3+2$.\n\nLet $f(n)$ be the maximum product of the parts of any such partition of $n$ into distinct parts and let $m(n)$ be the number of elements of any such partition of $n$ with that product.\n\nSo $f(5)=6$ and $m(5)=2$.\n\nFor $n=10$ the partition with the largest product is $10=2+3+5$, which gives $f(10)=30$ and $m(10)=3$.\n\nAnd their product, $f(10) \\cdot m(10) = 30 \\cdot 3 = 90$.\n\nIt can be verified that\n\n$\\sum f(n) \\cdot m(n)$ for $1 \\le n \\le 100 = 1683550844462$.\n\nFind $\\sum f(n) \\cdot m(n)$ for $1 \\le n \\le 10^{14}$.\n\nGive your answer modulo $982451653$, the $50$ millionth prime.", "raw_html": "

An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers.

\n\n

Partitions that differ only in the order of their summands are considered the same.\nA partition of $n$ into distinct parts is a partition of $n$ in which every part occurs at most once.

\n\n

The partitions of $5$ into distinct parts are:\n
$5$, $4+1$ and $3+2$.

\n\n

Let $f(n)$ be the maximum product of the parts of any such partition of $n$ into distinct parts and let $m(n)$ be the number of elements of any such partition of $n$ with that product.

\n\n

So $f(5)=6$ and $m(5)=2$.

\n\n

For $n=10$ the partition with the largest product is $10=2+3+5$, which gives $f(10)=30$ and $m(10)=3$.\n
And their product, $f(10) \\cdot m(10) = 30 \\cdot 3 = 90$.

\n\n

It can be verified that\n
$\\sum f(n) \\cdot m(n)$ for $1 \\le n \\le 100 = 1683550844462$.

\n\n

Find $\\sum f(n) \\cdot m(n)$ for $1 \\le n \\le 10^{14}$.\n
Give your answer modulo $982451653$, the $50$ millionth prime.

", "url": "https://projecteuler.net/problem=374", "answer": "334420941"} {"id": 375, "problem": "Let $S_n$ be an integer sequence produced with the following pseudo-random number generator:\n\n$$\\begin{align}\nS_0 & = 290797 \\\\\nS_{n+1} & = S_n^2 \\bmod 50515093\n\\end{align}$$\n\nLet $A(i, j)$ be the minimum of the numbers $S_i, S_{i+1}, \\dots, S_j$ for $i\\le j$.\n\nLet $M(N) = \\sum A(i, j)$ for $1 \\le i \\le j \\le N$.\n\nWe can verify that $M(10) = 432256955$ and $M(10\\,000) = 3264567774119$.\n\nFind $M(2\\,000\\,000\\,000)$.", "raw_html": "

Let $S_n$ be an integer sequence produced with the following pseudo-random number generator:

\n$$\\begin{align}\nS_0 & = 290797 \\\\\nS_{n+1} & = S_n^2 \\bmod 50515093\n\\end{align}$$\n\n

\nLet $A(i, j)$ be the minimum of the numbers $S_i, S_{i+1}, \\dots, S_j$ for $i\\le j$.
\nLet $M(N) = \\sum A(i, j)$ for $1 \\le i \\le j \\le N$.
\nWe can verify that $M(10) = 432256955$ and $M(10\\,000) = 3264567774119$.

\n\n

\nFind $M(2\\,000\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=375", "answer": "7435327983715286168"} {"id": 376, "problem": "Consider the following set of dice with nonstandard pips:\n\nDie $A$: $1$ $4$ $4$ $4$ $4$ $4$\n\nDie $B$: $2$ $2$ $2$ $5$ $5$ $5$\n\nDie $C$: $3$ $3$ $3$ $3$ $3$ $6$\n\nA game is played by two players picking a die in turn and rolling it. The player who rolls the highest value wins.\n\nIf the first player picks die $A$ and the second player picks die $B$ we get\n\n$P(\\text{second player wins}) = 7/12 \\gt 1/2$.\n\nIf the first player picks die $B$ and the second player picks die $C$ we get\n\n$P(\\text{second player wins}) = 7/12 \\gt 1/2$.\n\nIf the first player picks die $C$ and the second player picks die $A$ we get\n\n$P(\\text{second player wins}) = 25/36 \\gt 1/2$.\n\nSo whatever die the first player picks, the second player can pick another die and have a larger than $50\\%$ chance of winning.\n\nA set of dice having this property is called a nontransitive set of dice.\n\nWe wish to investigate how many sets of nontransitive dice exist. We will assume the following conditions:\n\n- There are three six-sided dice with each side having between $1$ and $N$ pips, inclusive.\n\n- Dice with the same set of pips are equal, regardless of which side on the die the pips are located.\n\n- The same pip value may appear on multiple dice; if both players roll the same value neither player wins.\n\n- The sets of dice $\\{A,B,C\\}$, $\\{B,C,A\\}$ and $\\{C,A,B\\}$ are the same set.\n\nFor $N = 7$ we find there are $9780$ such sets.\n\nHow many are there for $N = 30$?", "raw_html": "

\nConsider the following set of dice with nonstandard pips:\n

\n\n

\nDie $A$: $1$ $4$ $4$ $4$ $4$ $4$
\nDie $B$: $2$ $2$ $2$ $5$ $5$ $5$
\nDie $C$: $3$ $3$ $3$ $3$ $3$ $6$

\n\n

\nA game is played by two players picking a die in turn and rolling it. The player who rolls the highest value wins.\n

\n\n

\nIf the first player picks die $A$ and the second player picks die $B$ we get
\n$P(\\text{second player wins}) = 7/12 \\gt 1/2$.

\n\n

\nIf the first player picks die $B$ and the second player picks die $C$ we get
\n$P(\\text{second player wins}) = 7/12 \\gt 1/2$.

\n\n

\nIf the first player picks die $C$ and the second player picks die $A$ we get
\n$P(\\text{second player wins}) = 25/36 \\gt 1/2$.

\n\n

\nSo whatever die the first player picks, the second player can pick another die and have a larger than $50\\%$ chance of winning.
\nA set of dice having this property is called a nontransitive set of dice.\n

\n\n

\nWe wish to investigate how many sets of nontransitive dice exist. We will assume the following conditions:

\nFor $N = 7$ we find there are $9780$ such sets.
\nHow many are there for $N = 30$?\n

", "url": "https://projecteuler.net/problem=376", "answer": "973059630185670"} {"id": 377, "problem": "There are $16$ positive integers that do not have a zero in their digits and that have a digital sum equal to $5$, namely:\n\n$5$, $14$, $23$, $32$, $41$, $113$, $122$, $131$, $212$, $221$, $311$, $1112$, $1121$, $1211$, $2111$ and $11111$.\n\nTheir sum is $17891$.\n\nLet $f(n)$ be the sum of all positive integers that do not have a zero in their digits and have a digital sum equal to $n$.\n\nFind $\\displaystyle \\sum_{i=1}^{17} f(13^i)$.\n\nGive the last $9$ digits as your answer.", "raw_html": "

\nThere are $16$ positive integers that do not have a zero in their digits and that have a digital sum equal to $5$, namely:
\n$5$, $14$, $23$, $32$, $41$, $113$, $122$, $131$, $212$, $221$, $311$, $1112$, $1121$, $1211$, $2111$ and $11111$.
\nTheir sum is $17891$.\n

\n

\nLet $f(n)$ be the sum of all positive integers that do not have a zero in their digits and have a digital sum equal to $n$.\n

\n

\nFind $\\displaystyle \\sum_{i=1}^{17} f(13^i)$.
\nGive the last $9$ digits as your answer.\n

", "url": "https://projecteuler.net/problem=377", "answer": "732385277"} {"id": 378, "problem": "Let $T(n)$ be the nth triangle number, so $T(n) = \\dfrac{n(n + 1)}{2}$.\n\nLet $dT(n)$ be the number of divisors of $T(n)$.\n\nE.g.: $T(7) = 28$ and $dT(7) = 6$.\n\nLet $Tr(n)$ be the number of triples $(i, j, k)$ such that $1 \\le i \\lt j \\lt k \\le n$ and $dT(i) \\gt dT(j) \\gt dT(k)$.\n\n$Tr(20) = 14$, $Tr(100) = 5772$, and $Tr(1000) = 11174776$.\n\nFind $Tr(60 000 000)$.\n\nGive the last 18 digits of your answer.", "raw_html": "

Let $T(n)$ be the nth triangle number, so $T(n) = \\dfrac{n(n + 1)}{2}$.

\n\n

Let $dT(n)$ be the number of divisors of $T(n)$.
\nE.g.: $T(7) = 28$ and $dT(7) = 6$.

\n\n

Let $Tr(n)$ be the number of triples $(i, j, k)$ such that $1 \\le i \\lt j \\lt k \\le n$ and $dT(i) \\gt dT(j) \\gt dT(k)$.
\n$Tr(20) = 14$, $Tr(100) = 5772$, and $Tr(1000) = 11174776$.

\n\n

Find $Tr(60 000 000)$.
\nGive the last 18 digits of your answer.

", "url": "https://projecteuler.net/problem=378", "answer": "147534623725724718"} {"id": 379, "problem": "Let $f(n)$ be the number of couples $(x, y)$ with $x$ and $y$ positive integers, $x \\le y$ and the least common multiple of $x$ and $y$ equal to $n$.\n\nLet $g$ be the summatory function of $f$, i.e.:\n$g(n) = \\sum f(i)$ for $1 \\le i \\le n$.\n\nYou are given that $g(10^6) = 37429395$.\n\nFind $g(10^{12})$.", "raw_html": "

\nLet $f(n)$ be the number of couples $(x, y)$ with $x$ and $y$ positive integers, $x \\le y$ and the least common multiple of $x$ and $y$ equal to $n$.\n

\n

\nLet $g$ be the summatory function of $f$, i.e.: \n$g(n) = \\sum f(i)$ for $1 \\le i \\le n$.\n

\nYou are given that $g(10^6) = 37429395$.\n

\n

\nFind $g(10^{12})$.\n

", "url": "https://projecteuler.net/problem=379", "answer": "132314136838185"} {"id": 380, "problem": "An $m \\times n$ maze is an $m \\times n$ rectangular grid with walls placed between grid cells such that there is exactly one path from the top-left square to any other square.\nThe following are examples of a $9 \\times 12$ maze and a $15 \\times 20$ maze:\n\nLet $C(m,n)$ be the number of distinct $m \\times n$ mazes. Mazes which can be formed by rotation and reflection from another maze are considered distinct.\n\nIt can be verified that $C(1,1) = 1$, $C(2,2) = 4$, $C(3,4) = 2415$, and $C(9,12) = 2.5720\\mathrm e46$ (in scientific notation rounded to $5$ significant digits).\n\nFind $C(100,500)$ and write your answer in scientific notation rounded to $5$ significant digits.\n\nWhen giving your answer, use a lowercase e to separate mantissa and exponent.\nE.g. if the answer is $1234567891011$ then the answer format would be 1.2346e12.", "raw_html": "

\nAn $m \\times n$ maze is an $m \\times n$ rectangular grid with walls placed between grid cells such that there is exactly one path from the top-left square to any other square.
The following are examples of a $9 \\times 12$ maze and a $15 \\times 20$ maze:\n

\n

\n\"0380_mazes.gif\"

\n

\nLet $C(m,n)$ be the number of distinct $m \\times n$ mazes. Mazes which can be formed by rotation and reflection from another maze are considered distinct.\n

\n

\nIt can be verified that $C(1,1) = 1$, $C(2,2) = 4$, $C(3,4) = 2415$, and $C(9,12) = 2.5720\\mathrm e46$ (in scientific notation rounded to $5$ significant digits).
\nFind $C(100,500)$ and write your answer in scientific notation rounded to $5$ significant digits.\n

\n

\nWhen giving your answer, use a lowercase e to separate mantissa and exponent.\nE.g. if the answer is $1234567891011$ then the answer format would be 1.2346e12.\n\n

", "url": "https://projecteuler.net/problem=380", "answer": "6.3202e25093"} {"id": 381, "problem": "For a prime $p$ let $S(p) = (\\sum (p-k)!) \\bmod (p)$ for $1 \\le k \\le 5$.\n\nFor example, if $p=7$,\n\n$(7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! = 720+120+24+6+2 = 872$.\n\nAs $872 \\bmod (7) = 4$, $S(7) = 4$.\n\nIt can be verified that $\\sum S(p) = 480$ for $5 \\le p \\lt 100$.\n\nFind $\\sum S(p)$ for $5 \\le p \\lt 10^8$.", "raw_html": "

\nFor a prime $p$ let $S(p) = (\\sum (p-k)!) \\bmod (p)$ for $1 \\le k \\le 5$.\n

\n

\nFor example, if $p=7$,
\n$(7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! = 720+120+24+6+2 = 872$.
\nAs $872 \\bmod (7) = 4$, $S(7) = 4$.\n

\n

\nIt can be verified that $\\sum S(p) = 480$ for $5 \\le p \\lt 100$.\n

\n

\nFind $\\sum S(p)$ for $5 \\le p \\lt 10^8$.\n

", "url": "https://projecteuler.net/problem=381", "answer": "139602943319822"} {"id": 382, "problem": "A polygon is a flat shape consisting of straight line segments that are joined to form a closed chain or circuit. A polygon consists of at least three sides and does not self-intersect.\n\nA set $S$ of positive numbers is said to generate a polygon $P$ if:\n\n- no two sides of $P$ are the same length,\n\n- the length of every side of $P$ is in $S$, and\n\n- $S$ contains no other value.\n\nFor example:\n\nThe set $\\{3, 4, 5\\}$ generates a polygon with sides $3$, $4$, and $5$ (a triangle).\n\nThe set $\\{6, 9, 11, 24\\}$ generates a polygon with sides $6$, $9$, $11$, and $24$ (a quadrilateral).\n\nThe sets $\\{1, 2, 3\\}$ and $\\{2, 3, 4, 9\\}$ do not generate any polygon at all.\n\nConsider the sequence $s$, defined as follows:\n\n- $s_1 = 1$, $s_2 = 2$, $s_3 = 3$\n\n- $s_n = s_{n-1} + s_{n-3}$ for $n \\gt 3$.\n\nLet $U_n$ be the set $\\{s_1, s_2, \\dots, s_n\\}$. For example, $U_{10} = \\{1, 2, 3, 4, 6, 9, 13, 19, 28, 41\\}$.\n\nLet $f(n)$ be the number of subsets of $U_n$ which generate at least one polygon.\n\nFor example, $f(5) = 7$, $f(10) = 501$ and $f(25) = 18635853$.\n\nFind the last $9$ digits of $f(10^{18})$.", "raw_html": "

\nA polygon is a flat shape consisting of straight line segments that are joined to form a closed chain or circuit. A polygon consists of at least three sides and does not self-intersect.\n

\n\n

\nA set $S$ of positive numbers is said to generate a polygon $P$ if:

\nFor example:
\nThe set $\\{3, 4, 5\\}$ generates a polygon with sides $3$, $4$, and $5$ (a triangle).
\nThe set $\\{6, 9, 11, 24\\}$ generates a polygon with sides $6$, $9$, $11$, and $24$ (a quadrilateral).
\nThe sets $\\{1, 2, 3\\}$ and $\\{2, 3, 4, 9\\}$ do not generate any polygon at all.

\n\n

\nConsider the sequence $s$, defined as follows:

\nLet $U_n$ be the set $\\{s_1, s_2, \\dots, s_n\\}$. For example, $U_{10} = \\{1, 2, 3, 4, 6, 9, 13, 19, 28, 41\\}$.
\nLet $f(n)$ be the number of subsets of $U_n$ which generate at least one polygon.
\nFor example, $f(5) = 7$, $f(10) = 501$ and $f(25) = 18635853$.\n

\n\n

\nFind the last $9$ digits of $f(10^{18})$.\n

", "url": "https://projecteuler.net/problem=382", "answer": "697003956"} {"id": 383, "problem": "Let $f_5(n)$ be the largest integer $x$ for which $5^x$ divides $n$.\n\nFor example, $f_5(625000) = 7$.\n\nLet $T_5(n)$ be the number of integers $i$ which satisfy $f_5((2 \\cdot i - 1)!) \\lt 2 \\cdot f_5(i!)$ and $1 \\le i \\le n$.\n\nIt can be verified that $T_5(10^3) = 68$ and $T_5(10^9) = 2408210$.\n\nFind $T_5(10^{18})$.", "raw_html": "

\nLet $f_5(n)$ be the largest integer $x$ for which $5^x$ divides $n$.
\nFor example, $f_5(625000) = 7$.\n

\n\n

\nLet $T_5(n)$ be the number of integers $i$ which satisfy $f_5((2 \\cdot i - 1)!) \\lt 2 \\cdot f_5(i!)$ and $1 \\le i \\le n$.
\nIt can be verified that $T_5(10^3) = 68$ and $T_5(10^9) = 2408210$.\n

\n\n

\nFind $T_5(10^{18})$.\n

", "url": "https://projecteuler.net/problem=383", "answer": "22173624649806"} {"id": 384, "problem": "Define the sequence $a(n)$ as the number of adjacent pairs of ones in the binary expansion of $n$ (possibly overlapping).\n\nE.g.: $a(5) = a(101_2) = 0$, $a(6) = a(110_2) = 1$, $a(7) = a(111_2) = 2$.\n\nDefine the sequence $b(n) = (-1)^{a(n)}$.\n\nThis sequence is called the Rudin-Shapiro sequence.\n\nAlso consider the summatory sequence of $b(n)$: $s(n) = \\sum \\limits_{i = 0}^n b(i)$.\n\nThe first couple of values of these sequences are:\n\n| $n$ | $0$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ |\n| $a(n)$ | $0$ | $0$ | $0$ | $1$ | $0$ | $0$ | $1$ | $2$ |\n| $b(n)$ | $1$ | $1$ | $1$ | $-1$ | $1$ | $1$ | $-1$ | $1$ |\n| $s(n)$ | $1$ | $2$ | $3$ | $2$ | $3$ | $4$ | $3$ | $4$ |\n\nThe sequence $s(n)$ has the remarkable property that all elements are positive and every positive integer $k$ occurs exactly $k$ times.\n\nDefine $g(t,c)$, with $1 \\le c \\le t$, as the index in $s(n)$ for which $t$ occurs for the $c$'th time in $s(n)$.\n\nE.g.: $g(3,3) = 6$, $g(4,2) = 7$ and $g(54321,12345) = 1220847710$.\n\nLet $F(n)$ be the Fibonacci sequence defined by:\n\n$F(0)=F(1)=1$ and\n\n$F(n)=F(n-1)+F(n-2)$ for $n \\gt 1$.\n\nDefine $GF(t)=g(F(t),F(t-1))$.\n\nFind $\\sum GF(t)$ for $2 \\le t \\le 45$.", "raw_html": "

Define the sequence $a(n)$ as the number of adjacent pairs of ones in the binary expansion of $n$ (possibly overlapping).\n
E.g.: $a(5) = a(101_2) = 0$, $a(6) = a(110_2) = 1$, $a(7) = a(111_2) = 2$.

\n\n

Define the sequence $b(n) = (-1)^{a(n)}$.\n
This sequence is called the Rudin-Shapiro sequence.

\n

Also consider the summatory sequence of $b(n)$: $s(n) = \\sum \\limits_{i = 0}^n b(i)$.

\n\n

The first couple of values of these sequences are:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
$n$$0$$1$$2$$3$$4$$5$$6$$7$
$a(n)$$0$$0$$0$$1$$0$$0$$1$$2$
$b(n)$$1$$1$$1$$-1$$1$$1$$-1$$1$
$s(n)$$1$$2$$3$$2$$3$$4$$3$$4$
\n\n

The sequence $s(n)$ has the remarkable property that all elements are positive and every positive integer $k$ occurs exactly $k$ times.

\n\n

Define $g(t,c)$, with $1 \\le c \\le t$, as the index in $s(n)$ for which $t$ occurs for the $c$'th time in $s(n)$.\n
E.g.: $g(3,3) = 6$, $g(4,2) = 7$ and $g(54321,12345) = 1220847710$.

\n\n

Let $F(n)$ be the Fibonacci sequence defined by:\n
$F(0)=F(1)=1$ and\n
$F(n)=F(n-1)+F(n-2)$ for $n \\gt 1$.

\n\n

Define $GF(t)=g(F(t),F(t-1))$.

\n\n

Find $\\sum GF(t)$ for $2 \\le t \\le 45$.

", "url": "https://projecteuler.net/problem=384", "answer": "3354706415856332783"} {"id": 385, "problem": "For any triangle $T$ in the plane, it can be shown that there is a unique ellipse with largest area that is completely inside $T$.\n\nFor a given $n$, consider triangles $T$ such that:\n\n- the vertices of $T$ have integer coordinates with absolute value $\\le n$, and\n\n- the foci1 of the largest-area ellipse inside $T$ are $(\\sqrt{13},0)$ and $(-\\sqrt{13},0)$.\n\nLet $A(n)$ be the sum of the areas of all such triangles.\n\nFor example, if $n = 8$, there are two such triangles. Their vertices are $(-4,-3),(-4,3),(8,0)$ and $(4,3),(4,-3),(-8,0)$, and the area of each triangle is $36$. Thus $A(8) = 36 + 36 = 72$.\n\nIt can be verified that $A(10) = 252$, $A(100) = 34632$ and $A(1000) = 3529008$.\n\nFind $A(1\\,000\\,000\\,000)$.\n\n1The foci (plural of focus) of an ellipse are two points $A$ and $B$ such that for every point $P$ on the boundary of the ellipse, $AP + PB$ is constant.", "raw_html": "

\nFor any triangle $T$ in the plane, it can be shown that there is a unique ellipse with largest area that is completely inside $T$.\n

\n\"0385_ellipsetriangle.png\"

\n

\nFor a given $n$, consider triangles $T$ such that:
\n- the vertices of $T$ have integer coordinates with absolute value $\\le n$, and
\n- the foci1 of the largest-area ellipse inside $T$ are $(\\sqrt{13},0)$ and $(-\\sqrt{13},0)$.
\nLet $A(n)$ be the sum of the areas of all such triangles.\n

\n

\nFor example, if $n = 8$, there are two such triangles. Their vertices are $(-4,-3),(-4,3),(8,0)$ and $(4,3),(4,-3),(-8,0)$, and the area of each triangle is $36$. Thus $A(8) = 36 + 36 = 72$.\n

\n

\nIt can be verified that $A(10) = 252$, $A(100) = 34632$ and $A(1000) = 3529008$.\n

\n

\nFind $A(1\\,000\\,000\\,000)$.\n

\n

\n\n1The foci (plural of focus) of an ellipse are two points $A$ and $B$ such that for every point $P$ on the boundary of the ellipse, $AP + PB$ is constant.\n\n\n

", "url": "https://projecteuler.net/problem=385", "answer": "3776957309612153700"} {"id": 386, "problem": "Let $n$ be an integer and $S(n)$ be the set of factors of $n$.\n\nA subset $A$ of $S(n)$ is called an antichain of $S(n)$ if $A$ contains only one element or if none of the elements of $A$ divides any of the other elements of $A$.\n\nFor example: $S(30) = \\{1, 2, 3, 5, 6, 10, 15, 30\\}$.\n\n$\\{2, 5, 6\\}$ is not an antichain of $S(30)$.\n\n$\\{2, 3, 5\\}$ is an antichain of $S(30)$.\n\nLet $N(n)$ be the maximum length of an antichain of $S(n)$.\n\nFind $\\sum N(n)$ for $1 \\le n \\le 10^8$.", "raw_html": "

Let $n$ be an integer and $S(n)$ be the set of factors of $n$.

\n\n

A subset $A$ of $S(n)$ is called an antichain of $S(n)$ if $A$ contains only one element or if none of the elements of $A$ divides any of the other elements of $A$.

\n\n

For example: $S(30) = \\{1, 2, 3, 5, 6, 10, 15, 30\\}$.\n
$\\{2, 5, 6\\}$ is not an antichain of $S(30)$.\n
$\\{2, 3, 5\\}$ is an antichain of $S(30)$.

\n\n

Let $N(n)$ be the maximum length of an antichain of $S(n)$.

\n\n

Find $\\sum N(n)$ for $1 \\le n \\le 10^8$.

", "url": "https://projecteuler.net/problem=386", "answer": "528755790"} {"id": 387, "problem": "A Harshad or Niven number is a number that is divisible by the sum of its digits.\n\n$201$ is a Harshad number because it is divisible by $3$ (the sum of its digits.)\n\nWhen we truncate the last digit from $201$, we get $20$, which is a Harshad number.\n\nWhen we truncate the last digit from $20$, we get $2$, which is also a Harshad number.\n\nLet's call a Harshad number that, while recursively truncating the last digit, always results in a Harshad number a right truncatable Harshad number.\n\n\n\nAlso:\n\n$201/3=67$ which is prime.\n\nLet's call a Harshad number that, when divided by the sum of its digits, results in a prime a strong Harshad number.\n\nNow take the number $2011$ which is prime.\n\nWhen we truncate the last digit from it we get $201$, a strong Harshad number that is also right truncatable.\n\nLet's call such primes strong, right truncatable Harshad primes.\n\nYou are given that the sum of the strong, right truncatable Harshad primes less than $10000$ is $90619$.\n\nFind the sum of the strong, right truncatable Harshad primes less than $10^{14}$.", "raw_html": "

A Harshad or Niven number is a number that is divisible by the sum of its digits.\n
$201$ is a Harshad number because it is divisible by $3$ (the sum of its digits.)\n
When we truncate the last digit from $201$, we get $20$, which is a Harshad number.\n
When we truncate the last digit from $20$, we get $2$, which is also a Harshad number.\n
Let's call a Harshad number that, while recursively truncating the last digit, always results in a Harshad number a right truncatable Harshad number.

\n\n

Also:\n
$201/3=67$ which is prime.\n
Let's call a Harshad number that, when divided by the sum of its digits, results in a prime a strong Harshad number.

\n\n

Now take the number $2011$ which is prime.\n
When we truncate the last digit from it we get $201$, a strong Harshad number that is also right truncatable.\n
Let's call such primes strong, right truncatable Harshad primes.

\n\n

You are given that the sum of the strong, right truncatable Harshad primes less than $10000$ is $90619$.

\n\n

Find the sum of the strong, right truncatable Harshad primes less than $10^{14}$.

", "url": "https://projecteuler.net/problem=387", "answer": "696067597313468"} {"id": 388, "problem": "Consider all lattice points $(a,b,c)$ with $0 \\le a,b,c \\le N$.\n\nFrom the origin $O(0,0,0)$ all lines are drawn to the other lattice points.\n\nLet $D(N)$ be the number of distinct such lines.\n\nYou are given that $D(1\\,000\\,000) = 831909254469114121$.\n\nFind $D(10^{10})$. Give as your answer the first nine digits followed by the last nine digits.", "raw_html": "

\nConsider all lattice points $(a,b,c)$ with $0 \\le a,b,c \\le N$.\n

\n

\nFrom the origin $O(0,0,0)$ all lines are drawn to the other lattice points.
\nLet $D(N)$ be the number of distinct such lines.\n

\n

\nYou are given that $D(1\\,000\\,000) = 831909254469114121$.\n

\nFind $D(10^{10})$. Give as your answer the first nine digits followed by the last nine digits.\n

", "url": "https://projecteuler.net/problem=388", "answer": "831907372805129931"} {"id": 389, "problem": "An unbiased single $4$-sided die is thrown and its value, $T$, is noted.\n$T$ unbiased $6$-sided dice are thrown and their scores are added together. The sum, $C$, is noted.\n$C$ unbiased $8$-sided dice are thrown and their scores are added together. The sum, $O$, is noted.\n$O$ unbiased $12$-sided dice are thrown and their scores are added together. The sum, $D$, is noted.\n$D$ unbiased $20$-sided dice are thrown and their scores are added together. The sum, $I$, is noted.\n\nFind the variance of $I$, and give your answer rounded to $4$ decimal places.", "raw_html": "

\nAn unbiased single $4$-sided die is thrown and its value, $T$, is noted.
$T$ unbiased $6$-sided dice are thrown and their scores are added together. The sum, $C$, is noted.
$C$ unbiased $8$-sided dice are thrown and their scores are added together. The sum, $O$, is noted.
$O$ unbiased $12$-sided dice are thrown and their scores are added together. The sum, $D$, is noted.
$D$ unbiased $20$-sided dice are thrown and their scores are added together. The sum, $I$, is noted.
\nFind the variance of $I$, and give your answer rounded to $4$ decimal places.\n

", "url": "https://projecteuler.net/problem=389", "answer": "2406376.3623"} {"id": 390, "problem": "Consider the triangle with sides $\\sqrt 5$, $\\sqrt {65}$ and $\\sqrt {68}$.\nIt can be shown that this triangle has area $9$.\n\n$S(n)$ is the sum of the areas of all triangles with sides $\\sqrt{1+b^2}$, $\\sqrt {1+c^2}$ and $\\sqrt{b^2+c^2}\\,$ (for positive integers $b$ and $c$) that have an integral area not exceeding $n$.\n\nThe example triangle has $b=2$ and $c=8$.\n\n$S(10^6)=18018206$.\n\nFind $S(10^{10})$.", "raw_html": "

Consider the triangle with sides $\\sqrt 5$, $\\sqrt {65}$ and $\\sqrt {68}$.\nIt can be shown that this triangle has area $9$.

\n\n

$S(n)$ is the sum of the areas of all triangles with sides $\\sqrt{1+b^2}$, $\\sqrt {1+c^2}$ and $\\sqrt{b^2+c^2}\\,$ (for positive integers $b$ and $c$) that have an integral area not exceeding $n$.

\n\n

The example triangle has $b=2$ and $c=8$.

\n\n

$S(10^6)=18018206$.

\n\n

Find $S(10^{10})$.

", "url": "https://projecteuler.net/problem=390", "answer": "2919133642971"} {"id": 391, "problem": "Let $s_k$ be the number of 1’s when writing the numbers from 0 to $k$ in binary.\n\nFor example, writing 0 to 5 in binary, we have $0, 1, 10, 11, 100, 101$. There are seven 1’s, so $s_5 = 7$.\n\nThe sequence $S = \\{s_k : k \\ge 0\\}$ starts $\\{0, 1, 2, 4, 5, 7, 9, 12, ...\\}$.\n\nA game is played by two players. Before the game starts, a number $n$ is chosen. A counter $c$ starts at 0. At each turn, the player chooses a number from 1 to $n$ (inclusive) and increases $c$ by that number. The resulting value of $c$ must be a member of $S$. If there are no more valid moves, then the player loses.\n\nFor example, with $n = 5$ and starting with $c = 0$:\n\nPlayer 1 chooses 4, so $c$ becomes $0 + 4 = 4$.\n\nPlayer 2 chooses 5, so $c$ becomes $4 + 5 = 9$.\n\nPlayer 1 chooses 3, so $c$ becomes $9 + 3 = 12$.\n\netc.\n\nNote that $c$ must always belong to $S$, and each player can increase $c$ by at most $n$.\n\nLet $M(n)$ be the highest number that the first player could choose at the start to force a win, and $M(n) = 0$ if there is no such move. For example, $M(2) = 2$, $M(7) = 1$, and $M(20) = 4$.\n\nIt can be verified that $\\sum{M(n)^3} = 8150$ for $1 \\le n \\le 20$.\n\nFind $\\sum{M(n)^3}$ for $1 \\le n \\le 1000$.", "raw_html": "

Let $s_k$ be the number of 1’s when writing the numbers from 0 to $k$ in binary.
\nFor example, writing 0 to 5 in binary, we have $0, 1, 10, 11, 100, 101$. There are seven 1’s, so $s_5 = 7$.
\nThe sequence $S = \\{s_k : k \\ge 0\\}$ starts $\\{0, 1, 2, 4, 5, 7, 9, 12, ...\\}$.

\n\n

A game is played by two players. Before the game starts, a number $n$ is chosen. A counter $c$ starts at 0. At each turn, the player chooses a number from 1 to $n$ (inclusive) and increases $c$ by that number. The resulting value of $c$ must be a member of $S$. If there are no more valid moves, then the player loses.

\n\n

For example, with $n = 5$ and starting with $c = 0$:

\n

Player 1 chooses 4, so $c$ becomes $0 + 4 = 4$.
\nPlayer 2 chooses 5, so $c$ becomes $4 + 5 = 9$.
\nPlayer 1 chooses 3, so $c$ becomes $9 + 3 = 12$.
\netc.

\n

Note that $c$ must always belong to $S$, and each player can increase $c$ by at most $n$.

\n\n

Let $M(n)$ be the highest number that the first player could choose at the start to force a win, and $M(n) = 0$ if there is no such move. For example, $M(2) = 2$, $M(7) = 1$, and $M(20) = 4$.

\n\n

It can be verified that $\\sum{M(n)^3} = 8150$ for $1 \\le n \\le 20$.

\n\n

Find $\\sum{M(n)^3}$ for $1 \\le n \\le 1000$.

", "url": "https://projecteuler.net/problem=391", "answer": "61029882288"} {"id": 392, "problem": "A rectilinear grid is an orthogonal grid where the spacing between the gridlines does not have to be equidistant.\n\nAn example of such grid is logarithmic graph paper.\n\nConsider rectilinear grids in the Cartesian coordinate system with the following properties:\n\n- The gridlines are parallel to the axes of the Cartesian coordinate system.\n- There are $N+2$ vertical and $N+2$ horizontal gridlines. Hence there are $(N+1) \\times (N+1)$ rectangular cells.\n- The equations of the two outer vertical gridlines are $x = -1$ and $x = 1$.\n- The equations of the two outer horizontal gridlines are $y = -1$ and $y = 1$.\n- The grid cells are colored red if they overlap with the unit circleThe unit circle is the circle that has radius $1$ and is centered at the origin, black otherwise.\n\nFor this problem we would like you to find the positions of the remaining $N$ inner horizontal and $N$ inner vertical gridlines so that the area occupied by the red cells is minimized.\n\nE.g. here is a picture of the solution for $N = 10$:\n\nThe area occupied by the red cells for $N = 10$ rounded to $10$ digits behind the decimal point is $3.3469640797$.\n\nFind the positions for $N = 400$.\n\nGive as your answer the area occupied by the red cells rounded to $10$ digits behind the decimal point.", "raw_html": "

\nA rectilinear grid is an orthogonal grid where the spacing between the gridlines does not have to be equidistant.
\nAn example of such grid is logarithmic graph paper.\n

\n

\nConsider rectilinear grids in the Cartesian coordinate system with the following properties:

For this problem we would like you to find the positions of the remaining $N$ inner horizontal and $N$ inner vertical gridlines so that the area occupied by the red cells is minimized.\n\n

\nE.g. here is a picture of the solution for $N = 10$:\n

\n\"0392_gridlines.png\"

\n\n\nThe area occupied by the red cells for $N = 10$ rounded to $10$ digits behind the decimal point is $3.3469640797$.\n\n

\nFind the positions for $N = 400$.
\nGive as your answer the area occupied by the red cells rounded to $10$ digits behind the decimal point.\n

", "url": "https://projecteuler.net/problem=392", "answer": "3.1486734435"} {"id": 393, "problem": "An $n \\times n$ grid of squares contains $n^2$ ants, one ant per square.\n\nAll ants decide to move simultaneously to an adjacent square (usually $4$ possibilities, except for ants on the edge of the grid or at the corners).\n\nWe define $f(n)$ to be the number of ways this can happen without any ants ending on the same square and without any two ants crossing the same edge between two squares.\n\nYou are given that $f(4) = 88$.\n\nFind $f(10)$.", "raw_html": "

\nAn $n \\times n$ grid of squares contains $n^2$ ants, one ant per square.
\nAll ants decide to move simultaneously to an adjacent square (usually $4$ possibilities, except for ants on the edge of the grid or at the corners).
\nWe define $f(n)$ to be the number of ways this can happen without any ants ending on the same square and without any two ants crossing the same edge between two squares.\n

\n

\nYou are given that $f(4) = 88$.
\nFind $f(10)$.\n

", "url": "https://projecteuler.net/problem=393", "answer": "112398351350823112"} {"id": 394, "problem": "Jeff eats a pie in an unusual way.\n\nThe pie is circular. He starts with slicing an initial cut in the pie along a radius.\n\nWhile there is at least a given fraction $F$ of pie left, he performs the following procedure:\n\n- He makes two slices from the pie centre to any point of what is remaining of the pie border, any point on the remaining pie border equally likely. This will divide the remaining pie into three pieces.\n\n- Going counterclockwise from the initial cut, he takes the first two pie pieces and eats them.\n\nWhen less than a fraction $F$ of pie remains, he does not repeat this procedure. Instead, he eats all of the remaining pie.\n\nFor $x \\ge 1$, let $E(x)$ be the expected number of times Jeff repeats the procedure above with $F = 1/x$.\n\nIt can be verified that $E(1) = 1$, $E(2) \\approx 1.2676536759$, and $E(7.5) \\approx 2.1215732071$.\n\nFind $E(40)$ rounded to $10$ decimal places behind the decimal point.", "raw_html": "

\nJeff eats a pie in an unusual way.
\nThe pie is circular. He starts with slicing an initial cut in the pie along a radius.
\nWhile there is at least a given fraction $F$ of pie left, he performs the following procedure:
\n- He makes two slices from the pie centre to any point of what is remaining of the pie border, any point on the remaining pie border equally likely. This will divide the remaining pie into three pieces.
\n- Going counterclockwise from the initial cut, he takes the first two pie pieces and eats them.
\nWhen less than a fraction $F$ of pie remains, he does not repeat this procedure. Instead, he eats all of the remaining pie.\n

\n

\n\"0394_eatpie.gif\"

\n\n\n

\nFor $x \\ge 1$, let $E(x)$ be the expected number of times Jeff repeats the procedure above with $F = 1/x$.
\nIt can be verified that $E(1) = 1$, $E(2) \\approx 1.2676536759$, and $E(7.5) \\approx 2.1215732071$.\n

\n

\nFind $E(40)$ rounded to $10$ decimal places behind the decimal point.\n

", "url": "https://projecteuler.net/problem=394", "answer": "3.2370342194"} {"id": 395, "problem": "The Pythagorean tree is a fractal generated by the following procedure:\n\nStart with a unit square. Then, calling one of the sides its base (in the animation, the bottom side is the base):\n\n- Attach a right triangle to the side opposite the base, with the hypotenuse coinciding with that side and with the sides in a $3\\text - 4\\text - 5$ ratio. Note that the smaller side of the triangle must be on the 'right' side with respect to the base (see animation).\n\n- Attach a square to each leg of the right triangle, with one of its sides coinciding with that leg.\n\n- Repeat this procedure for both squares, considering as their bases the sides touching the triangle.\n\nThe resulting figure, after an infinite number of iterations, is the Pythagorean tree.\n\nIt can be shown that there exists at least one rectangle, whose sides are parallel to the largest square of the Pythagorean tree, which encloses the Pythagorean tree completely.\n\nFind the smallest area possible for such a bounding rectangle, and give your answer rounded to $10$ decimal places.", "raw_html": "

\nThe Pythagorean tree is a fractal generated by the following procedure:\n

\n\n

\nStart with a unit square. Then, calling one of the sides its base (in the animation, the bottom side is the base):\n

  1. Attach a right triangle to the side opposite the base, with the hypotenuse coinciding with that side and with the sides in a $3\\text - 4\\text - 5$ ratio. Note that the smaller side of the triangle must be on the 'right' side with respect to the base (see animation).
  2. \n
  3. Attach a square to each leg of the right triangle, with one of its sides coinciding with that leg.
  4. \n
  5. Repeat this procedure for both squares, considering as their bases the sides touching the triangle.
  6. \n
\nThe resulting figure, after an infinite number of iterations, is the Pythagorean tree.\n\n\n
\"0395_pythagorean.gif\"
\n\n

\nIt can be shown that there exists at least one rectangle, whose sides are parallel to the largest square of the Pythagorean tree, which encloses the Pythagorean tree completely.\n

\n

\nFind the smallest area possible for such a bounding rectangle, and give your answer rounded to $10$ decimal places.\n

", "url": "https://projecteuler.net/problem=395", "answer": "28.2453753155"} {"id": 396, "problem": "For any positive integer $n$, the $n$th weak Goodstein sequence $\\{g_1, g_2, g_3, \\dots\\}$ is defined as:\n\n- $g_1 = n$\n\n- for $k \\gt 1$, $g_k$ is obtained by writing $g_{k-1}$ in base $k$, interpreting it as a base $k + 1$ number, and subtracting $1$.\n\nThe sequence terminates when $g_k$ becomes $0$.\n\nFor example, the $6$th weak Goodstein sequence is $\\{6, 11, 17, 25, \\dots\\}$:\n\n- $g_1 = 6$.\n\n- $g_2 = 11$ since $6 = 110_2$, $110_3 = 12$, and $12 - 1 = 11$.\n\n- $g_3 = 17$ since $11 = 102_3$, $102_4 = 18$, and $18 - 1 = 17$.\n\n- $g_4 = 25$ since $17 = 101_4$, $101_5 = 26$, and $26 - 1 = 25$.\n\nand so on.\n\nIt can be shown that every weak Goodstein sequence terminates.\n\nLet $G(n)$ be the number of nonzero elements in the $n$th weak Goodstein sequence.\n\nIt can be verified that $G(2) = 3$, $G(4) = 21$ and $G(6) = 381$.\n\nIt can also be verified that $\\sum G(n) = 2517$ for $1 \\le n \\lt 8$.\n\nFind the last $9$ digits of $\\sum G(n)$ for $1 \\le n \\lt 16$.", "raw_html": "

\nFor any positive integer $n$, the $n$th weak Goodstein sequence $\\{g_1, g_2, g_3, \\dots\\}$ is defined as:\n

\nThe sequence terminates when $g_k$ becomes $0$.\n\n

\nFor example, the $6$th weak Goodstein sequence is $\\{6, 11, 17, 25, \\dots\\}$:\n

\nand so on.\n\n

\nIt can be shown that every weak Goodstein sequence terminates.\n

\n

\nLet $G(n)$ be the number of nonzero elements in the $n$th weak Goodstein sequence.
\nIt can be verified that $G(2) = 3$, $G(4) = 21$ and $G(6) = 381$.
\nIt can also be verified that $\\sum G(n) = 2517$ for $1 \\le n \\lt 8$.\n

\n

\nFind the last $9$ digits of $\\sum G(n)$ for $1 \\le n \\lt 16$.\n

", "url": "https://projecteuler.net/problem=396", "answer": "173214653"} {"id": 397, "problem": "On the parabola $y = x^2/k$, three points $A(a, a^2/k)$, $B(b, b^2/k)$ and $C(c, c^2/k)$ are chosen.\n\nLet $F(K, X)$ be the number of the integer quadruplets $(k, a, b, c)$ such that at least one angle of the triangle $ABC$ is $45$-degree, with $1 \\le k \\le K$ and $-X \\le a \\lt b \\lt c \\le X$.\n\nFor example, $F(1, 10) = 41$ and $F(10, 100) = 12492$.\n\nFind $F(10^6, 10^9)$.", "raw_html": "

\nOn the parabola $y = x^2/k$, three points $A(a, a^2/k)$, $B(b, b^2/k)$ and $C(c, c^2/k)$ are chosen.\n

\n

\nLet $F(K, X)$ be the number of the integer quadruplets $(k, a, b, c)$ such that at least one angle of the triangle $ABC$ is $45$-degree, with $1 \\le k \\le K$ and $-X \\le a \\lt b \\lt c \\le X$.\n

\n

\nFor example, $F(1, 10) = 41$ and $F(10, 100) = 12492$.
\nFind $F(10^6, 10^9)$.\n

", "url": "https://projecteuler.net/problem=397", "answer": "141630459461893728"} {"id": 398, "problem": "Inside a rope of length $n$, $n - 1$ points are placed with distance $1$ from each other and from the endpoints. Among these points, we choose $m - 1$ points at random and cut the rope at these points to create $m$ segments.\n\nLet $E(n, m)$ be the expected length of the second-shortest segment.\nFor example, $E(3, 2) = 2$ and $E(8, 3) = 16/7$.\nNote that if multiple segments have the same shortest length the length of the second-shortest segment is defined as the same as the shortest length.\n\nFind $E(10^7, 100)$.\nGive your answer rounded to $5$ decimal places behind the decimal point.", "raw_html": "

\nInside a rope of length $n$, $n - 1$ points are placed with distance $1$ from each other and from the endpoints. Among these points, we choose $m - 1$ points at random and cut the rope at these points to create $m$ segments.\n

\n

\nLet $E(n, m)$ be the expected length of the second-shortest segment.\nFor example, $E(3, 2) = 2$ and $E(8, 3) = 16/7$.\nNote that if multiple segments have the same shortest length the length of the second-shortest segment is defined as the same as the shortest length.\n

\n

\nFind $E(10^7, 100)$.\nGive your answer rounded to $5$ decimal places behind the decimal point.\n

", "url": "https://projecteuler.net/problem=398", "answer": "2010.59096"} {"id": 399, "problem": "The first $15$ Fibonacci numbers are:\n\n$1,1,2,3,5,8,13,21,34,55,89,144,233,377,610$.\n\nIt can be seen that $8$ and $144$ are not squarefree: $8$ is divisible by $4$ and $144$ is divisible by $4$ and by $9$.\n\nSo the first $13$ squarefree Fibonacci numbers are:\n\n$1,1,2,3,5,13,21,34,55,89,233,377$ and $610$.\n\nThe $200$th squarefree Fibonacci number is:\n$971183874599339129547649988289594072811608739584170445$.\n\nThe last sixteen digits of this number are: $1608739584170445$ and in scientific notation this number can be written as $9.7\\mathrm e53$.\n\nFind the $100\\,000\\,000$th squarefree Fibonacci number.\n\nGive as your answer its last sixteen digits followed by a comma followed by the number in scientific notation (rounded to one digit after the decimal point).\n\nFor the $200$th squarefree number the answer would have been: 1608739584170445,9.7e53\n\nNote:\n\nFor this problem, assume that for every prime $p$, the first fibonacci number divisible by $p$ is not divisible by $p^2$ (this is part of Wall's conjecture). This has been verified for primes $\\le 3 \\cdot 10^{15}$, but has not been proven in general.\n\nIf it happens that the conjecture is false, then the accepted answer to this problem isn't guaranteed to be the $100\\,000\\,000$th squarefree Fibonacci number, rather it represents only a lower bound for that number.", "raw_html": "

\nThe first $15$ Fibonacci numbers are:
\n$1,1,2,3,5,8,13,21,34,55,89,144,233,377,610$.
\nIt can be seen that $8$ and $144$ are not squarefree: $8$ is divisible by $4$ and $144$ is divisible by $4$ and by $9$.
\nSo the first $13$ squarefree Fibonacci numbers are:
\n$1,1,2,3,5,13,21,34,55,89,233,377$ and $610$.\n

\n

\nThe $200$th squarefree Fibonacci number is:\n$971183874599339129547649988289594072811608739584170445$.
\nThe last sixteen digits of this number are: $1608739584170445$ and in scientific notation this number can be written as $9.7\\mathrm e53$.\n

\n

\nFind the $100\\,000\\,000$th squarefree Fibonacci number.
\nGive as your answer its last sixteen digits followed by a comma followed by the number in scientific notation (rounded to one digit after the decimal point).
\nFor the $200$th squarefree number the answer would have been: 1608739584170445,9.7e53\n

\n

\n\nNote:
\nFor this problem, assume that for every prime $p$, the first fibonacci number divisible by $p$ is not divisible by $p^2$ (this is part of Wall's conjecture). This has been verified for primes $\\le 3 \\cdot 10^{15}$, but has not been proven in general.
\n\nIf it happens that the conjecture is false, then the accepted answer to this problem isn't guaranteed to be the $100\\,000\\,000$th squarefree Fibonacci number, rather it represents only a lower bound for that number.\n
\n

", "url": "https://projecteuler.net/problem=399", "answer": "1508395636674243,6.5e27330467"} {"id": 400, "problem": "A Fibonacci tree is a binary tree recursively defined as:\n\n- $T(0)$ is the empty tree.\n\n- $T(1)$ is the binary tree with only one node.\n\n- $T(k)$ consists of a root node that has $T(k-1)$ and $T(k-2)$ as children.\n\nOn such a tree two players play a take-away game. On each turn a player selects a node and removes that node along with the subtree rooted at that node.\n\nThe player who is forced to take the root node of the entire tree loses.\n\nHere are the winning moves of the first player on the first turn for $T(k)$ from $k=1$ to $k=6$.\n\nLet $f(k)$ be the number of winning moves of the first player (i.e. the moves for which the second player has no winning strategy) on the first turn of the game when this game is played on $T(k)$.\n\nFor example, $f(5) = 1$ and $f(10) = 17$.\n\nFind $f(10000)$. Give the last $18$ digits of your answer.", "raw_html": "

\nA Fibonacci tree is a binary tree recursively defined as:

\nOn such a tree two players play a take-away game. On each turn a player selects a node and removes that node along with the subtree rooted at that node.
\nThe player who is forced to take the root node of the entire tree loses.

\n\n

\nHere are the winning moves of the first player on the first turn for $T(k)$ from $k=1$ to $k=6$.\n

\"0400_winning.png\"

\n\n\n\nLet $f(k)$ be the number of winning moves of the first player (i.e. the moves for which the second player has no winning strategy) on the first turn of the game when this game is played on $T(k)$.\n\n\n

\nFor example, $f(5) = 1$ and $f(10) = 17$.\n

\n\n

\nFind $f(10000)$. Give the last $18$ digits of your answer.\n

", "url": "https://projecteuler.net/problem=400", "answer": "438505383468410633"} {"id": 401, "problem": "The divisors of $6$ are $1,2,3$ and $6$.\n\nThe sum of the squares of these numbers is $1+4+9+36=50$.\n\nLet $\\operatorname{sigma}_2(n)$ represent the sum of the squares of the divisors of $n$.\nThus $\\operatorname{sigma}_2(6)=50$.\n\nLet $\\operatorname{SIGMA}_2$ represent the summatory function of $\\operatorname{sigma}_2$, that is $\\operatorname{SIGMA}_2(n)=\\sum \\operatorname{sigma}_2(i)$ for $i=1$ to $n$.\n\nThe first $6$ values of $\\operatorname{SIGMA}_2$ are: $1,6,16,37,63$ and $113$.\n\nFind $\\operatorname{SIGMA}_2(10^{15})$ modulo $10^9$.", "raw_html": "

\nThe divisors of $6$ are $1,2,3$ and $6$.
\nThe sum of the squares of these numbers is $1+4+9+36=50$.\n

\n

\nLet $\\operatorname{sigma}_2(n)$ represent the sum of the squares of the divisors of $n$.\nThus $\\operatorname{sigma}_2(6)=50$.\n

\nLet $\\operatorname{SIGMA}_2$ represent the summatory function of $\\operatorname{sigma}_2$, that is $\\operatorname{SIGMA}_2(n)=\\sum \\operatorname{sigma}_2(i)$ for $i=1$ to $n$.
\nThe first $6$ values of $\\operatorname{SIGMA}_2$ are: $1,6,16,37,63$ and $113$.\n\n

\nFind $\\operatorname{SIGMA}_2(10^{15})$ modulo $10^9$. \n

", "url": "https://projecteuler.net/problem=401", "answer": "281632621"} {"id": 402, "problem": "It can be shown that the polynomial $n^4 + 4n^3 + 2n^2 + 5n$ is a multiple of $6$ for every integer $n$. It can also be shown that $6$ is the largest integer satisfying this property.\n\nDefine $M(a, b, c)$ as the maximum $m$ such that $n^4 + an^3 + bn^2 + cn$ is a multiple of $m$ for all integers $n$. For example, $M(4, 2, 5) = 6$.\n\nAlso, define $S(N)$ as the sum of $M(a, b, c)$ for all $0 \\lt a, b, c \\leq N$.\n\nWe can verify that $S(10) = 1972$ and $S(10000) = 2024258331114$.\n\nLet $F_k$ be the Fibonacci sequence:\n\n$F_0 = 0$, $F_1 = 1$ and\n\n$F_k = F_{k-1} + F_{k-2}$ for $k \\geq 2$.\n\nFind the last $9$ digits of $\\sum S(F_k)$ for $2 \\leq k \\leq 1234567890123$.", "raw_html": "

\nIt can be shown that the polynomial $n^4 + 4n^3 + 2n^2 + 5n$ is a multiple of $6$ for every integer $n$. It can also be shown that $6$ is the largest integer satisfying this property.\n

\n

\nDefine $M(a, b, c)$ as the maximum $m$ such that $n^4 + an^3 + bn^2 + cn$ is a multiple of $m$ for all integers $n$. For example, $M(4, 2, 5) = 6$.\n

\n

\nAlso, define $S(N)$ as the sum of $M(a, b, c)$ for all $0 \\lt a, b, c \\leq N$.\n

\n

\nWe can verify that $S(10) = 1972$ and $S(10000) = 2024258331114$.\n

\n

\nLet $F_k$ be the Fibonacci sequence:
\n$F_0 = 0$, $F_1 = 1$ and
\n$F_k = F_{k-1} + F_{k-2}$ for $k \\geq 2$.\n

\n

\nFind the last $9$ digits of $\\sum S(F_k)$ for $2 \\leq k \\leq 1234567890123$.\n

", "url": "https://projecteuler.net/problem=402", "answer": "356019862"} {"id": 403, "problem": "For integers $a$ and $b$, we define $D(a, b)$ as the domain enclosed by the parabola $y = x^2$ and the line $y = a\\cdot x + b$:\n$D(a, b) = \\{(x, y) \\mid x^2 \\leq y \\leq a\\cdot x + b \\}$.\n\n$L(a, b)$ is defined as the number of lattice points contained in $D(a, b)$.\n\nFor example, $L(1, 2) = 8$ and $L(2, -1) = 1$.\n\nWe also define $S(N)$ as the sum of $L(a, b)$ for all the pairs $(a, b)$ such that the area of $D(a, b)$ is a rational number and $|a|,|b| \\leq N$.\n\nWe can verify that $S(5) = 344$ and $S(100) = 26709528$.\n\nFind $S(10^{12})$. Give your answer mod $10^8$.", "raw_html": "

\nFor integers $a$ and $b$, we define $D(a, b)$ as the domain enclosed by the parabola $y = x^2$ and the line $y = a\\cdot x + b$:
$D(a, b) = \\{(x, y) \\mid x^2 \\leq y \\leq a\\cdot x + b \\}$.\n

\n

\n$L(a, b)$ is defined as the number of lattice points contained in $D(a, b)$.
\nFor example, $L(1, 2) = 8$ and $L(2, -1) = 1$.\n

\n

\nWe also define $S(N)$ as the sum of $L(a, b)$ for all the pairs $(a, b)$ such that the area of $D(a, b)$ is a rational number and $|a|,|b| \\leq N$.
\nWe can verify that $S(5) = 344$ and $S(100) = 26709528$.\n

\n

\nFind $S(10^{12})$. Give your answer mod $10^8$.\n

", "url": "https://projecteuler.net/problem=403", "answer": "18224771"} {"id": 404, "problem": "$E_a$ is an ellipse with an equation of the form $x^2 + 4y^2 = 4a^2$.\n\n$E_a^\\prime$ is the rotated image of $E_a$ by $\\theta$ degrees counterclockwise around the origin $O(0, 0)$ for $0^\\circ \\lt \\theta \\lt 90^\\circ$.\n\n$b$ is the distance to the origin of the two intersection points closest to the origin and $c$ is the distance of the two other intersection points.\n\nWe call an ordered triplet $(a, b, c)$ a canonical ellipsoidal triplet if $a, b$ and $c$ are positive integers.\n\nFor example, $(209, 247, 286)$ is a canonical ellipsoidal triplet.\n\nLet $C(N)$ be the number of distinct canonical ellipsoidal triplets $(a, b, c)$ for $a \\leq N$.\n\nIt can be verified that $C(10^3) = 7$, $C(10^4) = 106$ and $C(10^6) = 11845$.\n\nFind $C(10^{17})$.", "raw_html": "

\n$E_a$ is an ellipse with an equation of the form $x^2 + 4y^2 = 4a^2$.
\n$E_a^\\prime$ is the rotated image of $E_a$ by $\\theta$ degrees counterclockwise around the origin $O(0, 0)$ for $0^\\circ \\lt \\theta \\lt 90^\\circ$.\n

\n\n
\n\"0404_c_ellipse.gif\"
\n\n

\n$b$ is the distance to the origin of the two intersection points closest to the origin and $c$ is the distance of the two other intersection points.
\nWe call an ordered triplet $(a, b, c)$ a canonical ellipsoidal triplet if $a, b$ and $c$ are positive integers.
\nFor example, $(209, 247, 286)$ is a canonical ellipsoidal triplet.\n

\n\n

\nLet $C(N)$ be the number of distinct canonical ellipsoidal triplets $(a, b, c)$ for $a \\leq N$.
\nIt can be verified that $C(10^3) = 7$, $C(10^4) = 106$ and $C(10^6) = 11845$.\n

\n\n

\nFind $C(10^{17})$.\n

", "url": "https://projecteuler.net/problem=404", "answer": "1199215615081353"} {"id": 405, "problem": "We wish to tile a rectangle whose length is twice its width.\n\nLet $T(0)$ be the tiling consisting of a single rectangle.\n\nFor $n \\gt 0$, let $T(n)$ be obtained from $T(n-1)$ by replacing all tiles in the following manner:\n\nThe following animation demonstrates the tilings $T(n)$ for $n$ from $0$ to $5$:\n\nLet $f(n)$ be the number of points where four tiles meet in $T(n)$.\n\nFor example, $f(1) = 0$, $f(4) = 82$ and $f(10^9) \\bmod 17^7 = 126897180$.\n\nFind $f(10^k)$ for $k = 10^{18}$, give your answer modulo $17^7$.", "raw_html": "

\nWe wish to tile a rectangle whose length is twice its width.
\nLet $T(0)$ be the tiling consisting of a single rectangle.
\nFor $n \\gt 0$, let $T(n)$ be obtained from $T(n-1)$ by replacing all tiles in the following manner:\n

\n\n
\n\"0405_tile1.png\"
\n\n

\nThe following animation demonstrates the tilings $T(n)$ for $n$ from $0$ to $5$:\n

\n\n
\n\"0405_tile2.gif\"
\n\n

\nLet $f(n)$ be the number of points where four tiles meet in $T(n)$.
\nFor example, $f(1) = 0$, $f(4) = 82$ and $f(10^9) \\bmod 17^7 = 126897180$.\n

\n\n

\nFind $f(10^k)$ for $k = 10^{18}$, give your answer modulo $17^7$.\n

", "url": "https://projecteuler.net/problem=405", "answer": "237696125"} {"id": 406, "problem": "We are trying to find a hidden number selected from the set of integers $\\{1, 2, \\dots, n\\}$ by asking questions.\nEach number (question) we ask, we get one of three possible answers:\n\n- \"Your guess is lower than the hidden number\" (and you incur a cost of $a$), or\n\n- \"Your guess is higher than the hidden number\" (and you incur a cost of $b$), or\n\n- \"Yes, that's it!\" (and the game ends).\n\nGiven the value of $n$, $a$, and $b$, an optimal strategy minimizes the total cost for the worst possible case.\n\nFor example, if $n = 5$, $a = 2$, and $b = 3$, then we may begin by asking \"2\" as our first question.\n\nIf we are told that 2 is higher than the hidden number (for a cost of b=3), then we are sure that \"1\" is the hidden number (for a total cost of 3).\n\nIf we are told that 2 is lower than the hidden number (for a cost of a=2), then our next question will be \"4\".\n\nIf we are told that 4 is higher than the hidden number (for a cost of b=3), then we are sure that \"3\" is the hidden number (for a total cost of 2+3=5).\n\nIf we are told that 4 is lower than the hidden number (for a cost of a=2), then we are sure that \"5\" is the hidden number (for a total cost of 2+2=4).\n\nThus, the worst-case cost achieved by this strategy is 5. It can also be shown that this is the lowest worst-case cost that can be achieved.\nSo, in fact, we have just described an optimal strategy for the given values of $n$, $a$, and $b$.\n\nLet $C(n, a, b)$ be the worst-case cost achieved by an optimal strategy for the given values of $n$, $a$ and $b$.\n\nHere are a few examples:\n\n$C(5, 2, 3) = 5$\n\n$C(500, \\sqrt 2, \\sqrt 3) = 13.22073197\\dots$\n\n$C(20000, 5, 7) = 82$\n\n$C(2000000, \\sqrt 5, \\sqrt 7) = 49.63755955\\dots$\n\nLet $F_k$ be the Fibonacci numbers: $F_k=F_{k-1}+F_{k-2}$ with base cases $F_1=F_2= 1$.\nFind $\\displaystyle \\sum \\limits_{k = 1}^{30} {C \\left (10^{12}, \\sqrt{k}, \\sqrt{F_k} \\right )}$, and give your answer rounded to 8 decimal places behind the decimal point.", "raw_html": "

We are trying to find a hidden number selected from the set of integers $\\{1, 2, \\dots, n\\}$ by asking questions. \nEach number (question) we ask, we get one of three possible answers:

Given the value of $n$, $a$, and $b$, an optimal strategy minimizes the total cost for the worst possible case.

\n\n

For example, if $n = 5$, $a = 2$, and $b = 3$, then we may begin by asking \"2\" as our first question.

\n\n

If we are told that 2 is higher than the hidden number (for a cost of b=3), then we are sure that \"1\" is the hidden number (for a total cost of 3).
\nIf we are told that 2 is lower than the hidden number (for a cost of a=2), then our next question will be \"4\".
\nIf we are told that 4 is higher than the hidden number (for a cost of b=3), then we are sure that \"3\" is the hidden number (for a total cost of 2+3=5).
\nIf we are told that 4 is lower than the hidden number (for a cost of a=2), then we are sure that \"5\" is the hidden number (for a total cost of 2+2=4).
\nThus, the worst-case cost achieved by this strategy is 5. It can also be shown that this is the lowest worst-case cost that can be achieved. \nSo, in fact, we have just described an optimal strategy for the given values of $n$, $a$, and $b$.

\n\n

Let $C(n, a, b)$ be the worst-case cost achieved by an optimal strategy for the given values of $n$, $a$ and $b$.

\n\n

Here are a few examples:
\n$C(5, 2, 3) = 5$
\n$C(500, \\sqrt 2, \\sqrt 3) = 13.22073197\\dots$
\n$C(20000, 5, 7) = 82$
\n$C(2000000, \\sqrt 5, \\sqrt 7) = 49.63755955\\dots$

\n\n

Let $F_k$ be the Fibonacci numbers: $F_k=F_{k-1}+F_{k-2}$ with base cases $F_1=F_2= 1$.
Find $\\displaystyle \\sum \\limits_{k = 1}^{30} {C \\left (10^{12}, \\sqrt{k}, \\sqrt{F_k} \\right )}$, and give your answer rounded to 8 decimal places behind the decimal point.

", "url": "https://projecteuler.net/problem=406", "answer": "36813.12757207"} {"id": 407, "problem": "If we calculate $a^2 \\bmod 6$ for $0 \\leq a \\leq 5$ we get: $0,1,4,3,4,1$.\n\nThe largest value of $a$ such that $a^2 \\equiv a \\bmod 6$ is $4$.\n\nLet's call $M(n)$ the largest value of $a \\lt n$ such that $a^2 \\equiv a \\pmod n$.\n\nSo $M(6) = 4$.\n\nFind $\\sum M(n)$ for $1 \\leq n \\leq 10^7$.", "raw_html": "

\nIf we calculate $a^2 \\bmod 6$ for $0 \\leq a \\leq 5$ we get: $0,1,4,3,4,1$.\n

\n

\nThe largest value of $a$ such that $a^2 \\equiv a \\bmod 6$ is $4$.
\nLet's call $M(n)$ the largest value of $a \\lt n$ such that $a^2 \\equiv a \\pmod n$.
\nSo $M(6) = 4$.\n

\n

\nFind $\\sum M(n)$ for $1 \\leq n \\leq 10^7$.\n

", "url": "https://projecteuler.net/problem=407", "answer": "39782849136421"} {"id": 408, "problem": "Let's call a lattice point $(x, y)$ inadmissible if $x, y$ and $x+y$ are all positive perfect squares.\n\nFor example, $(9, 16)$ is inadmissible, while $(0, 4)$, $(3, 1)$ and $(9, 4)$ are not.\n\nConsider a path from point $(x_1, y_1)$ to point $(x_2, y_2)$ using only unit steps north or east.\n\nLet's call such a path admissible if none of its intermediate points are inadmissible.\n\nLet $P(n)$ be the number of admissible paths from $(0, 0)$ to $(n, n)$.\n\nIt can be verified that $P(5) = 252$, $P(16) = 596994440$ and $P(1000) \\bmod 1\\,000\\,000\\,007 = 341920854$.\n\nFind $P(10\\,000\\,000) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Let's call a lattice point $(x, y)$ inadmissible if $x, y$ and $x+y$ are all positive perfect squares.
\nFor example, $(9, 16)$ is inadmissible, while $(0, 4)$, $(3, 1)$ and $(9, 4)$ are not.

\n\n

Consider a path from point $(x_1, y_1)$ to point $(x_2, y_2)$ using only unit steps north or east.
\nLet's call such a path admissible if none of its intermediate points are inadmissible.

\n\n

Let $P(n)$ be the number of admissible paths from $(0, 0)$ to $(n, n)$.
\nIt can be verified that $P(5) = 252$, $P(16) = 596994440$ and $P(1000) \\bmod 1\\,000\\,000\\,007 = 341920854$.

\n\n

Find $P(10\\,000\\,000) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=408", "answer": "299742733"} {"id": 409, "problem": "Let $n$ be a positive integer. Consider nim positions where:\n\n- There are $n$ non-empty piles.\n\n- Each pile has size less than $2^n$.\n\n- No two piles have the same size.\n\nLet $W(n)$ be the number of winning nim positions satisfying the above conditions (a position is winning if the first player has a winning strategy). For example, $W(1) = 1$, $W(2) = 6$, $W(3) = 168$, $W(5) = 19764360$ and $W(100) \\bmod 1\\,000\\,000\\,007 = 384777056$.\n\nFind $W(10\\,000\\,000) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Let $n$ be a positive integer. Consider nim positions where:

Let $W(n)$ be the number of winning nim positions satisfying the above conditions (a position is winning if the first player has a winning strategy). For example, $W(1) = 1$, $W(2) = 6$, $W(3) = 168$, $W(5) = 19764360$ and $W(100) \\bmod 1\\,000\\,000\\,007 = 384777056$.\n

\n

Find $W(10\\,000\\,000) \\bmod 1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=409", "answer": "253223948"} {"id": 410, "problem": "Let $C$ be the circle with radius $r$, $x^2 + y^2 = r^2$. We choose two points $P(a, b)$ and $Q(-a, c)$ so that the line passing through $P$ and $Q$ is tangent to $C$.\n\nFor example, the quadruplet $(r, a, b, c) = (2, 6, 2, -7)$ satisfies this property.\n\nLet $F(R, X)$ be the number of the integer quadruplets $(r, a, b, c)$ with this property, and with $0 \\lt r \\leq R$ and $0 \\lt a \\leq X$.\n\nWe can verify that $F(1, 5) = 10$, $F(2, 10) = 52$ and $F(10, 100) = 3384$.\n\nFind $F(10^8, 10^9) + F(10^9, 10^8)$.", "raw_html": "

Let $C$ be the circle with radius $r$, $x^2 + y^2 = r^2$. We choose two points $P(a, b)$ and $Q(-a, c)$ so that the line passing through $P$ and $Q$ is tangent to $C$.

\n\n

For example, the quadruplet $(r, a, b, c) = (2, 6, 2, -7)$ satisfies this property.

\n\n

Let $F(R, X)$ be the number of the integer quadruplets $(r, a, b, c)$ with this property, and with $0 \\lt r \\leq R$ and $0 \\lt a \\leq X$.

\n\n

We can verify that $F(1, 5) = 10$, $F(2, 10) = 52$ and $F(10, 100) = 3384$.
\nFind $F(10^8, 10^9) + F(10^9, 10^8)$.

", "url": "https://projecteuler.net/problem=410", "answer": "799999783589946560"} {"id": 411, "problem": "Let $n$ be a positive integer. Suppose there are stations at the coordinates $(x, y) = (2^i \\bmod n, 3^i \\bmod n)$ for $0 \\leq i \\leq 2n$. We will consider stations with the same coordinates as the same station.\n\nWe wish to form a path from $(0, 0)$ to $(n, n)$ such that the $x$ and $y$ coordinates never decrease.\n\nLet $S(n)$ be the maximum number of stations such a path can pass through.\n\nFor example, if $n = 22$, there are $11$ distinct stations, and a valid path can pass through at most $5$ stations. Therefore, $S(22) = 5$.\nThe case is illustrated below, with an example of an optimal path:\n\nIt can also be verified that $S(123) = 14$ and $S(10000) = 48$.\n\nFind $\\sum S(k^5)$ for $1 \\leq k \\leq 30$.", "raw_html": "

\nLet $n$ be a positive integer. Suppose there are stations at the coordinates $(x, y) = (2^i \\bmod n, 3^i \\bmod n)$ for $0 \\leq i \\leq 2n$. We will consider stations with the same coordinates as the same station.\n

\nWe wish to form a path from $(0, 0)$ to $(n, n)$ such that the $x$ and $y$ coordinates never decrease.
\nLet $S(n)$ be the maximum number of stations such a path can pass through.\n

\nFor example, if $n = 22$, there are $11$ distinct stations, and a valid path can pass through at most $5$ stations. Therefore, $S(22) = 5$.\nThe case is illustrated below, with an example of an optimal path:\n

\n

\"0411_longpath.png\"

\n

\nIt can also be verified that $S(123) = 14$ and $S(10000) = 48$.\n

\nFind $\\sum S(k^5)$ for $1 \\leq k \\leq 30$.\n

", "url": "https://projecteuler.net/problem=411", "answer": "9936352"} {"id": 412, "problem": "For integers $m, n$ ($0 \\leq n \\lt m$), let $L(m, n)$ be an $m \\times m$ grid with the top-right $n \\times n$ grid removed.\n\nFor example, $L(5, 3)$ looks like this:\n\nWe want to number each cell of $L(m, n)$ with consecutive integers $1, 2, 3, \\dots$ such that the number in every cell is smaller than the number below it and to the left of it.\n\nFor example, here are two valid numberings of $L(5, 3)$:\n\nLet $\\operatorname{LC}(m, n)$ be the number of valid numberings of $L(m, n)$.\n\nIt can be verified that $\\operatorname{LC}(3, 0) = 42$, $\\operatorname{LC}(5, 3) = 250250$, $\\operatorname{LC}(6, 3) = 406029023400$ and $\\operatorname{LC}(10, 5) \\bmod 76543217 = 61251715$.\n\nFind $\\operatorname{LC}(10000, 5000) \\bmod 76543217$.", "raw_html": "

For integers $m, n$ ($0 \\leq n \\lt m$), let $L(m, n)$ be an $m \\times m$ grid with the top-right $n \\times n$ grid removed.

\n\n

For example, $L(5, 3)$ looks like this:

\n\n

\"0412_table53.png\"

\n\n

We want to number each cell of $L(m, n)$ with consecutive integers $1, 2, 3, \\dots$ such that the number in every cell is smaller than the number below it and to the left of it.

\n\n

For example, here are two valid numberings of $L(5, 3)$:

\n

\"0412_tablenums.png\"

\n\n

Let $\\operatorname{LC}(m, n)$ be the number of valid numberings of $L(m, n)$.
\nIt can be verified that $\\operatorname{LC}(3, 0) = 42$, $\\operatorname{LC}(5, 3) = 250250$, $\\operatorname{LC}(6, 3) = 406029023400$ and $\\operatorname{LC}(10, 5) \\bmod 76543217 = 61251715$.

\n\n

Find $\\operatorname{LC}(10000, 5000) \\bmod 76543217$.

", "url": "https://projecteuler.net/problem=412", "answer": "38788800"} {"id": 413, "problem": "We say that a $d$-digit positive number (no leading zeros) is a one-child number if exactly one of its sub-strings is divisible by $d$.\n\nFor example, $5671$ is a $4$-digit one-child number. Among all its sub-strings $5$, $6$, $7$, $1$, $56$, $67$, $71$, $567$, $671$ and $5671$, only $56$ is divisible by $4$.\n\nSimilarly, $104$ is a $3$-digit one-child number because only $0$ is divisible by $3$.\n\n$1132451$ is a $7$-digit one-child number because only $245$ is divisible by $7$.\n\nLet $F(N)$ be the number of the one-child numbers less than $N$.\n\nWe can verify that $F(10) = 9$, $F(10^3) = 389$ and $F(10^7) = 277674$.\n\nFind $F(10^{19})$.", "raw_html": "

We say that a $d$-digit positive number (no leading zeros) is a one-child number if exactly one of its sub-strings is divisible by $d$.

\n\n

For example, $5671$ is a $4$-digit one-child number. Among all its sub-strings $5$, $6$, $7$, $1$, $56$, $67$, $71$, $567$, $671$ and $5671$, only $56$ is divisible by $4$.
\nSimilarly, $104$ is a $3$-digit one-child number because only $0$ is divisible by $3$.
\n$1132451$ is a $7$-digit one-child number because only $245$ is divisible by $7$.

\n\n

Let $F(N)$ be the number of the one-child numbers less than $N$.
\nWe can verify that $F(10) = 9$, $F(10^3) = 389$ and $F(10^7) = 277674$.

\n\n

Find $F(10^{19})$.

", "url": "https://projecteuler.net/problem=413", "answer": "3079418648040719"} {"id": 414, "problem": "$6174$ is a remarkable number; if we sort its digits in increasing order and subtract that number from the number you get when you sort the digits in decreasing order, we get $7641-1467=6174$.\n\nEven more remarkable is that if we start from any $4$ digit number and repeat this process of sorting and subtracting, we'll eventually end up with $6174$ or immediately with $0$ if all digits are equal.\n\nThis also works with numbers that have less than $4$ digits if we pad the number with leading zeroes until we have $4$ digits.\n\nE.g. let's start with the number $0837$:\n\n$8730-0378=8352$\n\n$8532-2358=6174$\n\n$6174$ is called the Kaprekar constant. The process of sorting and subtracting and repeating this until either $0$ or the Kaprekar constant is reached is called the Kaprekar routine.\n\nWe can consider the Kaprekar routine for other bases and number of digits.\n\nUnfortunately, it is not guaranteed a Kaprekar constant exists in all cases; either the routine can end up in a cycle for some input numbers or the constant the routine arrives at can be different for different input numbers.\n\nHowever, it can be shown that for $5$ digits and a base $b = 6t+3\\neq 9$, a Kaprekar constant exists.\n\nE.g. base $15$: $(10,4,14,9,5)_{15}$\n\nbase $21$: $(14,6,20,13,7)_{21}$\n\nDefine $C_b$ to be the Kaprekar constant in base $b$ for $5$ digits.\nDefine the function $sb(i)$ to be\n\n- $0$ if $i = C_b$ or if $i$ written in base $b$ consists of $5$ identical digits\n\n- the number of iterations it takes the Kaprekar routine in base $b$ to arrive at $C_b$, otherwise\n\nNote that we can define $sb(i)$ for all integers $i \\lt b^5$. If $i$ written in base $b$ takes less than $5$ digits, the number is padded with leading zero digits until we have $5$ digits before applying the Kaprekar routine.\n\nDefine $S(b)$ as the sum of $sb(i)$ for $0 \\lt i \\lt b^5$.\n\nE.g. $S(15) = 5274369$\n\n$S(111) = 400668930299$\n\nFind the sum of $S(6k+3)$ for $2 \\leq k \\leq 300$.\n\nGive the last $18$ digits as your answer.", "raw_html": "

\n$6174$ is a remarkable number; if we sort its digits in increasing order and subtract that number from the number you get when you sort the digits in decreasing order, we get $7641-1467=6174$.
\nEven more remarkable is that if we start from any $4$ digit number and repeat this process of sorting and subtracting, we'll eventually end up with $6174$ or immediately with $0$ if all digits are equal.
\nThis also works with numbers that have less than $4$ digits if we pad the number with leading zeroes until we have $4$ digits.
\nE.g. let's start with the number $0837$:
\n$8730-0378=8352$
\n$8532-2358=6174$\n

\n

\n$6174$ is called the Kaprekar constant. The process of sorting and subtracting and repeating this until either $0$ or the Kaprekar constant is reached is called the Kaprekar routine.\n

\n

\nWe can consider the Kaprekar routine for other bases and number of digits.
\nUnfortunately, it is not guaranteed a Kaprekar constant exists in all cases; either the routine can end up in a cycle for some input numbers or the constant the routine arrives at can be different for different input numbers.
\nHowever, it can be shown that for $5$ digits and a base $b = 6t+3\\neq 9$, a Kaprekar constant exists.
\nE.g. base $15$: $(10,4,14,9,5)_{15}$
\nbase $21$: $(14,6,20,13,7)_{21}$

\n

\nDefine $C_b$ to be the Kaprekar constant in base $b$ for $5$ digits.\nDefine the function $sb(i)$ to be\n

\nNote that we can define $sb(i)$ for all integers $i \\lt b^5$. If $i$ written in base $b$ takes less than $5$ digits, the number is padded with leading zero digits until we have $5$ digits before applying the Kaprekar routine.\n\n

\nDefine $S(b)$ as the sum of $sb(i)$ for $0 \\lt i \\lt b^5$.
\nE.g. $S(15) = 5274369$
\n$S(111) = 400668930299$\n

\n

\nFind the sum of $S(6k+3)$ for $2 \\leq k \\leq 300$.
\nGive the last $18$ digits as your answer.\n

", "url": "https://projecteuler.net/problem=414", "answer": "552506775824935461"} {"id": 415, "problem": "A set of lattice points $S$ is called a titanic set if there exists a line passing through exactly two points in $S$.\n\nAn 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$.\n\nOn 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.\n\nFor any positive integer $N$, let $T(N)$ be the number of titanic sets $S$ whose every point $(x, y)$ satisfies $0 \\leq x, y \\leq N$.\nIt can be verified that $T(1) = 11$, $T(2) = 494$, $T(4) = 33554178$, $T(111) \\bmod 10^8 = 13500401$ and $T(10^5) \\bmod 10^8 = 63259062$.\n\nFind $T(10^{11})\\bmod 10^8$.", "raw_html": "

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

\n\n

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$.

\n\n

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.

\n\n

For any positive integer $N$, let $T(N)$ be the number of titanic sets $S$ whose every point $(x, y)$ satisfies $0 \\leq x, y \\leq N$.\nIt can be verified that $T(1) = 11$, $T(2) = 494$, $T(4) = 33554178$, $T(111) \\bmod 10^8 = 13500401$ and $T(10^5) \\bmod 10^8 = 63259062$.

\n\n

Find $T(10^{11})\\bmod 10^8$.

", "url": "https://projecteuler.net/problem=415", "answer": "55859742"} {"id": 416, "problem": "A row of $n$ squares contains a frog in the leftmost square. By successive jumps the frog goes to the rightmost square and then back to the leftmost square. On the outward trip he jumps one, two or three squares to the right, and on the homeward trip he jumps to the left in a similar manner. He cannot jump outside the squares. He repeats the round-trip travel $m$ times.\n\nLet $F(m, n)$ be the number of the ways the frog can travel so that at most one square remains unvisited.\n\nFor example, $F(1, 3) = 4$, $F(1, 4) = 15$, $F(1, 5) = 46$, $F(2, 3) = 16$ and $F(2, 100) \\bmod 10^9 = 429619151$.\n\nFind the last $9$ digits of $F(10, 10^{12})$.", "raw_html": "

A row of $n$ squares contains a frog in the leftmost square. By successive jumps the frog goes to the rightmost square and then back to the leftmost square. On the outward trip he jumps one, two or three squares to the right, and on the homeward trip he jumps to the left in a similar manner. He cannot jump outside the squares. He repeats the round-trip travel $m$ times.

\n\n

Let $F(m, n)$ be the number of the ways the frog can travel so that at most one square remains unvisited.
\nFor example, $F(1, 3) = 4$, $F(1, 4) = 15$, $F(1, 5) = 46$, $F(2, 3) = 16$ and $F(2, 100) \\bmod 10^9 = 429619151$.

\n\n

Find the last $9$ digits of $F(10, 10^{12})$.

", "url": "https://projecteuler.net/problem=416", "answer": "898082747"} {"id": 417, "problem": "A unit fraction contains $1$ in the numerator. The decimal representation of the unit fractions with denominators $2$ to $10$ are given:\n\n$$\\begin{align}\n1/2 &= 0.5\\\\\n1/3 &=0.(3)\\\\\n1/4 &=0.25\\\\\n1/5 &= 0.2\\\\\n1/6 &= 0.1(6)\\\\\n1/7 &= 0.(142857)\\\\\n1/8 &= 0.125\\\\\n1/9 &= 0.(1)\\\\\n1/10 &= 0.1\n\\end{align}$$\n\nWhere $0.1(6)$ means $0.166666\\cdots$, and has a $1$-digit recurring cycle. It can be seen that $1/7$ has a $6$-digit recurring cycle.\n\nUnit fractions whose denominator has no other prime factors than $2$ and/or $5$ are not considered to have a recurring cycle.\n\nWe define the length of the recurring cycle of those unit fractions as $0$.\n\nLet $L(n)$ denote the length of the recurring cycle of $1/n$.\nYou are given that $\\sum L(n)$ for $3 \\leq n \\leq 1\\,000\\,000$ equals $55535191115$.\n\nFind $\\sum L(n)$ for $3 \\leq n \\leq 100\\,000\\,000$.", "raw_html": "

A unit fraction contains $1$ in the numerator. The decimal representation of the unit fractions with denominators $2$ to $10$ are given:

\n$$\\begin{align}\n1/2 &= 0.5\\\\\n1/3 &=0.(3)\\\\\n1/4 &=0.25\\\\\n1/5 &= 0.2\\\\\n1/6 &= 0.1(6)\\\\\n1/7 &= 0.(142857)\\\\\n1/8 &= 0.125\\\\\n1/9 &= 0.(1)\\\\\n1/10 &= 0.1\n\\end{align}$$\n\n

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

\n

\nUnit fractions whose denominator has no other prime factors than $2$ and/or $5$ are not considered to have a recurring cycle.
\nWe define the length of the recurring cycle of those unit fractions as $0$.\n

\n

\nLet $L(n)$ denote the length of the recurring cycle of $1/n$.\nYou are given that $\\sum L(n)$ for $3 \\leq n \\leq 1\\,000\\,000$ equals $55535191115$.\n

\n

\nFind $\\sum L(n)$ for $3 \\leq n \\leq 100\\,000\\,000$.

", "url": "https://projecteuler.net/problem=417", "answer": "446572970925740"} {"id": 418, "problem": "Let $n$ be a positive integer. An integer triple $(a, b, c)$ is called a factorisation triple of $n$ if:\n\n- $1 \\leq a \\leq b \\leq c$\n- $a \\cdot b \\cdot c = n$.\n\nDefine $f(n)$ to be $a + b + c$ for the factorisation triple $(a, b, c)$ of $n$ which minimises $c / a$. One can show that this triple is unique.\n\nFor example, $f(165) = 19$, $f(100100) = 142$ and $f(20!) = 4034872$.\n\nFind $f(43!)$.", "raw_html": "

\nLet $n$ be a positive integer. An integer triple $(a, b, c)$ is called a factorisation triple of $n$ if:

\nDefine $f(n)$ to be $a + b + c$ for the factorisation triple $(a, b, c)$ of $n$ which minimises $c / a$. One can show that this triple is unique.\n

\n

\nFor example, $f(165) = 19$, $f(100100) = 142$ and $f(20!) = 4034872$.\n

\n

\nFind $f(43!)$.\n

", "url": "https://projecteuler.net/problem=418", "answer": "1177163565297340320"} {"id": 419, "problem": "The look and say sequence goes 1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ...\n\nThe sequence starts with 1 and all other members are obtained by describing the previous member in terms of consecutive digits.\n\nIt helps to do this out loud:\n\n1 is 'one one' → 11\n\n11 is 'two ones' → 21\n\n21 is 'one two and one one' → 1211\n\n1211 is 'one one, one two and two ones' → 111221\n\n111221 is 'three ones, two twos and one one' → 312211\n\n...\n\nDefine $A(n)$, $B(n)$ and $C(n)$ as the number of ones, twos and threes in the $n$'th element of the sequence respectively.\n\nOne can verify that $A(40) = 31254$, $B(40) = 20259$ and $C(40) = 11625$.\n\nFind $A(n)$, $B(n)$ and $C(n)$ for $n = 10^{12}$.\n\nGive your answer modulo $2^{30}$ and separate your values for $A$, $B$ and $C$ by a comma.\n\nE.g. for $n = 40$ the answer would be 31254,20259,11625", "raw_html": "

\nThe look and say sequence goes 1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ...
\nThe sequence starts with 1 and all other members are obtained by describing the previous member in terms of consecutive digits.
\nIt helps to do this out loud:
\n1 is 'one one' → 11
\n11 is 'two ones' → 21
\n21 is 'one two and one one' → 1211
\n1211 is 'one one, one two and two ones' → 111221
\n111221 is 'three ones, two twos and one one' → 312211
\n...\n

\n

\nDefine $A(n)$, $B(n)$ and $C(n)$ as the number of ones, twos and threes in the $n$'th element of the sequence respectively.
\nOne can verify that $A(40) = 31254$, $B(40) = 20259$ and $C(40) = 11625$.\n

\n

\nFind $A(n)$, $B(n)$ and $C(n)$ for $n = 10^{12}$.
\nGive your answer modulo $2^{30}$ and separate your values for $A$, $B$ and $C$ by a comma.
\nE.g. for $n = 40$ the answer would be 31254,20259,11625\n

", "url": "https://projecteuler.net/problem=419", "answer": "998567458,1046245404,43363922"} {"id": 420, "problem": "A positive integer matrix is a matrix whose elements are all positive integers.\n\nSome positive integer matrices can be expressed as a square of a positive integer matrix in two different ways. Here is an example:\n\n$$\\begin{pmatrix}\n40 & 12\\\\\n48 & 40\n\\end{pmatrix} =\n\\begin{pmatrix}\n2 & 3\\\\\n12 & 2\n\\end{pmatrix}^2 =\n\\begin{pmatrix}\n6 & 1\\\\\n4 & 6\n\\end{pmatrix}^2\n$$\n\nWe define $F(N)$ as the number of the $2\\times 2$ positive integer matrices which have a tracethe sum of the elements on the main diagonal less than $N$ and which can be expressed as a square of a positive integer matrix in two different ways.\n\nWe can verify that $F(50) = 7$ and $F(1000) = 1019$.\n\nFind $F(10^7)$.", "raw_html": "

A positive integer matrix is a matrix whose elements are all positive integers.
\nSome positive integer matrices can be expressed as a square of a positive integer matrix in two different ways. Here is an example:

\n\n$$\\begin{pmatrix}\n40 & 12\\\\\n48 & 40\n\\end{pmatrix} =\n\\begin{pmatrix}\n2 & 3\\\\\n12 & 2\n\\end{pmatrix}^2 =\n\\begin{pmatrix}\n6 & 1\\\\\n4 & 6\n\\end{pmatrix}^2\n$$\n\n

\nWe define $F(N)$ as the number of the $2\\times 2$ positive integer matrices which have a tracethe sum of the elements on the main diagonal less than $N$ and which can be expressed as a square of a positive integer matrix in two different ways.
\nWe can verify that $F(50) = 7$ and $F(1000) = 1019$.\n

\n\n

\nFind $F(10^7)$.\n

", "url": "https://projecteuler.net/problem=420", "answer": "145159332"} {"id": 421, "problem": "Numbers of the form $n^{15}+1$ are composite for every integer $n \\gt 1$.\n\nFor positive integers $n$ and $m$ let $s(n,m)$ be defined as the sum of the distinct prime factors of $n^{15}+1$ not exceeding $m$.\n\nE.g. $2^{15}+1 = 3 \\times 3 \\times 11 \\times 331$.\n\nSo $s(2,10) = 3$ and $s(2,1000) = 3+11+331 = 345$.\n\nAlso $10^{15}+1 = 7 \\times 11 \\times 13 \\times 211 \\times 241 \\times 2161 \\times 9091$.\n\nSo $s(10,100) = 31$ and $s(10,1000) = 483$.\n\nFind $\\sum s(n,10^8)$ for $1 \\leq n \\leq 10^{11}$.", "raw_html": "

\nNumbers of the form $n^{15}+1$ are composite for every integer $n \\gt 1$.
\nFor positive integers $n$ and $m$ let $s(n,m)$ be defined as the sum of the distinct prime factors of $n^{15}+1$ not exceeding $m$.\n

\nE.g. $2^{15}+1 = 3 \\times 3 \\times 11 \\times 331$.
\nSo $s(2,10) = 3$ and $s(2,1000) = 3+11+331 = 345$.

\n\nAlso $10^{15}+1 = 7 \\times 11 \\times 13 \\times 211 \\times 241 \\times 2161 \\times 9091$.
\nSo $s(10,100) = 31$ and $s(10,1000) = 483$.

\nFind $\\sum s(n,10^8)$ for $1 \\leq n \\leq 10^{11}$.\n

", "url": "https://projecteuler.net/problem=421", "answer": "2304215802083466198"} {"id": 422, "problem": "Let $H$ be the hyperbola defined by the equation $12x^2 + 7xy - 12y^2 = 625$.\n\nNext, define $X$ as the point $(7, 1)$. It can be seen that $X$ is in $H$.\n\nNow we define a sequence of points in $H$, $\\{P_i: i \\geq 1\\}$, as:\n\n- $P_1 = (13, 61/4)$.\n\n- $P_2 = (-43/6, -4)$.\n\n- For $i \\gt 2$, $P_i$ is the unique point in $H$ that is different from $P_{i-1}$ and such that line $P_iP_{i-1}$ is parallel to line $P_{i-2}X$. It can be shown that $P_i$ is well-defined, and that its coordinates are always rational.\n\nYou are given that $P_3 = (-19/2, -229/24)$, $P_4 = (1267/144, -37/12)$ and $P_7 = (17194218091/143327232, 274748766781/1719926784)$.\n\nFind $P_n$ for $n = 11^{14}$ in the following format:\nIf $P_n = (a/b, c/d)$ where the fractions are in lowest terms and the denominators are positive, then the answer is $(a + b + c + d) \\bmod 1\\,000\\,000\\,007$.\n\nFor $n = 7$, the answer would have been: $806236837$.", "raw_html": "

Let $H$ be the hyperbola defined by the equation $12x^2 + 7xy - 12y^2 = 625$.

\n\n

Next, define $X$ as the point $(7, 1)$. It can be seen that $X$ is in $H$.

\n\n

Now we define a sequence of points in $H$, $\\{P_i: i \\geq 1\\}$, as:\n

\n
\"0422_hyperbola.gif\"
\n

You are given that $P_3 = (-19/2, -229/24)$, $P_4 = (1267/144, -37/12)$ and $P_7 = (17194218091/143327232, 274748766781/1719926784)$.

\n\n

Find $P_n$ for $n = 11^{14}$ in the following format:
If $P_n = (a/b, c/d)$ where the fractions are in lowest terms and the denominators are positive, then the answer is $(a + b + c + d) \\bmod 1\\,000\\,000\\,007$.

\n\n

For $n = 7$, the answer would have been: $806236837$.

", "url": "https://projecteuler.net/problem=422", "answer": "92060460"} {"id": 423, "problem": "Let $n$ be a positive integer.\n\nA 6-sided die is thrown $n$ times. Let $c$ be the number of pairs of consecutive throws that give the same value.\n\nFor example, if $n = 7$ and the values of the die throws are (1,1,5,6,6,6,3), then the following pairs of consecutive throws give the same value:\n\n(1,1,5,6,6,6,3)\n\n(1,1,5,6,6,6,3)\n\n(1,1,5,6,6,6,3)\n\nTherefore, $c = 3$ for (1,1,5,6,6,6,3).\n\nDefine $C(n)$ as the number of outcomes of throwing a 6-sided die $n$ times such that $c$ does not exceed $\\pi(n)$.1\n\nFor example, $C(3) = 216$, $C(4) = 1290$, $C(11) = 361912500$ and $C(24) = 4727547363281250000$.\n\nDefine $S(L)$ as $\\sum C(n)$ for $1 \\leq n \\leq L$.\n\nFor example, $S(50) \\bmod 1\\,000\\,000\\,007 = 832833871$.\n\nFind $S(50\\,000\\,000) \\bmod 1\\,000\\,000\\,007$.\n\n1 $\\pi$ denotes the prime-counting function, i.e. $\\pi(n)$ is the number of primes $\\leq n$.", "raw_html": "

Let $n$ be a positive integer.
\nA 6-sided die is thrown $n$ times. Let $c$ be the number of pairs of consecutive throws that give the same value.

\n\n

For example, if $n = 7$ and the values of the die throws are (1,1,5,6,6,6,3), then the following pairs of consecutive throws give the same value:
\n(1,1,5,6,6,6,3)
\n(1,1,5,6,6,6,3)
\n(1,1,5,6,6,6,3)
\nTherefore, $c = 3$ for (1,1,5,6,6,6,3).

\n\n

Define $C(n)$ as the number of outcomes of throwing a 6-sided die $n$ times such that $c$ does not exceed $\\pi(n)$.1
\nFor example, $C(3) = 216$, $C(4) = 1290$, $C(11) = 361912500$ and $C(24) = 4727547363281250000$.

\n\n

Define $S(L)$ as $\\sum C(n)$ for $1 \\leq n \\leq L$.
\nFor example, $S(50) \\bmod 1\\,000\\,000\\,007 = 832833871$.

\n\n

Find $S(50\\,000\\,000) \\bmod 1\\,000\\,000\\,007$.

\n\n

1 $\\pi$ denotes the prime-counting function, i.e. $\\pi(n)$ is the number of primes $\\leq n$.

", "url": "https://projecteuler.net/problem=423", "answer": "653972374"} {"id": 424, "problem": "The above is an example of a cryptic kakuro (also known as cross sums, or even sums cross) puzzle, with its final solution on the right. (The common rules of kakuro puzzles can be found easily on numerous internet sites. Other related information can also be currently found at krazydad.com whose author has provided the puzzle data for this challenge.)\n\nThe downloadable text file (kakuro200.txt) contains the description of 200 such puzzles, a mix of 5x5 and 6x6 types. The first puzzle in the file is the above example which is coded as follows:\n\n6,X,X,(vCC),(vI),X,X,X,(hH),B,O,(vCA),(vJE),X,(hFE,vD),O,O,O,O,(hA),O,I,(hJC,vB),O,O,(hJC),H,O,O,O,X,X,X,(hJE),O,O,X\n\nThe first character is a numerical digit indicating the size of the information grid. It would be either a 6 (for a 5x5 kakuro puzzle) or a 7 (for a 6x6 puzzle) followed by a comma (,). The extra top line and left column are needed to insert information.\n\nThe content of each cell is then described and followed by a comma, going left to right and starting with the top line.\n\nX = Gray cell, not required to be filled by a digit.\n\nO (upper case letter)= White empty cell to be filled by a digit.\n\nA = Or any one of the upper case letters from A to J to be replaced by its equivalent digit in the solved puzzle.\n\n( ) = Location of the encrypted sums. Horizontal sums are preceded by a lower case \"h\" and vertical sums are preceded by a lower case \"v\". Those are followed by one or two upper case letters depending if the sum is a single digit or double digit one. For double digit sums, the first letter would be for the \"tens\" and the second one for the \"units\". When the cell must contain information for both a horizontal and a vertical sum, the first one is always for the horizontal sum and the two are separated by a comma within the same set of brackets, ex.: (hFE,vD). Each set of brackets is also immediately followed by a comma.\n\nThe description of the last cell is followed by a Carriage Return/Line Feed (CRLF) instead of a comma.\n\nThe required answer to each puzzle is based on the value of each letter necessary to arrive at the solution and according to the alphabetical order. As indicated under the example puzzle, its answer would be 8426039571. At least 9 out of the 10 encrypting letters are always part of the problem description. When only 9 are given, the missing one must be assigned the remaining digit.\n\nYou are given that the sum of the answers for the first 10 puzzles in the file is 64414157580.\n\nFind the sum of the answers for the 200 puzzles.", "raw_html": "
\"0424_kakuro1.gif\"
\n\n

The above is an example of a cryptic kakuro (also known as cross sums, or even sums cross) puzzle, with its final solution on the right. (The common rules of kakuro puzzles can be found easily on numerous internet sites. Other related information can also be currently found at krazydad.com whose author has provided the puzzle data for this challenge.)

\n\n

The downloadable text file (kakuro200.txt) contains the description of 200 such puzzles, a mix of 5x5 and 6x6 types. The first puzzle in the file is the above example which is coded as follows:

\n\n

6,X,X,(vCC),(vI),X,X,X,(hH),B,O,(vCA),(vJE),X,(hFE,vD),O,O,O,O,(hA),O,I,(hJC,vB),O,O,(hJC),H,O,O,O,X,X,X,(hJE),O,O,X

\n\n

The first character is a numerical digit indicating the size of the information grid. It would be either a 6 (for a 5x5 kakuro puzzle) or a 7 (for a 6x6 puzzle) followed by a comma (,). The extra top line and left column are needed to insert information.

\n\n

The content of each cell is then described and followed by a comma, going left to right and starting with the top line.
\nX = Gray cell, not required to be filled by a digit.
\nO (upper case letter)= White empty cell to be filled by a digit.
\nA = Or any one of the upper case letters from A to J to be replaced by its equivalent digit in the solved puzzle.
\n( ) = Location of the encrypted sums. Horizontal sums are preceded by a lower case \"h\" and vertical sums are preceded by a lower case \"v\". Those are followed by one or two upper case letters depending if the sum is a single digit or double digit one. For double digit sums, the first letter would be for the \"tens\" and the second one for the \"units\". When the cell must contain information for both a horizontal and a vertical sum, the first one is always for the horizontal sum and the two are separated by a comma within the same set of brackets, ex.: (hFE,vD). Each set of brackets is also immediately followed by a comma.

\n\n

The description of the last cell is followed by a Carriage Return/Line Feed (CRLF) instead of a comma.

\n\n

The required answer to each puzzle is based on the value of each letter necessary to arrive at the solution and according to the alphabetical order. As indicated under the example puzzle, its answer would be 8426039571. At least 9 out of the 10 encrypting letters are always part of the problem description. When only 9 are given, the missing one must be assigned the remaining digit.

\n\n

You are given that the sum of the answers for the first 10 puzzles in the file is 64414157580.

\n\n

Find the sum of the answers for the 200 puzzles.

", "url": "https://projecteuler.net/problem=424", "answer": "1059760019628"} {"id": 425, "problem": "Two positive numbers $A$ and $B$ are said to be connected (denoted by \"$A \\leftrightarrow B$\") if one of these conditions holds:\n\n(1) $A$ and $B$ have the same length and differ in exactly one digit; for example, $123 \\leftrightarrow 173$.\n\n(2) Adding one digit to the left of $A$ (or $B$) makes $B$ (or $A$); for example, $23 \\leftrightarrow 223$ and $123 \\leftrightarrow 23$.\n\nWe call a prime $P$ a $2$'s relative if there exists a chain of connected primes between $2$ and $P$ and no prime in the chain exceeds $P$.\n\nFor example, $127$ is a $2$'s relative. One of the possible chains is shown below:\n\n$2 \\leftrightarrow 3 \\leftrightarrow 13 \\leftrightarrow 113 \\leftrightarrow 103 \\leftrightarrow 107 \\leftrightarrow 127$\n\nHowever, $11$ and $103$ are not $2$'s relatives.\n\nLet $F(N)$ be the sum of the primes $\\leq N$ which are not $2$'s relatives.\n\nWe can verify that $F(10^3) = 431$ and $F(10^4) = 78728$.\n\nFind $F(10^7)$.", "raw_html": "

\nTwo positive numbers $A$ and $B$ are said to be connected (denoted by \"$A \\leftrightarrow B$\") if one of these conditions holds:
\n(1) $A$ and $B$ have the same length and differ in exactly one digit; for example, $123 \\leftrightarrow 173$.
\n(2) Adding one digit to the left of $A$ (or $B$) makes $B$ (or $A$); for example, $23 \\leftrightarrow 223$ and $123 \\leftrightarrow 23$.\n

\n

\nWe call a prime $P$ a $2$'s relative if there exists a chain of connected primes between $2$ and $P$ and no prime in the chain exceeds $P$.\n

\n

\nFor example, $127$ is a $2$'s relative. One of the possible chains is shown below:
\n$2 \\leftrightarrow 3 \\leftrightarrow 13 \\leftrightarrow 113 \\leftrightarrow 103 \\leftrightarrow 107 \\leftrightarrow 127$
\nHowever, $11$ and $103$ are not $2$'s relatives.\n

\n

\nLet $F(N)$ be the sum of the primes $\\leq N$ which are not $2$'s relatives.
\nWe can verify that $F(10^3) = 431$ and $F(10^4) = 78728$.\n

\n

\nFind $F(10^7)$.\n

", "url": "https://projecteuler.net/problem=425", "answer": "46479497324"} {"id": 426, "problem": "Consider an infinite row of boxes. Some of the boxes contain a ball. For example, an initial configuration of 2 consecutive occupied boxes followed by 2 empty boxes, 2 occupied boxes, 1 empty box, and 2 occupied boxes can be denoted by the sequence (2, 2, 2, 1, 2), in which the number of consecutive occupied and empty boxes appear alternately.\n\nA turn consists of moving each ball exactly once according to the following rule: Transfer the leftmost ball which has not been moved to the nearest empty box to its right.\n\nAfter one turn the sequence (2, 2, 2, 1, 2) becomes (2, 2, 1, 2, 3) as can be seen below; note that we begin the new sequence starting at the first occupied box.\n\nA system like this is called a Box-Ball System or BBS for short.\n\nIt can be shown that after a sufficient number of turns, the system evolves to a state where the consecutive numbers of occupied boxes is invariant. In the example below, the consecutive numbers of occupied boxes evolves to [1, 2, 3]; we shall call this the final state.\n\nWe define the sequence {ti}:\n\n- s0 = 290797\n\n- sk+1 = sk2 mod 50515093\n\n- tk = (sk mod 64) + 1\n\nStarting from the initial configuration (t0, t1, …, t10), the final state becomes [1, 3, 10, 24, 51, 75].\n\nStarting from the initial configuration (t0, t1, …, t10 000 000), find the final state.\n\nGive as your answer the sum of the squares of the elements of the final state. For example, if the final state is [1, 2, 3] then 14 ( = 12 + 22 + 32) is your answer.", "raw_html": "

\nConsider an infinite row of boxes. Some of the boxes contain a ball. For example, an initial configuration of 2 consecutive occupied boxes followed by 2 empty boxes, 2 occupied boxes, 1 empty box, and 2 occupied boxes can be denoted by the sequence (2, 2, 2, 1, 2), in which the number of consecutive occupied and empty boxes appear alternately.\n

\n

\nA turn consists of moving each ball exactly once according to the following rule: Transfer the leftmost ball which has not been moved to the nearest empty box to its right.\n

\n

\nAfter one turn the sequence (2, 2, 2, 1, 2) becomes (2, 2, 1, 2, 3) as can be seen below; note that we begin the new sequence starting at the first occupied box.\n

\n\n
\n\"0426_baxball1.gif\"
\n\n

\nA system like this is called a Box-Ball System or BBS for short.\n

\n

\nIt can be shown that after a sufficient number of turns, the system evolves to a state where the consecutive numbers of occupied boxes is invariant. In the example below, the consecutive numbers of occupied boxes evolves to [1, 2, 3]; we shall call this the final state.\n

\n\n
\n\"0426_baxball2.gif\"
\n\n

\nWe define the sequence {ti}:

\nStarting from the initial configuration (t0, t1, …, t10), the final state becomes [1, 3, 10, 24, 51, 75].
\nStarting from the initial configuration (t0, t1, …, t10 000 000), find the final state.
\nGive as your answer the sum of the squares of the elements of the final state. For example, if the final state is [1, 2, 3] then 14 ( = 12 + 22 + 32) is your answer.\n

", "url": "https://projecteuler.net/problem=426", "answer": "31591886008"} {"id": 427, "problem": "A sequence of integers $S = \\{s_i\\}$ is called an $n$-sequence if it has $n$ elements and each element $s_i$ satisfies $1 \\leq s_i \\leq n$. Thus there are $n^n$ distinct $n$-sequences in total.\nFor example, the sequence $S = \\{1, 5, 5, 10, 7, 7, 7, 2, 3, 7\\}$ is a $10$-sequence.\n\nFor any sequence $S$, let $L(S)$ be the length of the longest contiguous subsequence of $S$ with the same value.\nFor example, for the given sequence $S$ above, $L(S) = 3$, because of the three consecutive $7$'s.\n\nLet $f(n) = \\sum L(S)$ for all $n$-sequences S.\n\nFor example, $f(3) = 45$, $f(7) = 1403689$ and $f(11) = 481496895121$.\n\nFind $f(7\\,500\\,000) \\bmod 1\\,000\\,000\\,009$.", "raw_html": "

A sequence of integers $S = \\{s_i\\}$ is called an $n$-sequence if it has $n$ elements and each element $s_i$ satisfies $1 \\leq s_i \\leq n$. Thus there are $n^n$ distinct $n$-sequences in total.\nFor example, the sequence $S = \\{1, 5, 5, 10, 7, 7, 7, 2, 3, 7\\}$ is a $10$-sequence.

\n\n

For any sequence $S$, let $L(S)$ be the length of the longest contiguous subsequence of $S$ with the same value.\nFor example, for the given sequence $S$ above, $L(S) = 3$, because of the three consecutive $7$'s.

\n\n

Let $f(n) = \\sum L(S)$ for all $n$-sequences S.

\n\n

For example, $f(3) = 45$, $f(7) = 1403689$ and $f(11) = 481496895121$.

\n\n

Find $f(7\\,500\\,000) \\bmod 1\\,000\\,000\\,009$.

", "url": "https://projecteuler.net/problem=427", "answer": "97138867"} {"id": 428, "problem": "Let $a$, $b$ and $c$ be positive numbers.\n\nLet $W, X, Y, Z$ be four collinear points where $|WX| = a$, $|XY| = b$, $|YZ| = c$ and $|WZ| = a + b + c$.\n\nLet $C_{in}$ be the circle having the diameter $XY$.\n\nLet $C_{out}$ be the circle having the diameter $WZ$.\n\nThe triplet $(a, b, c)$ is called a necklace triplet if you can place $k \\geq 3$ distinct circles $C_1, C_2, \\dots, C_k$ such that:\n\n- $C_i$ has no common interior points with any $C_j$ for $1 \\leq i, j \\leq k$ and $i \\neq j$,\n\n- $C_i$ is tangent to both $C_{in}$ and $C_{out}$ for $1 \\leq i \\leq k$,\n\n- $C_i$ is tangent to $C_{i+1}$ for $1 \\leq i \\lt k$, and\n\n- $C_k$ is tangent to $C_1$.\n\nFor example, $(5, 5, 5)$ and $(4, 3, 21)$ are necklace triplets, while it can be shown that $(2, 2, 5)$ is not.\n\nLet $T(n)$ be the number of necklace triplets $(a, b, c)$ such that $a$, $b$ and $c$ are positive integers, and $b \\leq n$.\nFor example, $T(1) = 9$, $T(20) = 732$ and $T(3000) = 438106$.\n\nFind $T(1\\,000\\,000\\,000)$.", "raw_html": "

Let $a$, $b$ and $c$ be positive numbers.
\nLet $W, X, Y, Z$ be four collinear points where $|WX| = a$, $|XY| = b$, $|YZ| = c$ and $|WZ| = a + b + c$.
\nLet $C_{in}$ be the circle having the diameter $XY$.
\nLet $C_{out}$ be the circle having the diameter $WZ$.

\n\n

\nThe triplet $(a, b, c)$ is called a necklace triplet if you can place $k \\geq 3$ distinct circles $C_1, C_2, \\dots, C_k$ such that:\n

\nFor example, $(5, 5, 5)$ and $(4, 3, 21)$ are necklace triplets, while it can be shown that $(2, 2, 5)$ is not.\n

\n

\"0428_necklace.png\"

\n\n

\nLet $T(n)$ be the number of necklace triplets $(a, b, c)$ such that $a$, $b$ and $c$ are positive integers, and $b \\leq n$.\nFor example, $T(1) = 9$, $T(20) = 732$ and $T(3000) = 438106$.\n

\n

\nFind $T(1\\,000\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=428", "answer": "747215561862"} {"id": 429, "problem": "A unitary divisor $d$ of a number $n$ is a divisor of $n$ that has the property $\\gcd(d, n/d) = 1$.\n\nThe unitary divisors of $4! = 24$ are $1, 3, 8$ and $24$.\n\nThe sum of their squares is $1^2 + 3^2 + 8^2 + 24^2 = 650$.\n\nLet $S(n)$ represent the sum of the squares of the unitary divisors of $n$. Thus $S(4!)=650$.\n\nFind $S(100\\,000\\,000!)$ modulo $1\\,000\\,000\\,009$.", "raw_html": "

\nA unitary divisor $d$ of a number $n$ is a divisor of $n$ that has the property $\\gcd(d, n/d) = 1$.
\nThe unitary divisors of $4! = 24$ are $1, 3, 8$ and $24$.
\nThe sum of their squares is $1^2 + 3^2 + 8^2 + 24^2 = 650$.\n

\n

\nLet $S(n)$ represent the sum of the squares of the unitary divisors of $n$. Thus $S(4!)=650$.\n

\n

\nFind $S(100\\,000\\,000!)$ modulo $1\\,000\\,000\\,009$.\n

", "url": "https://projecteuler.net/problem=429", "answer": "98792821"} {"id": 430, "problem": "$N$ disks are placed in a row, indexed $1$ to $N$ from left to right.\n\nEach disk has a black side and white side. Initially all disks show their white side.\n\nAt each turn, two, not necessarily distinct, integers $A$ and $B$ between $1$ and $N$ (inclusive) are chosen uniformly at random.\n\nAll disks with an index from $A$ to $B$ (inclusive) are flipped.\n\nThe following example shows the case $N = 8$. At the first turn $A = 5$ and $B = 2$, and at the second turn $A = 4$ and $B = 6$.\n\nLet $E(N, M)$ be the expected number of disks that show their white side after $M$ turns.\n\nWe can verify that $E(3, 1) = 10/9$, $E(3, 2) = 5/3$, $E(10, 4) \\approx 5.157$ and $E(100, 10) \\approx 51.893$.\n\nFind $E(10^{10}, 4000)$.\n\nGive your answer rounded to $2$ decimal places behind the decimal point.", "raw_html": "

$N$ disks are placed in a row, indexed $1$ to $N$ from left to right.
\nEach disk has a black side and white side. Initially all disks show their white side.

\n\n

At each turn, two, not necessarily distinct, integers $A$ and $B$ between $1$ and $N$ (inclusive) are chosen uniformly at random.
\nAll disks with an index from $A$ to $B$ (inclusive) are flipped.

\n\n

The following example shows the case $N = 8$. At the first turn $A = 5$ and $B = 2$, and at the second turn $A = 4$ and $B = 6$.

\n\n

\"0430_flips.gif\"

\n\n

Let $E(N, M)$ be the expected number of disks that show their white side after $M$ turns.
\nWe can verify that $E(3, 1) = 10/9$, $E(3, 2) = 5/3$, $E(10, 4) \\approx 5.157$ and $E(100, 10) \\approx 51.893$.

\n\n

Find $E(10^{10}, 4000)$.
\nGive your answer rounded to $2$ decimal places behind the decimal point.

", "url": "https://projecteuler.net/problem=430", "answer": "5000624921.38"} {"id": 431, "problem": "Fred the farmer arranges to have a new storage silo installed on his farm and having an obsession for all things square he is absolutely devastated when he discovers that it is circular. Quentin, the representative from the company that installed the silo, explains that they only manufacture cylindrical silos, but he points out that it is resting on a square base. Fred is not amused and insists that it is removed from his property.\n\nQuick thinking Quentin explains that when granular materials are delivered from above a conical slope is formed and the natural angle made with the horizontal is called the angle of repose. For example if the angle of repose, $\\alpha = 30$ degrees, and grain is delivered at the centre of the silo then a perfect cone will form towards the top of the cylinder. In the case of this silo, which has a diameter of $6\\mathrm m$, the amount of space wasted would be approximately $32.648388556\\mathrm{m^3}$. However, if grain is delivered at a point on the top which has a horizontal distance of $x$ metres from the centre then a cone with a strangely curved and sloping base is formed. He shows Fred a picture.\n\n\n\nWe shall let the amount of space wasted in cubic metres be given by $V(x)$. If $x = 1.114785284$, which happens to have three squared decimal places, then the amount of space wasted, $V(1.114785284) \\approx 36$. Given the range of possible solutions to this problem there is exactly one other option: $V(2.511167869) \\approx 49$. It would be like knowing that the square is king of the silo, sitting in splendid glory on top of your grain.\n\nFred's eyes light up with delight at this elegant resolution, but on closer inspection of Quentin's drawings and calculations his happiness turns to despondency once more. Fred points out to Quentin that it's the radius of the silo that is $6$ metres, not the diameter, and the angle of repose for his grain is $40$ degrees. However, if Quentin can find a set of solutions for this particular silo then he will be more than happy to keep it.\n\nIf Quick thinking Quentin is to satisfy frustratingly fussy Fred the farmer's appetite for all things square then determine the values of $x$ for all possible square space wastage options and calculate $\\sum x$ correct to $9$ decimal places.", "raw_html": "

Fred the farmer arranges to have a new storage silo installed on his farm and having an obsession for all things square he is absolutely devastated when he discovers that it is circular. Quentin, the representative from the company that installed the silo, explains that they only manufacture cylindrical silos, but he points out that it is resting on a square base. Fred is not amused and insists that it is removed from his property.

\n\n

Quick thinking Quentin explains that when granular materials are delivered from above a conical slope is formed and the natural angle made with the horizontal is called the angle of repose. For example if the angle of repose, $\\alpha = 30$ degrees, and grain is delivered at the centre of the silo then a perfect cone will form towards the top of the cylinder. In the case of this silo, which has a diameter of $6\\mathrm m$, the amount of space wasted would be approximately $32.648388556\\mathrm{m^3}$. However, if grain is delivered at a point on the top which has a horizontal distance of $x$ metres from the centre then a cone with a strangely curved and sloping base is formed. He shows Fred a picture.

\n\n
\n \"0431_grain_silo.png\"
\n\n

We shall let the amount of space wasted in cubic metres be given by $V(x)$. If $x = 1.114785284$, which happens to have three squared decimal places, then the amount of space wasted, $V(1.114785284) \\approx 36$. Given the range of possible solutions to this problem there is exactly one other option: $V(2.511167869) \\approx 49$. It would be like knowing that the square is king of the silo, sitting in splendid glory on top of your grain.

\n\n

Fred's eyes light up with delight at this elegant resolution, but on closer inspection of Quentin's drawings and calculations his happiness turns to despondency once more. Fred points out to Quentin that it's the radius of the silo that is $6$ metres, not the diameter, and the angle of repose for his grain is $40$ degrees. However, if Quentin can find a set of solutions for this particular silo then he will be more than happy to keep it.

\n\n

If Quick thinking Quentin is to satisfy frustratingly fussy Fred the farmer's appetite for all things square then determine the values of $x$ for all possible square space wastage options and calculate $\\sum x$ correct to $9$ decimal places.

", "url": "https://projecteuler.net/problem=431", "answer": "23.386029052"} {"id": 432, "problem": "Let $S(n,m) = \\sum\\phi(n \\times i)$ for $1 \\leq i \\leq m$. ($\\phi$ is Euler's totient function)\n\nYou are given that $S(510510,10^6)= 45480596821125120$.\n\nFind $S(510510,10^{11})$.\n\nGive the last $9$ digits of your answer.", "raw_html": "

\nLet $S(n,m) = \\sum\\phi(n \\times i)$ for $1 \\leq i \\leq m$. ($\\phi$ is Euler's totient function)
\nYou are given that $S(510510,10^6)= 45480596821125120$. \n

\n

\nFind $S(510510,10^{11})$.
\nGive the last $9$ digits of your answer.\n

", "url": "https://projecteuler.net/problem=432", "answer": "754862080"} {"id": 433, "problem": "Let $E(x_0, y_0)$ be the number of steps it takes to determine the greatest common divisor of $x_0$ and $y_0$ with Euclid's algorithm. More formally:\n$x_1 = y_0$, $y_1 = x_0 \\bmod y_0$\n$x_n = y_{n-1}$, $y_n = x_{n-1} \\bmod y_{n-1}$\n\n$E(x_0, y_0)$ is the smallest $n$ such that $y_n = 0$.\n\nWe have $E(1,1) = 1$, $E(10,6) = 3$ and $E(6,10) = 4$.\n\nDefine $S(N)$ as the sum of $E(x,y)$ for $1 \\leq x,y \\leq N$.\n\nWe have $S(1) = 1$, $S(10) = 221$ and $S(100) = 39826$.\n\nFind $S(5\\cdot 10^6)$.", "raw_html": "

\nLet $E(x_0, y_0)$ be the number of steps it takes to determine the greatest common divisor of $x_0$ and $y_0$ with Euclid's algorithm. More formally:
$x_1 = y_0$, $y_1 = x_0 \\bmod y_0$
$x_n = y_{n-1}$, $y_n = x_{n-1} \\bmod y_{n-1}$
\n$E(x_0, y_0)$ is the smallest $n$ such that $y_n = 0$.\n

\n

\nWe have $E(1,1) = 1$, $E(10,6) = 3$ and $E(6,10) = 4$.\n

\n

\nDefine $S(N)$ as the sum of $E(x,y)$ for $1 \\leq x,y \\leq N$.
\nWe have $S(1) = 1$, $S(10) = 221$ and $S(100) = 39826$.\n

\n

\nFind $S(5\\cdot 10^6)$.\n

", "url": "https://projecteuler.net/problem=433", "answer": "326624372659664"} {"id": 434, "problem": "Recall that a graph is a collection of vertices and edges connecting the vertices, and that two vertices connected by an edge are called adjacent.\n\nGraphs can be embedded in Euclidean space by associating each vertex with a point in the Euclidean space.\n\nA flexible graph is an embedding of a graph where it is possible to move one or more vertices continuously so that the distance between at least two nonadjacent vertices is altered while the distances between each pair of adjacent vertices is kept constant.\n\nA rigid graph is an embedding of a graph which is not flexible.\n\nInformally, a graph is rigid if by replacing the vertices with fully rotating hinges and the edges with rods that are unbending and inelastic, no parts of the graph can be moved independently from the rest of the graph.\n\nThe grid graphs embedded in the Euclidean plane are not rigid, as the following animation demonstrates:\n\nHowever, one can make them rigid by adding diagonal edges to the cells. For example, for the $2\\times 3$ grid graph, there are $19$ ways to make the graph rigid:\n\nNote that for the purposes of this problem, we do not consider changing the orientation of a diagonal edge or adding both diagonal edges to a cell as a different way of making a grid graph rigid.\n\nLet $R(m,n)$ be the number of ways to make the $m \\times n$ grid graph rigid.\n\nE.g. $R(2,3) = 19$ and $R(5,5) = 23679901$.\n\nDefine $S(N)$ as $\\sum R(i,j)$ for $1 \\leq i, j \\leq N$.\n\nE.g. $S(5) = 25021721$.\n\nFind $S(100)$, give your answer modulo $1000000033$.", "raw_html": "

Recall that a graph is a collection of vertices and edges connecting the vertices, and that two vertices connected by an edge are called adjacent.
\nGraphs can be embedded in Euclidean space by associating each vertex with a point in the Euclidean space.
\nA flexible graph is an embedding of a graph where it is possible to move one or more vertices continuously so that the distance between at least two nonadjacent vertices is altered while the distances between each pair of adjacent vertices is kept constant.
\nA rigid graph is an embedding of a graph which is not flexible.
\nInformally, a graph is rigid if by replacing the vertices with fully rotating hinges and the edges with rods that are unbending and inelastic, no parts of the graph can be moved independently from the rest of the graph.\n

\n

The grid graphs embedded in the Euclidean plane are not rigid, as the following animation demonstrates:

\n
\"0434_rigid.gif\"
\n

However, one can make them rigid by adding diagonal edges to the cells. For example, for the $2\\times 3$ grid graph, there are $19$ ways to make the graph rigid:

\n
\"0434_rigid23.png\"
\n

Note that for the purposes of this problem, we do not consider changing the orientation of a diagonal edge or adding both diagonal edges to a cell as a different way of making a grid graph rigid.\n

\n

Let $R(m,n)$ be the number of ways to make the $m \\times n$ grid graph rigid.
\nE.g. $R(2,3) = 19$ and $R(5,5) = 23679901$.\n

\n

Define $S(N)$ as $\\sum R(i,j)$ for $1 \\leq i, j \\leq N$.
\nE.g. $S(5) = 25021721$.
\nFind $S(100)$, give your answer modulo $1000000033$.\n

", "url": "https://projecteuler.net/problem=434", "answer": "863253606"} {"id": 435, "problem": "The Fibonacci numbers $\\{f_n, n \\ge 0\\}$ are defined recursively as $f_n = f_{n-1} + f_{n-2}$ with base cases $f_0 = 0$ and $f_1 = 1$.\n\nDefine the polynomials $\\{F_n, n \\ge 0\\}$ as $F_n(x) = \\displaystyle{\\sum_{i=0}^n f_i x^i}$.\n\nFor example, $F_7(x) = x + x^2 + 2x^3 + 3x^4 + 5x^5 + 8x^6 + 13x^7$, and $F_7(11) = 268\\,357\\,683$.\n\nLet $n = 10^{15}$. Find the sum $\\displaystyle{\\sum_{x=0}^{100} F_n(x)}$ and give your answer modulo $1\\,307\\,674\\,368\\,000 \\ (= 15!)$.", "raw_html": "

The Fibonacci numbers $\\{f_n, n \\ge 0\\}$ are defined recursively as $f_n = f_{n-1} + f_{n-2}$ with base cases $f_0 = 0$ and $f_1 = 1$.

\n

Define the polynomials $\\{F_n, n \\ge 0\\}$ as $F_n(x) = \\displaystyle{\\sum_{i=0}^n f_i x^i}$.

\n

For example, $F_7(x) = x + x^2 + 2x^3 + 3x^4 + 5x^5 + 8x^6 + 13x^7$, and $F_7(11) = 268\\,357\\,683$.

\n

Let $n = 10^{15}$. Find the sum $\\displaystyle{\\sum_{x=0}^{100} F_n(x)}$ and give your answer modulo $1\\,307\\,674\\,368\\,000 \\ (= 15!)$.

", "url": "https://projecteuler.net/problem=435", "answer": "252541322550"} {"id": 436, "problem": "Julie proposes the following wager to her sister Louise.\n\nShe suggests they play a game of chance to determine who will wash the dishes.\n\nFor this game, they shall use a generator of independent random numbers uniformly distributed between $0$ and $1$.\n\nThe game starts with $S = 0$.\n\nThe first player, Louise, adds to $S$ different random numbers from the generator until $S \\gt 1$ and records her last random number '$x$'.\n\nThe second player, Julie, continues adding to $S$ different random numbers from the generator until $S \\gt 2$ and records her last random number '$y$'.\n\nThe player with the highest number wins and the loser washes the dishes, i.e. if $y \\gt x$ the second player wins.\n\nFor example, if the first player draws $0.62$ and $0.44$, the first player turn ends since $0.62+0.44 \\gt 1$ and $x = 0.44$.\n\nIf the second players draws $0.1$, $0.27$ and $0.91$, the second player turn ends since $0.62+0.44+0.1+0.27+0.91 \\gt 2$ and $y = 0.91$.\nSince $y \\gt x$, the second player wins.\n\nLouise thinks about it for a second, and objects: \"That's not fair\".\n\nWhat is the probability that the second player wins?\n\nGive your answer rounded to $10$ places behind the decimal point in the form 0.abcdefghij.", "raw_html": "

Julie proposes the following wager to her sister Louise.
\nShe suggests they play a game of chance to determine who will wash the dishes.
\nFor this game, they shall use a generator of independent random numbers uniformly distributed between $0$ and $1$.
\nThe game starts with $S = 0$.
\nThe first player, Louise, adds to $S$ different random numbers from the generator until $S \\gt 1$ and records her last random number '$x$'.
\nThe second player, Julie, continues adding to $S$ different random numbers from the generator until $S \\gt 2$ and records her last random number '$y$'.
\nThe player with the highest number wins and the loser washes the dishes, i.e. if $y \\gt x$ the second player wins.

\n\n

For example, if the first player draws $0.62$ and $0.44$, the first player turn ends since $0.62+0.44 \\gt 1$ and $x = 0.44$.
\nIf the second players draws $0.1$, $0.27$ and $0.91$, the second player turn ends since $0.62+0.44+0.1+0.27+0.91 \\gt 2$ and $y = 0.91$.\nSince $y \\gt x$, the second player wins.

\n\n

Louise thinks about it for a second, and objects: \"That's not fair\".
\nWhat is the probability that the second player wins?
\nGive your answer rounded to $10$ places behind the decimal point in the form 0.abcdefghij.

", "url": "https://projecteuler.net/problem=436", "answer": "0.5276662759"} {"id": 437, "problem": "When we calculate $8^n$ modulo $11$ for $n=0$ to $9$ we get: $1, 8, 9, 6, 4, 10, 3, 2, 5, 7$.\n\nAs we see all possible values from $1$ to $10$ occur. So $8$ is a primitive root of $11$.\n\nBut there is more:\n\nIf we take a closer look we see:\n\n$1+8=9$\n\n$8+9=17 \\equiv 6 \\bmod 11$\n\n$9+6=15 \\equiv 4 \\bmod 11$\n\n$6+4=10$\n\n$4+10=14 \\equiv 3 \\bmod 11$\n\n$10+3=13 \\equiv 2 \\bmod 11$\n\n$3+2=5$\n\n$2+5=7$\n\n$5+7=12 \\equiv 1 \\bmod 11$.\n\nSo the powers of $8 \\bmod 11$ are cyclic with period $10$, and $8^n + 8^{n+1} \\equiv 8^{n+2} \\pmod{11}$.\n\n$8$ is called a Fibonacci primitive root of $11$.\n\nNot every prime has a Fibonacci primitive root.\n\nThere are $323$ primes less than $10000$ with one or more Fibonacci primitive roots and the sum of these primes is $1480491$.\n\nFind the sum of the primes less than $100\\,000\\,000$ with at least one Fibonacci primitive root.", "raw_html": "

\nWhen we calculate $8^n$ modulo $11$ for $n=0$ to $9$ we get: $1, 8, 9, 6, 4, 10, 3, 2, 5, 7$.
\nAs we see all possible values from $1$ to $10$ occur. So $8$ is a primitive root of $11$.
\nBut there is more:
\nIf we take a closer look we see:
\n$1+8=9$
\n$8+9=17 \\equiv 6 \\bmod 11$
\n$9+6=15 \\equiv 4 \\bmod 11$
\n$6+4=10$
\n$4+10=14 \\equiv 3 \\bmod 11$
\n$10+3=13 \\equiv 2 \\bmod 11$
\n$3+2=5$
\n$2+5=7$
\n$5+7=12 \\equiv 1 \\bmod 11$.\n

\nSo the powers of $8 \\bmod 11$ are cyclic with period $10$, and $8^n + 8^{n+1} \\equiv 8^{n+2} \\pmod{11}$.
\n$8$ is called a Fibonacci primitive root of $11$.
\nNot every prime has a Fibonacci primitive root.
\nThere are $323$ primes less than $10000$ with one or more Fibonacci primitive roots and the sum of these primes is $1480491$.
\nFind the sum of the primes less than $100\\,000\\,000$ with at least one Fibonacci primitive root.", "url": "https://projecteuler.net/problem=437", "answer": "74204709657207"} {"id": 438, "problem": "For an $n$-tuple of integers $t = (a_1, \\dots, a_n)$, let $(x_1, \\dots, x_n)$ be the solutions of the polynomial equation $x^n + a_1 x^{n-1} + a_2 x^{n-2} + \\cdots + a_{n-1}x + a_n = 0$.\n\nConsider the following two conditions:\n\n- $x_1, \\dots, x_n$ are all real.\n\n- If $x_1, \\dots, x_n$ are sorted, $\\lfloor x_i\\rfloor = i$ for $1 \\leq i \\leq n$. ($\\lfloor \\cdot \\rfloor$: floor function.)\n\nIn the case of $n = 4$, there are $12$ $n$-tuples of integers which satisfy both conditions.\n\nWe define $S(t)$ as the sum of the absolute values of the integers in $t$.\n\nFor $n = 4$ we can verify that $\\sum S(t) = 2087$ for all $n$-tuples $t$ which satisfy both conditions.\n\nFind $\\sum S(t)$ for $n = 7$.", "raw_html": "

\nFor an $n$-tuple of integers $t = (a_1, \\dots, a_n)$, let $(x_1, \\dots, x_n)$ be the solutions of the polynomial equation $x^n + a_1 x^{n-1} + a_2 x^{n-2} + \\cdots + a_{n-1}x + a_n = 0$.\n

\n

\nConsider the following two conditions:\n

\nIn the case of $n = 4$, there are $12$ $n$-tuples of integers which satisfy both conditions.
\nWe define $S(t)$ as the sum of the absolute values of the integers in $t$.
\nFor $n = 4$ we can verify that $\\sum S(t) = 2087$ for all $n$-tuples $t$ which satisfy both conditions.\n

\n

\nFind $\\sum S(t)$ for $n = 7$.\n

", "url": "https://projecteuler.net/problem=438", "answer": "2046409616809"} {"id": 439, "problem": "Let $d(k)$ be the sum of all divisors of $k$.\n\nWe define the function $S(N) = \\sum_{i=1}^N \\sum_{j=1}^Nd(i \\cdot j)$.\n\nFor example, $S(3) = d(1) + d(2) + d(3) + d(2) + d(4) + d(6) + d(3) + d(6) + d(9) = 59$.\n\nYou are given that $S(10^3) = 563576517282$ and $S(10^5) \\bmod 10^9 = 215766508$.\n\nFind $S(10^{11}) \\bmod 10^9$.", "raw_html": "

Let $d(k)$ be the sum of all divisors of $k$.
\nWe define the function $S(N) = \\sum_{i=1}^N \\sum_{j=1}^Nd(i \\cdot j)$.
\nFor example, $S(3) = d(1) + d(2) + d(3) + d(2) + d(4) + d(6) + d(3) + d(6) + d(9) = 59$.

\n\n

You are given that $S(10^3) = 563576517282$ and $S(10^5) \\bmod 10^9 = 215766508$.
\nFind $S(10^{11}) \\bmod 10^9$.

", "url": "https://projecteuler.net/problem=439", "answer": "968697378"} {"id": 440, "problem": "We want to tile a board of length $n$ and height $1$ completely, with either $1 \\times 2$ blocks or $1 \\times 1$ blocks with a single decimal digit on top:\n\nFor example, here are some of the ways to tile a board of length $n = 8$:\n\nLet $T(n)$ be the number of ways to tile a board of length $n$ as described above.\n\nFor example, $T(1) = 10$ and $T(2) = 101$.\n\nLet $S(L)$ be the triple sum $\\sum_{a, b, c}\\gcd(T(c^a), T(c^b))$ for $1 \\leq a, b, c \\leq L$.\n\nFor example:\n\n$S(2) = 10444$\n\n$S(3) = 1292115238446807016106539989$\n\n$S(4) \\bmod 987\\,898\\,789 = 670616280$.\n\nFind $S(2000) \\bmod 987\\,898\\,789$.", "raw_html": "

We want to tile a board of length $n$ and height $1$ completely, with either $1 \\times 2$ blocks or $1 \\times 1$ blocks with a single decimal digit on top:

\n
\n\"0440_tiles.png\"\n
\n

For example, here are some of the ways to tile a board of length $n = 8$:

\n\n
\n\"0440_some8.png\"\n
\n

Let $T(n)$ be the number of ways to tile a board of length $n$ as described above.

\n\n

For example, $T(1) = 10$ and $T(2) = 101$.

\n\n

Let $S(L)$ be the triple sum $\\sum_{a, b, c}\\gcd(T(c^a), T(c^b))$ for $1 \\leq a, b, c \\leq L$.
\nFor example:
\n$S(2) = 10444$
\n$S(3) = 1292115238446807016106539989$
\n$S(4) \\bmod 987\\,898\\,789 = 670616280$.

\n\n

Find $S(2000) \\bmod 987\\,898\\,789$.

", "url": "https://projecteuler.net/problem=440", "answer": "970746056"} {"id": 441, "problem": "For an integer $M$, we define $R(M)$ as the sum of $1/(p \\cdot q)$ for all the integer pairs $p$ and $q$ which satisfy all of these conditions:\n\n- $1 \\leq p \\lt q \\leq M$\n\n- $p + q \\geq M$\n\n- $p$ and $q$ are coprime.\n\nWe also define $S(N)$ as the sum of $R(i)$ for $2 \\leq i \\leq N$.\n\nWe can verify that $S(2) = R(2) = 1/2$, $S(10) \\approx 6.9147$ and $S(100) \\approx 58.2962$.\n\nFind $S(10^7)$. Give your answer rounded to four decimal places.", "raw_html": "

\nFor an integer $M$, we define $R(M)$ as the sum of $1/(p \\cdot q)$ for all the integer pairs $p$ and $q$ which satisfy all of these conditions:\n

\n

\nWe also define $S(N)$ as the sum of $R(i)$ for $2 \\leq i \\leq N$.
\nWe can verify that $S(2) = R(2) = 1/2$, $S(10) \\approx 6.9147$ and $S(100) \\approx 58.2962$.\n

\n

\nFind $S(10^7)$. Give your answer rounded to four decimal places.\n

", "url": "https://projecteuler.net/problem=441", "answer": "5000088.8395"} {"id": 442, "problem": "An integer is called eleven-free if its decimal expansion does not contain any substring representing a power of $11$ except $1$.\n\nFor example, $2404$ and $13431$ are eleven-free, while $911$ and $4121331$ are not.\n\nLet $E(n)$ be the $n$th positive eleven-free integer. For example, $E(3) = 3$, $E(200) = 213$ and $E(500\\,000) = 531563$.\n\nFind $E(10^{18})$.", "raw_html": "

An integer is called eleven-free if its decimal expansion does not contain any substring representing a power of $11$ except $1$.

\n\n

For example, $2404$ and $13431$ are eleven-free, while $911$ and $4121331$ are not.

\n\n

Let $E(n)$ be the $n$th positive eleven-free integer. For example, $E(3) = 3$, $E(200) = 213$ and $E(500\\,000) = 531563$.

\n\n

Find $E(10^{18})$.

", "url": "https://projecteuler.net/problem=442", "answer": "1295552661530920149"} {"id": 443, "problem": "Let $g(n)$ be a sequence defined as follows:\n\n$g(4) = 13$,\n\n$g(n) = g(n-1) + \\gcd(n, g(n-1))$ for $n \\gt 4$.\n\nThe first few values are:\n\n\n\n| $n$ | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | ... |\n| $g(n)$ | 13 | 14 | 16 | 17 | 18 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 51 | 54 | 55 | 60 | ... |\n\nYou are given that $g(1\\,000) = 2524$ and $g(1\\,000\\,000) = 2624152$.\n\nFind $g(10^{15})$.", "raw_html": "

Let $g(n)$ be a sequence defined as follows:
\n$g(4) = 13$,
\n$g(n) = g(n-1) + \\gcd(n, g(n-1))$ for $n \\gt 4$.

\n\n

The first few values are:

\n
\n \n \n
$n$4567891011121314151617181920...
$g(n)$1314161718272829303132333451545560...
\n\n

You are given that $g(1\\,000) = 2524$ and $g(1\\,000\\,000) = 2624152$.

\n\n

Find $g(10^{15})$.

", "url": "https://projecteuler.net/problem=443", "answer": "2744233049300770"} {"id": 444, "problem": "A group of $p$ people decide to sit down at a round table and play a lottery-ticket trading game. Each person starts off with a randomly-assigned, unscratched lottery ticket. Each ticket, when scratched, reveals a whole-pound prize ranging anywhere from £1 to £$p$, with no two tickets alike. The goal of the game is for all of the players to maximize the winnings of the ticket they hold upon leaving the game.\n\nAn arbitrary person is chosen to be the first player. Going around the table, each player has only one of two options:\n\n- The player can choose to scratch the ticket and reveal its worth to everyone at the table.\n\n- If the player's ticket is unscratched, then the player may trade it with a previous player's scratched ticket, and then leaves the game with that ticket. The previous player then scratches the newly-acquired ticket and reveals its worth to everyone at the table.\n\nThe game ends once all tickets have been scratched. All players still remaining at the table must leave with their currently-held tickets.\n\nAssume that players will use the optimal strategy for maximizing the expected value of their ticket winnings.\n\nLet $E(p)$ represent the expected number of players left at the table when the game ends in a game consisting of $p$ players.\n\nE.g. $E(111) = 5.2912$ when rounded to 5 significant digits.\n\nLet $S_1(N) = \\sum \\limits_{p = 1}^{N} {E(p)}$.\n\nLet $S_k(N) = \\sum \\limits_{p = 1}^{N} {S_{k-1}(p)}$ for $k \\gt 1$.\n\nFind $S_{20}(10^{14})$ and write the answer in scientific notation rounded to 10 significant digits. Use a lowercase e to separate mantissa and exponent. For example, the answer for $S_3(100)$ would be 5.983679014e5.", "raw_html": "

A group of $p$ people decide to sit down at a round table and play a lottery-ticket trading game. Each person starts off with a randomly-assigned, unscratched lottery ticket. Each ticket, when scratched, reveals a whole-pound prize ranging anywhere from £1 to £$p$, with no two tickets alike. The goal of the game is for all of the players to maximize the winnings of the ticket they hold upon leaving the game.

\n\n

An arbitrary person is chosen to be the first player. Going around the table, each player has only one of two options:

\n\n
    \n
  1. The player can choose to scratch the ticket and reveal its worth to everyone at the table.
  2. \n
  3. If the player's ticket is unscratched, then the player may trade it with a previous player's scratched ticket, and then leaves the game with that ticket. The previous player then scratches the newly-acquired ticket and reveals its worth to everyone at the table.
  4. \n
\n\n

The game ends once all tickets have been scratched. All players still remaining at the table must leave with their currently-held tickets.

\n\n

Assume that players will use the optimal strategy for maximizing the expected value of their ticket winnings.

\n\n

Let $E(p)$ represent the expected number of players left at the table when the game ends in a game consisting of $p$ players.
\nE.g. $E(111) = 5.2912$ when rounded to 5 significant digits.

\n\n

Let $S_1(N) = \\sum \\limits_{p = 1}^{N} {E(p)}$.
\nLet $S_k(N) = \\sum \\limits_{p = 1}^{N} {S_{k-1}(p)}$ for $k \\gt 1$.

\n\n

Find $S_{20}(10^{14})$ and write the answer in scientific notation rounded to 10 significant digits. Use a lowercase e to separate mantissa and exponent. For example, the answer for $S_3(100)$ would be 5.983679014e5.

", "url": "https://projecteuler.net/problem=444", "answer": "1.200856722e263"} {"id": 445, "problem": "For every integer $n>1$, the family of functions $f_{n,a,b}$ is defined\nby\n\n$f_{n,a,b}(x)\\equiv a x + b \\mod n\\,\\,\\, $ for $a,b,x$ integer and $0< a \nFor every integer $n>1$, the family of functions $f_{n,a,b}$ is defined \nby
\n$f_{n,a,b}(x)\\equiv a x + b \\mod n\\,\\,\\, $ for $a,b,x$ integer and $0< a <n, 0 \\le b < n,0 \\le x < n$.

\n

\nWe will call $f_{n,a,b}$ a retraction if $\\,\\,\\, f_{n,a,b}(f_{n,a,b}(x)) \\equiv f_{n,a,b}(x) \\mod n \\,\\,\\,$ for every $0 \\le x < n$.
\nLet $R(n)$ be the number of retractions for $n$.\n

\n

\nYou are given that
\n$\\displaystyle \\sum_{k=1}^{99\\,999} R(\\binom {100\\,000} k) \\equiv 628701600 \\mod 1\\,000\\,000\\,007$.

\n

\nFind $\\displaystyle \\sum_{k=1}^{9\\,999\\,999} R(\\binom {10\\,000\\,000} k)$.
\nGive your answer modulo $1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=445", "answer": "659104042"} {"id": 446, "problem": "For every integer $n>1$, the family of functions $f_{n,a,b}$ is defined\nby\n\n$f_{n,a,b}(x)\\equiv a x + b \\mod n\\,\\,\\, $ for $a,b,x$ integer and $0< a \nFor every integer $n>1$, the family of functions $f_{n,a,b}$ is defined \nby
\n$f_{n,a,b}(x)\\equiv a x + b \\mod n\\,\\,\\, $ for $a,b,x$ integer and $0< a <n, 0 \\le b < n,0 \\le x < n$.

\n

\nWe will call $f_{n,a,b}$ a retraction if $\\,\\,\\, f_{n,a,b}(f_{n,a,b}(x)) \\equiv f_{n,a,b}(x) \\mod n \\,\\,\\,$ for every $0 \\le x < n$.
\nLet $R(n)$ be the number of retractions for $n$.\n

\n

\n$\\displaystyle F(N)=\\sum_{n=1}^NR(n^4+4)$.
\n$F(1024)=77532377300600$.

\n

\nFind $F(10^7)$.
\nGive your answer modulo $1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=446", "answer": "907803852"} {"id": 447, "problem": "For every integer $n>1$, the family of functions $f_{n,a,b}$ is defined\nby\n\n$f_{n,a,b}(x)\\equiv a x + b \\mod n\\,\\,\\, $ for $a,b,x$ integer and $0< a \nFor every integer $n>1$, the family of functions $f_{n,a,b}$ is defined \nby
\n$f_{n,a,b}(x)\\equiv a x + b \\mod n\\,\\,\\, $ for $a,b,x$ integer and $0< a <n, 0 \\le b < n,0 \\le x < n$.

\n

\nWe will call $f_{n,a,b}$ a retraction if $\\,\\,\\, f_{n,a,b}(f_{n,a,b}(x)) \\equiv f_{n,a,b}(x) \\mod n \\,\\,\\,$ for every $0 \\le x < n$.
\nLet $R(n)$ be the number of retractions for $n$.\n

\n

\n$\\displaystyle F(N)=\\sum_{n=2}^N R(n)$.
\n$F(10^7)\\equiv 638042271 \\mod 1\\,000\\,000\\,007$.

\n

\nFind $F(10^{14})$.
\nGive your answer modulo $1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=447", "answer": "530553372"} {"id": 448, "problem": "The function $\\operatorname{\\mathbf{lcm}}(a,b)$ denotes the least common multiple of $a$ and $b$.\n\nLet $A(n)$ be the average of the values of $\\operatorname{lcm}(n,i)$ for $1 \\le i \\le n$.\n\nE.g: $A(2)=(2+2)/2=2$ and $A(10)=(10+10+30+20+10+30+70+40+90+10)/10=32$.\n\nLet $S(n)=\\sum A(k)$ for $1 \\le k \\le n$.\n\n$S(100)=122726$.\n\nFind $S(99999999019) \\bmod 999999017$.", "raw_html": "

\nThe function $\\operatorname{\\mathbf{lcm}}(a,b)$ denotes the least common multiple of $a$ and $b$.
\nLet $A(n)$ be the average of the values of $\\operatorname{lcm}(n,i)$ for $1 \\le i \\le n$.
\nE.g: $A(2)=(2+2)/2=2$ and $A(10)=(10+10+30+20+10+30+70+40+90+10)/10=32$. \n

\nLet $S(n)=\\sum A(k)$ for $1 \\le k \\le n$.
\n$S(100)=122726$.\n\n

\nFind $S(99999999019) \\bmod 999999017$.\n

", "url": "https://projecteuler.net/problem=448", "answer": "106467648"} {"id": 449, "problem": "Phil the confectioner is making a new batch of chocolate covered candy. Each candy centre is shaped like an ellipsoid of revolution defined by the equation:\n$b^2 x^2 + b^2 y^2 + a^2 z^2 = a^2 b^2$.\n\nPhil wants to know how much chocolate is needed to cover one candy centre with a uniform coat of chocolate one millimeter thick.\n\nIf $a = 1$ mm and $b = 1$ mm, the amount of chocolate required is $\\dfrac{28}{3} \\pi$ mm3\n\nIf $a = 2$ mm and $b = 1$ mm, the amount of chocolate required is approximately 60.35475635 mm3.\n\nFind the amount of chocolate in mm3 required if $a = 3$ mm and $b =1$ mm. Give your answer as the number rounded to 8 decimal places behind the decimal point.", "raw_html": "

Phil the confectioner is making a new batch of chocolate covered candy. Each candy centre is shaped like an ellipsoid of revolution defined by the equation:\n$b^2 x^2 + b^2 y^2 + a^2 z^2 = a^2 b^2$.

\n\n

Phil wants to know how much chocolate is needed to cover one candy centre with a uniform coat of chocolate one millimeter thick.\n

\n\n

If $a = 1$ mm and $b = 1$ mm, the amount of chocolate required is $\\dfrac{28}{3} \\pi$ mm3

\n\n

If $a = 2$ mm and $b = 1$ mm, the amount of chocolate required is approximately 60.35475635 mm3.

\n\n

Find the amount of chocolate in mm3 required if $a = 3$ mm and $b =1$ mm. Give your answer as the number rounded to 8 decimal places behind the decimal point.

", "url": "https://projecteuler.net/problem=449", "answer": "103.37870096"} {"id": 450, "problem": "A hypocycloid is the curve drawn by a point on a small circle rolling inside a larger circle. The parametric equations of a hypocycloid centered at the origin, and starting at the right most point is given by:\n\n$$x(t) = (R - r) \\cos(t) + r \\cos(\\frac {R - r} r t)$$\n$$y(t) = (R - r) \\sin(t) - r \\sin(\\frac {R - r} r t)$$\n\nWhere $R$ is the radius of the large circle and $r$ the radius of the small circle.\n\nLet $C(R, r)$ be the set of distinct points with integer coordinates on the hypocycloid with radius R and r and for which there is a corresponding value of t such that $\\sin(t)$ and $\\cos(t)$ are rational numbers.\n\nLet $S(R, r) = \\sum_{(x,y) \\in C(R, r)} |x| + |y|$ be the sum of the absolute values of the $x$ and $y$ coordinates of the points in $C(R, r)$.\n\nLet $T(N) = \\sum_{R = 3}^N \\sum_{r=1}^{\\lfloor \\frac {R - 1} 2 \\rfloor} S(R, r)$ be the sum of $S(R, r)$ for R and r positive integers, $R\\leq N$ and $2r < R$.\n\nYou are given:\n\n| $C(3, 1)$ | = | $\\{(3, 0), (-1, 2), (-1,0), (-1,-2)\\}$ |\n| $C(2500, 1000)$ | = | $\\{(2500, 0), (772, 2376), (772, -2376), (516, 1792), (516, -1792), (500, 0), (68, 504), (68, -504),$ |\n| | $(-1356, 1088), (-1356, -1088), (-1500, 1000), (-1500, -1000)\\}$ |\n\nNote: $(-625, 0)$ is not an element of $C(2500, 1000)$ because $\\sin(t)$ is not a rational number for the corresponding values of $t$.\n\n$S(3, 1) = (|3| + |0|) + (|-1| + |2|) + (|-1| + |0|) + (|-1| + |-2|) = 10$\n\n$T(3) = 10; T(10) = 524; T(100) = 580442; T(10^3) = 583108600$.\n\nFind $T(10^6)$.", "raw_html": "

A hypocycloid is the curve drawn by a point on a small circle rolling inside a larger circle. The parametric equations of a hypocycloid centered at the origin, and starting at the right most point is given by:

\n\n

$$x(t) = (R - r) \\cos(t) + r \\cos(\\frac {R - r} r t)$$\n$$y(t) = (R - r) \\sin(t) - r \\sin(\\frac {R - r} r t)$$

\n\n

Where $R$ is the radius of the large circle and $r$ the radius of the small circle.

\n\n

Let $C(R, r)$ be the set of distinct points with integer coordinates on the hypocycloid with radius R and r and for which there is a corresponding value of t such that $\\sin(t)$ and $\\cos(t)$ are rational numbers.

\n

\nLet $S(R, r) = \\sum_{(x,y) \\in C(R, r)} |x| + |y|$ be the sum of the absolute values of the $x$ and $y$ coordinates of the points in $C(R, r)$.

\n\n

Let $T(N) = \\sum_{R = 3}^N \\sum_{r=1}^{\\lfloor \\frac {R - 1} 2 \\rfloor} S(R, r)$ be the sum of $S(R, r)$ for R and r positive integers, $R\\leq N$ and $2r < R$.

\n\n

You are given:

\n\n\n\n\n\n\n\n\n\n\n
$C(3, 1)$=$\\{(3, 0), (-1, 2), (-1,0), (-1,-2)\\}$
$C(2500, 1000)$=$\\{(2500, 0), (772, 2376), (772, -2376), (516, 1792), (516, -1792), (500, 0), (68, 504), (68, -504),$
 $(-1356, 1088), (-1356, -1088), (-1500, 1000), (-1500, -1000)\\}$
\n\n

Note: $(-625, 0)$ is not an element of $C(2500, 1000)$ because $\\sin(t)$ is not a rational number for the corresponding values of $t$.

\n\n

$S(3, 1) = (|3| + |0|) + (|-1| + |2|) + (|-1| + |0|) + (|-1| + |-2|) = 10$

\n\n

$T(3) = 10; T(10) = 524; T(100) = 580442; T(10^3) = 583108600$.

\n\n

Find $T(10^6)$.

", "url": "https://projecteuler.net/problem=450", "answer": "583333163984220940"} {"id": 451, "problem": "Consider the number $15$.\n\nThere are eight positive numbers less than $15$ which are coprime to $15$: $1, 2, 4, 7, 8, 11, 13, 14$.\n\nThe modular inverses of these numbers modulo $15$ are: $1, 8, 4, 13, 2, 11, 7, 14$\n\nbecause\n\n$1 \\cdot 1 \\bmod 15=1$\n\n$2 \\cdot 8=16 \\bmod 15=1$\n\n$4 \\cdot 4=16 \\bmod 15=1$\n\n$7 \\cdot 13=91 \\bmod 15=1$\n\n$11 \\cdot 11=121 \\bmod 15=1$\n\n$14 \\cdot 14=196 \\bmod 15=1\n$\n\nLet $I(n)$ be the largest positive number $m$ smaller than $n-1$ such that the modular inverse of $m$ modulo $n$ equals $m$ itself.\n\nSo $I(15)=11$.\n\nAlso $I(100)=51$ and $I(7)=1$.\n\nFind $\\sum I(n)$ for $3 \\le n \\le 2 \\times 10^7$.", "raw_html": "

\nConsider the number $15$.
\nThere are eight positive numbers less than $15$ which are coprime to $15$: $1, 2, 4, 7, 8, 11, 13, 14$.
\nThe modular inverses of these numbers modulo $15$ are: $1, 8, 4, 13, 2, 11, 7, 14$
\nbecause
\n$1 \\cdot 1 \\bmod 15=1$
\n$2 \\cdot 8=16 \\bmod 15=1$
\n$4 \\cdot 4=16 \\bmod 15=1$
\n$7 \\cdot 13=91 \\bmod 15=1$
\n$11 \\cdot 11=121 \\bmod 15=1$
\n$14 \\cdot 14=196 \\bmod 15=1
$

\n

\nLet $I(n)$ be the largest positive number $m$ smaller than $n-1$ such that the modular inverse of $m$ modulo $n$ equals $m$ itself.
\nSo $I(15)=11$.
\nAlso $I(100)=51$ and $I(7)=1$.

\n

\nFind $\\sum I(n)$ for $3 \\le n \\le 2 \\times 10^7$.

", "url": "https://projecteuler.net/problem=451", "answer": "153651073760956"} {"id": 452, "problem": "Define $F(m,n)$ as the number of $n$-tuples of positive integers for which the product of the elements doesn't exceed $m$.\n\n$F(10, 10) = 571$.\n\n$F(10^6, 10^6) \\bmod 1\\,234\\,567\\,891 = 252903833$.\n\nFind $F(10^9, 10^9) \\bmod 1\\,234\\,567\\,891$.", "raw_html": "

Define $F(m,n)$ as the number of $n$-tuples of positive integers for which the product of the elements doesn't exceed $m$.

\n

$F(10, 10) = 571$.

\n

$F(10^6, 10^6) \\bmod 1\\,234\\,567\\,891 = 252903833$.

\n

Find $F(10^9, 10^9) \\bmod 1\\,234\\,567\\,891$.

", "url": "https://projecteuler.net/problem=452", "answer": "345558983"} {"id": 453, "problem": "A simple quadrilateral is a polygon that has four distinct vertices, has no straight angles and does not self-intersect.\n\nLet $Q(m, n)$ be the number of simple quadrilaterals whose vertices are lattice points with coordinates $(x,y)$ satisfying $0 \\le x \\le m$ and $0 \\le y \\le n$.\n\nFor example, $Q(2, 2) = 94$ as can be seen below:\n\nIt can also be verified that $Q(3, 7) = 39590$, $Q(12, 3) = 309000$ and $Q(123, 45) = 70542215894646$.\n\nFind $Q(12345, 6789) \\bmod 135707531$.", "raw_html": "

A simple quadrilateral is a polygon that has four distinct vertices, has no straight angles and does not self-intersect.

\n\n

Let $Q(m, n)$ be the number of simple quadrilaterals whose vertices are lattice points with coordinates $(x,y)$ satisfying $0 \\le x \\le m$ and $0 \\le y \\le n$.

\n\n

For example, $Q(2, 2) = 94$ as can be seen below:

\n

\"0453_quad.png\"

\n

It can also be verified that $Q(3, 7) = 39590$, $Q(12, 3) = 309000$ and $Q(123, 45) = 70542215894646$.

\n\n

Find $Q(12345, 6789) \\bmod 135707531$.

", "url": "https://projecteuler.net/problem=453", "answer": "104354107"} {"id": 454, "problem": "In the following equation $x$, $y$, and $n$ are positive integers.\n\n$$\\dfrac{1}{x} + \\dfrac{1}{y} = \\dfrac{1}{n}$$\nFor a limit $L$ we define $F(L)$ as the number of solutions which satisfy $x \\lt y \\le L$.\n\nWe can verify that $F(15) = 4$ and $F(1000) = 1069$.\n\nFind $F(10^{12})$.", "raw_html": "

In the following equation $x$, $y$, and $n$ are positive integers.

\n$$\\dfrac{1}{x} + \\dfrac{1}{y} = \\dfrac{1}{n}$$\n

For a limit $L$ we define $F(L)$ as the number of solutions which satisfy $x \\lt y \\le L$.

\n\n

We can verify that $F(15) = 4$ and $F(1000) = 1069$.
\nFind $F(10^{12})$.

", "url": "https://projecteuler.net/problem=454", "answer": "5435004633092"} {"id": 455, "problem": "Let $f(n)$ be the largest positive integer $x$ less than $10^9$ such that the last $9$ digits of $n^x$ form the number $x$ (including leading zeros), or zero if no such integer exists.\n\nFor example:\n\n- $f(4) = 411728896$ ($4^{411728896} = \\cdots 490\\underline{411728896}$)\n\n- $f(10) = 0$\n\n- $f(157) = 743757$ ($157^{743757} = \\cdots 567\\underline{000743757}$)\n\n- $\\sum_{2 \\le n \\le 10^3} f(n) = 442530011399$\n\nFind $\\sum_{2 \\le n \\le 10^6}f(n)$.", "raw_html": "

Let $f(n)$ be the largest positive integer $x$ less than $10^9$ such that the last $9$ digits of $n^x$ form the number $x$ (including leading zeros), or zero if no such integer exists.

\n\n

For example:

\n\n
  • $f(4) = 411728896$ ($4^{411728896} = \\cdots 490\\underline{411728896}$)
  • \n
  • $f(10) = 0$
  • \n
  • $f(157) = 743757$ ($157^{743757} = \\cdots 567\\underline{000743757}$)
  • \n
  • $\\sum_{2 \\le n \\le 10^3} f(n) = 442530011399$
  • \n

Find $\\sum_{2 \\le n \\le 10^6}f(n)$.

", "url": "https://projecteuler.net/problem=455", "answer": "450186511399999"} {"id": 456, "problem": "Define:\n$x_n = (1248^n \\bmod 32323) - 16161$\n$y_n = (8421^n \\bmod 30103) - 15051$\n\n$P_n = \\{(x_1, y_1), (x_2, y_2), \\dots, (x_n, y_n)\\}$\n\nFor example, $P_8 = \\{(-14913, -6630),$$(-10161, 5625),$$(5226, 11896),$$(8340, -10778),$$(15852, -5203),$$(-15165, 11295),$$(-1427, -14495),$$(12407, 1060)\\}$.\n\nLet $C(n)$ be the number of triangles whose vertices are in $P_n$ which contain the origin in the interior.\n\nExamples:\n\n$C(8) = 20$\n\n$C(600) = 8950634$\n\n$C(40\\,000) = 2666610948988$\n\nFind $C(2\\,000\\,000)$.", "raw_html": "

Define:
$x_n = (1248^n \\bmod 32323) - 16161$
$y_n = (8421^n \\bmod 30103) - 15051$
\n$P_n = \\{(x_1, y_1), (x_2, y_2), \\dots, (x_n, y_n)\\}$\n

\n\n

For example, $P_8 = \\{(-14913, -6630),$$(-10161, 5625),$$(5226, 11896),$$(8340, -10778),$$(15852, -5203),$$(-15165, 11295),$$(-1427, -14495),$$(12407, 1060)\\}$.

\n\n

Let $C(n)$ be the number of triangles whose vertices are in $P_n$ which contain the origin in the interior.

\n\n

\nExamples:
\n$C(8) = 20$
\n$C(600) = 8950634$
\n$C(40\\,000) = 2666610948988$\n

\n\n

Find $C(2\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=456", "answer": "333333208685971546"} {"id": 457, "problem": "Let $f(n) = n^2 - 3n - 1$.\n\nLet $p$ be a prime.\n\nLet $R(p)$ be the smallest positive integer $n$ such that $f(n) \\bmod p^2 = 0$ if such an integer $n$ exists, otherwise $R(p) = 0$.\n\nLet $SR(L)$ be $\\sum R(p)$ for all primes not exceeding $L$.\n\nFind $SR(10^7)$.", "raw_html": "

\nLet $f(n) = n^2 - 3n - 1$.
\nLet $p$ be a prime.
\nLet $R(p)$ be the smallest positive integer $n$ such that $f(n) \\bmod p^2 = 0$ if such an integer $n$ exists, otherwise $R(p) = 0$.\n

\n

\nLet $SR(L)$ be $\\sum R(p)$ for all primes not exceeding $L$.\n

\n

\nFind $SR(10^7)$.\n

", "url": "https://projecteuler.net/problem=457", "answer": "2647787126797397063"} {"id": 458, "problem": "Consider the alphabet $A$ made out of the letters of the word \"$\\text{project}$\": $A=\\{\\text c,\\text e,\\text j,\\text o,\\text p,\\text r,\\text t\\}$.\n\nLet $T(n)$ be the number of strings of length $n$ consisting of letters from $A$ that do not have a substring that is one of the $5040$ permutations of \"$\\text{project}$\".\n\n$T(7)=7^7-7!=818503$.\n\nFind $T(10^{12})$. Give the last $9$ digits of your answer.", "raw_html": "

\nConsider the alphabet $A$ made out of the letters of the word \"$\\text{project}$\": $A=\\{\\text c,\\text e,\\text j,\\text o,\\text p,\\text r,\\text t\\}$.
\nLet $T(n)$ be the number of strings of length $n$ consisting of letters from $A$ that do not have a substring that is one of the $5040$ permutations of \"$\\text{project}$\".\n

\n$T(7)=7^7-7!=818503$.\n\n

\nFind $T(10^{12})$. Give the last $9$ digits of your answer.\n

", "url": "https://projecteuler.net/problem=458", "answer": "423341841"} {"id": 459, "problem": "The flipping game is a two player game played on an $N$ by $N$ square board.\n\nEach square contains a disk with one side white and one side black.\n\nThe game starts with all disks showing their white side.\n\nA turn consists of flipping all disks in a rectangle with the following properties:\n\n- the upper right corner of the rectangle contains a white disk\n\n- the rectangle width is a perfect square ($1$, $4$, $9$, $16$, ...)\n\n- the rectangle height is a triangular numberThe triangular numbers are defined as $\\frac 1 2 n(n + 1)$ for positive integer $n$. ($1$, $3$, $6$, $10$, ...)\n\nPlayers alternate turns. A player wins by turning the grid all black.\n\nLet $W(N)$ be the number of winning movesThe first move of a strategy that ensures a win no matter what the opponent plays. for the first player on an $N$ by $N$ board with all disks white, assuming perfect play.\n\n$W(1) = 1$, $W(2) = 0$, $W(5) = 8$ and $W(10^2) = 31395$.\n\nFor $N=5$, the first player's eight winning first moves are:\n\nFind $W(10^6)$.", "raw_html": "

The flipping game is a two player game played on an $N$ by $N$ square board.
\nEach square contains a disk with one side white and one side black.
\nThe game starts with all disks showing their white side.

\n\n

A turn consists of flipping all disks in a rectangle with the following properties:\n

  • the upper right corner of the rectangle contains a white disk
  • \n
  • the rectangle width is a perfect square ($1$, $4$, $9$, $16$, ...)
  • \n
  • the rectangle height is a triangular numberThe triangular numbers are defined as $\\frac 1 2 n(n + 1)$ for positive integer $n$. ($1$, $3$, $6$, $10$, ...)
  • \n
\n

\"0459-flipping-game-0.png\"

\n\n

Players alternate turns. A player wins by turning the grid all black.

\n\n

Let $W(N)$ be the number of winning movesThe first move of a strategy that ensures a win no matter what the opponent plays. for the first player on an $N$ by $N$ board with all disks white, assuming perfect play.
\n$W(1) = 1$, $W(2) = 0$, $W(5) = 8$ and $W(10^2) = 31395$.

\n\n

For $N=5$, the first player's eight winning first moves are:

\n\n

\"0459-flipping-game-1.png\"

\n\n

Find $W(10^6)$.

", "url": "https://projecteuler.net/problem=459", "answer": "3996390106631"} {"id": 460, "problem": "On the Euclidean plane, an ant travels from point $A(0, 1)$ to point $B(d, 1)$ for an integer $d$.\n\nIn each step, the ant at point $(x_0, y_0)$ chooses one of the lattice points $(x_1, y_1)$ which satisfy $x_1 \\ge 0$ and $y_1 \\ge 1$ and goes straight to $(x_1, y_1)$ at a constant velocity $v$. The value of $v$ depends on $y_0$ and $y_1$ as follows:\n\n- If $y_0 = y_1$, the value of $v$ equals $y_0$.\n\n- If $y_0 \\ne y_1$, the value of $v$ equals $(y_1 - y_0) / (\\ln(y_1) - \\ln(y_0))$.\n\nThe left image is one of the possible paths for $d = 4$. First the ant goes from $A(0, 1)$ to $P_1(1, 3)$ at velocity $(3 - 1) / (\\ln(3) - \\ln(1)) \\approx 1.8205$. Then the required time is $\\sqrt 5 / 1.8205 \\approx 1.2283$.\n\nFrom $P_1(1, 3)$ to $P_2(3, 3)$ the ant travels at velocity $3$ so the required time is $2 / 3 \\approx 0.6667$. From $P_2(3, 3)$ to $B(4, 1)$ the ant travels at velocity $(1 - 3) / (\\ln(1) - \\ln(3)) \\approx 1.8205$ so the required time is $\\sqrt 5 / 1.8205 \\approx 1.2283$.\n\nThus the total required time is $1.2283 + 0.6667 + 1.2283 = 3.1233$.\n\nThe right image is another path. The total required time is calculated as $0.98026 + 1 + 0.98026 = 2.96052$. It can be shown that this is the quickest path for $d = 4$.\n\nLet $F(d)$ be the total required time if the ant chooses the quickest path. For example, $F(4) \\approx 2.960516287$.\n\nWe can verify that $F(10) \\approx 4.668187834$ and $F(100) \\approx 9.217221972$.\n\nFind $F(10000)$. Give your answer rounded to nine decimal places.", "raw_html": "

\nOn the Euclidean plane, an ant travels from point $A(0, 1)$ to point $B(d, 1)$ for an integer $d$.\n

\n

\nIn each step, the ant at point $(x_0, y_0)$ chooses one of the lattice points $(x_1, y_1)$ which satisfy $x_1 \\ge 0$ and $y_1 \\ge 1$ and goes straight to $(x_1, y_1)$ at a constant velocity $v$. The value of $v$ depends on $y_0$ and $y_1$ as follows:\n

  • If $y_0 = y_1$, the value of $v$ equals $y_0$.
  • \n
  • If $y_0 \\ne y_1$, the value of $v$ equals $(y_1 - y_0) / (\\ln(y_1) - \\ln(y_0))$.
  • \n

\nThe left image is one of the possible paths for $d = 4$. First the ant goes from $A(0, 1)$ to $P_1(1, 3)$ at velocity $(3 - 1) / (\\ln(3) - \\ln(1)) \\approx 1.8205$. Then the required time is $\\sqrt 5 / 1.8205 \\approx 1.2283$.
\nFrom $P_1(1, 3)$ to $P_2(3, 3)$ the ant travels at velocity $3$ so the required time is $2 / 3 \\approx 0.6667$. From $P_2(3, 3)$ to $B(4, 1)$ the ant travels at velocity $(1 - 3) / (\\ln(1) - \\ln(3)) \\approx 1.8205$ so the required time is $\\sqrt 5 / 1.8205 \\approx 1.2283$.
\nThus the total required time is $1.2283 + 0.6667 + 1.2283 = 3.1233$.\n

\n

\nThe right image is another path. The total required time is calculated as $0.98026 + 1 + 0.98026 = 2.96052$. It can be shown that this is the quickest path for $d = 4$.\n

\n

\"0460_ant.jpg\"

\n

\nLet $F(d)$ be the total required time if the ant chooses the quickest path. For example, $F(4) \\approx 2.960516287$.
\nWe can verify that $F(10) \\approx 4.668187834$ and $F(100) \\approx 9.217221972$.\n

\n

\nFind $F(10000)$. Give your answer rounded to nine decimal places.\n

", "url": "https://projecteuler.net/problem=460", "answer": "18.420738199"} {"id": 461, "problem": "Let $f_n(k) = e^{k/n} - 1$, for all non-negative integers $k$.\n\nRemarkably, $f_{200}(6)+f_{200}(75)+f_{200}(89)+f_{200}(226)=\\underline{3.1415926}44529\\cdots\\approx\\pi$.\n\nIn fact, it is the best approximation of $\\pi$ of the form $f_n(a) + f_n(b) + f_n(c) + f_n(d)$ for $n=200$.\n\nLet $g(n)=a^2 + b^2 + c^2 + d^2$ for $a, b, c, d$ that minimize the error: $|f_n(a) + f_n(b) + f_n(c) + f_n(d) - \\pi|$\n\n(where $|x|$ denotes the absolute value of $x$).\n\nYou are given $g(200)=6^2+75^2+89^2+226^2=64658$.\n\nFind $g(10000)$.", "raw_html": "

Let $f_n(k) = e^{k/n} - 1$, for all non-negative integers $k$.

\n

Remarkably, $f_{200}(6)+f_{200}(75)+f_{200}(89)+f_{200}(226)=\\underline{3.1415926}44529\\cdots\\approx\\pi$.

\n

In fact, it is the best approximation of $\\pi$ of the form $f_n(a) + f_n(b) + f_n(c) + f_n(d)$ for $n=200$.

\n

Let $g(n)=a^2 + b^2 + c^2 + d^2$ for $a, b, c, d$ that minimize the error: $|f_n(a) + f_n(b) + f_n(c) + f_n(d) - \\pi|$
\n(where $|x|$ denotes the absolute value of $x$).

\n

You are given $g(200)=6^2+75^2+89^2+226^2=64658$.

\n

Find $g(10000)$.

", "url": "https://projecteuler.net/problem=461", "answer": "159820276"} {"id": 462, "problem": "A $3$-smooth number is an integer which has no prime factor larger than $3$. For an integer $N$, we define $S(N)$ as the set of $3$-smooth numbers less than or equal to $N$. For example, $S(20) = \\{ 1, 2, 3, 4, 6, 8, 9, 12, 16, 18 \\}$.\n\nWe define $F(N)$ as the number of permutations of $S(N)$ in which each element comes after all of its proper divisors.\n\nThis is one of the possible permutations for $N = 20$.\n\n- $1, 2, 4, 3, 9, 8, 16, 6, 18, 12.$\n\nThis is not a valid permutation because $12$ comes before its divisor $6$.\n\n- $1, 2, 4, 3, 9, 8, \\boldsymbol{12}, 16, \\boldsymbol 6, 18$.\n\nWe can verify that $F(6) = 5$, $F(8) = 9$, $F(20) = 450$ and $F(1000) \\approx 8.8521816557\\mathrm e21$.\n\nFind $F(10^{18})$. Give as your answer its scientific notation rounded to ten digits after the decimal point.\n\nWhen giving your answer, use a lowercase e to separate mantissa and exponent. E.g. if the answer is $112\\,233\\,445\\,566\\,778\\,899$ then the answer format would be 1.1223344557e17.", "raw_html": "

\nA $3$-smooth number is an integer which has no prime factor larger than $3$. For an integer $N$, we define $S(N)$ as the set of $3$-smooth numbers less than or equal to $N$. For example, $S(20) = \\{ 1, 2, 3, 4, 6, 8, 9, 12, 16, 18 \\}$.\n

\n

\nWe define $F(N)$ as the number of permutations of $S(N)$ in which each element comes after all of its proper divisors.\n

\n

\nThis is one of the possible permutations for $N = 20$.
\n- $1, 2, 4, 3, 9, 8, 16, 6, 18, 12.$
\nThis is not a valid permutation because $12$ comes before its divisor $6$.
\n- $1, 2, 4, 3, 9, 8, \\boldsymbol{12}, 16, \\boldsymbol 6, 18$.\n

\n

\nWe can verify that $F(6) = 5$, $F(8) = 9$, $F(20) = 450$ and $F(1000) \\approx 8.8521816557\\mathrm e21$.
\nFind $F(10^{18})$. Give as your answer its scientific notation rounded to ten digits after the decimal point.
\nWhen giving your answer, use a lowercase e to separate mantissa and exponent. E.g. if the answer is $112\\,233\\,445\\,566\\,778\\,899$ then the answer format would be 1.1223344557e17.\n

", "url": "https://projecteuler.net/problem=462", "answer": "5.5350769703e1512"} {"id": 463, "problem": "The function $f$ is defined for all positive integers as follows:\n\n- $f(1)=1$\n\n- $f(3)=3$\n\n- $f(2n)=f(n)$\n\n- $f(4n + 1)=2f(2n + 1) - f(n)$\n\n- $f(4n + 3)=3f(2n + 1) - 2f(n)$\n\nThe function $S(n)$ is defined as $\\sum_{i=1}^{n}f(i)$.\n\n$S(8)=22$ and $S(100)=3604$.\n\nFind $S(3^{37})$. Give the last $9$ digits of your answer.", "raw_html": "

\nThe function $f$ is defined for all positive integers as follows:\n

  • $f(1)=1$\n
  • $f(3)=3$\n
  • $f(2n)=f(n)$\n
  • $f(4n + 1)=2f(2n + 1) - f(n)$\n
  • $f(4n + 3)=3f(2n + 1) - 2f(n)$\n
  • \n

The function $S(n)$ is defined as $\\sum_{i=1}^{n}f(i)$.

\n

$S(8)=22$ and $S(100)=3604$.

\n

Find $S(3^{37})$. Give the last $9$ digits of your answer.

", "url": "https://projecteuler.net/problem=463", "answer": "808981553"} {"id": 464, "problem": "The Möbius function, denoted $\\mu(n)$, is defined as:\n\n- $\\mu(n) = (-1)^{\\omega(n)}$ if $n$ is squarefree (where $\\omega(n)$ is the number of distinct prime factors of $n$)\n\n- $\\mu(n) = 0$ if $n$ is not squarefree.\n\nLet $P(a, b)$ be the number of integers $n$ in the interval $[a, b]$ such that $\\mu(n) = 1$.\n\nLet $N(a, b)$ be the number of integers $n$ in the interval $[a, b]$ such that $\\mu(n) = -1$.\n\nFor example, $P(2,10) = 2$ and $N(2,10) = 4$.\n\nLet $C(n)$ be the number of integer pairs $(a, b)$ such that:\n\n- $1\\le a \\le b \\le n$,\n\n- $99 \\cdot N(a, b) \\le 100 \\cdot P(a, b)$, and\n\n- $99 \\cdot P(a, b) \\le 100 \\cdot N(a, b)$.\n\nFor example, $C(10) = 13$, $C(500) = 16676$ and $C(10\\,000) = 20155319$.\n\nFind $C(20\\,000\\,000)$.", "raw_html": "

\nThe Möbius function, denoted $\\mu(n)$, is defined as:\n

  • $\\mu(n) = (-1)^{\\omega(n)}$ if $n$ is squarefree (where $\\omega(n)$ is the number of distinct prime factors of $n$)
  • \n
  • $\\mu(n) = 0$ if $n$ is not squarefree.
  • \n

\nLet $P(a, b)$ be the number of integers $n$ in the interval $[a, b]$ such that $\\mu(n) = 1$.
\nLet $N(a, b)$ be the number of integers $n$ in the interval $[a, b]$ such that $\\mu(n) = -1$.
\nFor example, $P(2,10) = 2$ and $N(2,10) = 4$.\n

\n\n

\nLet $C(n)$ be the number of integer pairs $(a, b)$ such that:\n

  • $1\\le a \\le b \\le n$,
  • \n
  • $99 \\cdot N(a, b) \\le 100 \\cdot P(a, b)$, and
  • \n
  • $99 \\cdot P(a, b) \\le 100 \\cdot N(a, b)$.
  • \n

\nFor example, $C(10) = 13$, $C(500) = 16676$ and $C(10\\,000) = 20155319$.\n

\n\n

\nFind $C(20\\,000\\,000)$.\n

", "url": "https://projecteuler.net/problem=464", "answer": "198775297232878"} {"id": 465, "problem": "The kernel of a polygon is defined by the set of points from which the entire polygon's boundary is visible. We define a polar polygon as a polygon for which the origin is strictly contained inside its kernel.\n\nFor this problem, a polygon can have collinear consecutive vertices. However, a polygon still cannot have self-intersection and cannot have zero area.\n\nFor example, only the first of the following is a polar polygon (the kernels of the second, third, and fourth do not strictly contain the origin, and the fifth does not have a kernel at all):\n\nNotice that the first polygon has three consecutive collinear vertices.\n\nLet $P(n)$ be the number of polar polygons such that the vertices $(x, y)$ have integer coordinates whose absolute values are not greater than $n$.\n\nNote that polygons should be counted as different if they have different set of edges, even if they enclose the same area. For example, the polygon with vertices $[(0,0),(0,3),(1,1),(3,0)]$ is distinct from the polygon with vertices $[(0,0),(0,3),(1,1),(3,0),(1,0)]$.\n\nFor example, $P(1) = 131$, $P(2) = 1648531$, $P(3) = 1099461296175$ and $P(343) \\bmod 1\\,000\\,000\\,007 = 937293740$.\n\nFind $P(7^{13}) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

The kernel of a polygon is defined by the set of points from which the entire polygon's boundary is visible. We define a polar polygon as a polygon for which the origin is strictly contained inside its kernel.

\n\n

For this problem, a polygon can have collinear consecutive vertices. However, a polygon still cannot have self-intersection and cannot have zero area.

\n\n

For example, only the first of the following is a polar polygon (the kernels of the second, third, and fourth do not strictly contain the origin, and the fifth does not have a kernel at all):\n

\"0465_polygons.png\"

\n\n\n

Notice that the first polygon has three consecutive collinear vertices.

\n\n

Let $P(n)$ be the number of polar polygons such that the vertices $(x, y)$ have integer coordinates whose absolute values are not greater than $n$.

\n\n

Note that polygons should be counted as different if they have different set of edges, even if they enclose the same area. For example, the polygon with vertices $[(0,0),(0,3),(1,1),(3,0)]$ is distinct from the polygon with vertices $[(0,0),(0,3),(1,1),(3,0),(1,0)]$.

\n\n

For example, $P(1) = 131$, $P(2) = 1648531$, $P(3) = 1099461296175$ and $P(343) \\bmod 1\\,000\\,000\\,007 = 937293740$.

\n\n

Find $P(7^{13}) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=465", "answer": "585965659"} {"id": 466, "problem": "Let $P(m,n)$ be the number of distinct terms in an $m\\times n$ multiplication table.\n\nFor example, a $3\\times 4$ multiplication table looks like this:\n\n| $\\times$ | 1 | 2 | 3 | 4 |\n| --- | --- | --- | --- | --- |\n| 1 | 1 | 2 | 3 | 4 |\n| 2 | 2 | 4 | 6 | 8 |\n| 3 | 3 | 6 | 9 | 12 |\n\nThere are $8$ distinct terms $\\{1,2,3,4,6,8,9,12\\}$, therefore $P(3,4) = 8$.\n\nYou are given that:\n\n$P(64,64) = 1263$,\n\n$P(12,345) = 1998$, and\n\n$P(32,10^{15}) = 13826382602124302$.\n\nFind $P(64,10^{16})$.", "raw_html": "

Let $P(m,n)$ be the number of distinct terms in an $m\\times n$ multiplication table.

\n\n

For example, a $3\\times 4$ multiplication table looks like this:

\n\n

$\\times$ 1234
1 1234
2 2468
3 36912
\n\n\n\n

There are $8$ distinct terms $\\{1,2,3,4,6,8,9,12\\}$, therefore $P(3,4) = 8$.

\n\n

You are given that:
\n$P(64,64) = 1263$,
\n$P(12,345) = 1998$, and
\n$P(32,10^{15}) = 13826382602124302$.

\n\n

Find $P(64,10^{16})$.

", "url": "https://projecteuler.net/problem=466", "answer": "258381958195474745"} {"id": 467, "problem": "An integer $s$ is called a superinteger of another integer $n$ if the digits of $n$ form a subsequenceA subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. of the digits of $s$.\n\nFor example, $2718281828$ is a superinteger of $18828$, while $314159$ is not a superinteger of $151$.\n\nLet $p(n)$ be the $n$th prime number, and let $c(n)$ be the $n$th composite number. For example, $p(1) = 2$, $p(10) = 29$, $c(1)$ = 4 and $c(10) = 18$.\n\n$\\{p(i) : i \\ge 1\\} = \\{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, \\dots\\}$\n\n$\\{c(i) : i \\ge 1\\} = \\{4, 6, 8, 9, 10, 12, 14, 15, 16, 18, \\dots\\}$\n\nLet $P^D$ be the sequence of the digital roots of $\\{p(i)\\}$ ($C^D$ is defined similarly for $\\{c(i)\\}$):\n\n$P^D = \\{2, 3, 5, 7, 2, 4, 8, 1, 5, 2, \\dots\\}$\n\n$C^D = \\{4, 6, 8, 9, 1, 3, 5, 6, 7, 9, \\dots\\}$\n\nLet $P_n$ be the integer formed by concatenating the first $n$ elements of $P^D$ ($C_n$ is defined similarly for $C^D$).\n\n$P_{10} = 2357248152$\n\n$C_{10} = 4689135679$\n\nLet $f(n)$ be the smallest positive integer that is a common superinteger of $P_n$ and $C_n$.\nFor example, $f(10) = 2357246891352679$, and $f(100) \\bmod 1\\,000\\,000\\,007 = 771661825$.\n\nFind $f(10\\,000) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

An integer $s$ is called a superinteger of another integer $n$ if the digits of $n$ form a subsequenceA subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. of the digits of $s$.
\nFor example, $2718281828$ is a superinteger of $18828$, while $314159$ is not a superinteger of $151$.\n

\n\n

Let $p(n)$ be the $n$th prime number, and let $c(n)$ be the $n$th composite number. For example, $p(1) = 2$, $p(10) = 29$, $c(1)$ = 4 and $c(10) = 18$.
\n$\\{p(i) : i \\ge 1\\} = \\{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, \\dots\\}$
\n$\\{c(i) : i \\ge 1\\} = \\{4, 6, 8, 9, 10, 12, 14, 15, 16, 18, \\dots\\}$

\n\n

Let $P^D$ be the sequence of the digital roots of $\\{p(i)\\}$ ($C^D$ is defined similarly for $\\{c(i)\\}$):
\n$P^D = \\{2, 3, 5, 7, 2, 4, 8, 1, 5, 2, \\dots\\}$
\n$C^D = \\{4, 6, 8, 9, 1, 3, 5, 6, 7, 9, \\dots\\}$

\n\n

Let $P_n$ be the integer formed by concatenating the first $n$ elements of $P^D$ ($C_n$ is defined similarly for $C^D$).
\n$P_{10} = 2357248152$
\n$C_{10} = 4689135679$

\n\n

Let $f(n)$ be the smallest positive integer that is a common superinteger of $P_n$ and $C_n$.
For example, $f(10) = 2357246891352679$, and $f(100) \\bmod 1\\,000\\,000\\,007 = 771661825$.

\n\n

Find $f(10\\,000) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=467", "answer": "775181359"} {"id": 468, "problem": "An integer is called B-smooth if none of its prime factors is greater than $B$.\n\nLet $S_B(n)$ be the largest $B$-smooth divisor of $n$.\n\nExamples:\n\n$S_1(10)=1$\n\n$S_4(2100) = 12$\n\n$S_{17}(2496144) = 5712$\n\nDefine $\\displaystyle F(n)=\\sum_{B=1}^n \\sum_{r=0}^n S_B(\\binom n r)$. Here, $\\displaystyle \\binom n r$ denotes the binomial coefficient.\n\nExamples:\n\n$F(11) = 3132$\n\n$F(1111) \\mod 1\\,000\\,000\\,993 = 706036312$\n\n$F(111\\,111) \\mod 1\\,000\\,000\\,993 = 22156169$\n\nFind $F(11\\,111\\,111) \\mod 1\\,000\\,000\\,993$.", "raw_html": "

An integer is called B-smooth if none of its prime factors is greater than $B$.

\n\n

Let $S_B(n)$ be the largest $B$-smooth divisor of $n$.
\nExamples:
\n$S_1(10)=1$
\n$S_4(2100) = 12$
\n$S_{17}(2496144) = 5712$

\n

Define $\\displaystyle F(n)=\\sum_{B=1}^n \\sum_{r=0}^n S_B(\\binom n r)$. Here, $\\displaystyle \\binom n r$ denotes the binomial coefficient.
\nExamples:
\n$F(11) = 3132$
\n$F(1111) \\mod 1\\,000\\,000\\,993 = 706036312$
\n$F(111\\,111) \\mod 1\\,000\\,000\\,993 = 22156169$

\n\n

Find $F(11\\,111\\,111) \\mod 1\\,000\\,000\\,993$.

", "url": "https://projecteuler.net/problem=468", "answer": "852950321"} {"id": 469, "problem": "In a room $N$ chairs are placed around a round table.\n\nKnights enter the room one by one and choose at random an available empty chair.\n\nTo have enough elbow room the knights always leave at least one empty chair between each other.\n\nWhen there aren't any suitable chairs left, the fraction $C$ of empty chairs is determined.\n\nWe also define $E(N)$ as the expected value of $C$.\n\nWe can verify that $E(4) = 1/2$ and $E(6) = 5/9$.\n\nFind $E(10^{18})$. Give your answer rounded to fourteen decimal places in the form 0.abcdefghijklmn.", "raw_html": "

\nIn a room $N$ chairs are placed around a round table.
\nKnights enter the room one by one and choose at random an available empty chair.
\nTo have enough elbow room the knights always leave at least one empty chair between each other.\n

\n

\nWhen there aren't any suitable chairs left, the fraction $C$ of empty chairs is determined.
\nWe also define $E(N)$ as the expected value of $C$.
\nWe can verify that $E(4) = 1/2$ and $E(6) = 5/9$.\n

\n

\nFind $E(10^{18})$. Give your answer rounded to fourteen decimal places in the form 0.abcdefghijklmn.\n

", "url": "https://projecteuler.net/problem=469", "answer": "0.56766764161831"} {"id": 470, "problem": "Consider a single game of Ramvok:\n\nLet $t$ represent the maximum number of turns the game lasts. If $t = 0$, then the game ends immediately. Otherwise, on each turn $i$, the player rolls a die. After rolling, if $i \\lt t$ the player can either stop the game and receive a prize equal to the value of the current roll, or discard the roll and try again next turn. If $i = t$, then the roll cannot be discarded and the prize must be accepted. Before the game begins, $t$ is chosen by the player, who must then pay an up-front cost $ct$ for some constant $c$. For $c = 0$, $t$ can be chosen to be infinite (with an up-front cost of $0$). Let $R(d, c)$ be the expected profit (i.e. net gain) that the player receives from a single game of optimally-played Ramvok, given a fair $d$-sided die and cost constant $c$. For example, $R(4, 0.2) = 2.65$. Assume that the player has sufficient funds for paying any/all up-front costs.\n\nNow consider a game of Super Ramvok:\n\nIn Super Ramvok, the game of Ramvok is played repeatedly, but with a slight modification. After each game, the die is altered. The alteration process is as follows: The die is rolled once, and if the resulting face has its pips visible, then that face is altered to be blank instead. If the face is already blank, then it is changed back to its original value. After the alteration is made, another game of Ramvok can begin (and during such a game, at each turn, the die is rolled until a face with a value on it appears). The player knows which faces are blank and which are not at all times. The game of Super Ramvok ends once all faces of the die are blank.\n\nLet $S(d, c)$ be the expected profit that the player receives from an optimally-played game of Super Ramvok, given a fair $d$-sided die to start (with all sides visible), and cost constant $c$. For example, $S(6, 1) = 208.3$.\n\nLet $F(n) = \\sum_{4 \\le d \\le n} \\sum_{0 \\le c \\le n} S(d, c)$.\n\nCalculate $F(20)$, rounded to the nearest integer.", "raw_html": "

Consider a single game of Ramvok:

\n\n

Let $t$ represent the maximum number of turns the game lasts. If $t = 0$, then the game ends immediately. Otherwise, on each turn $i$, the player rolls a die. After rolling, if $i \\lt t$ the player can either stop the game and receive a prize equal to the value of the current roll, or discard the roll and try again next turn. If $i = t$, then the roll cannot be discarded and the prize must be accepted. Before the game begins, $t$ is chosen by the player, who must then pay an up-front cost $ct$ for some constant $c$. For $c = 0$, $t$ can be chosen to be infinite (with an up-front cost of $0$). Let $R(d, c)$ be the expected profit (i.e. net gain) that the player receives from a single game of optimally-played Ramvok, given a fair $d$-sided die and cost constant $c$. For example, $R(4, 0.2) = 2.65$. Assume that the player has sufficient funds for paying any/all up-front costs.

\n\n

Now consider a game of Super Ramvok:

\n\n

In Super Ramvok, the game of Ramvok is played repeatedly, but with a slight modification. After each game, the die is altered. The alteration process is as follows: The die is rolled once, and if the resulting face has its pips visible, then that face is altered to be blank instead. If the face is already blank, then it is changed back to its original value. After the alteration is made, another game of Ramvok can begin (and during such a game, at each turn, the die is rolled until a face with a value on it appears). The player knows which faces are blank and which are not at all times. The game of Super Ramvok ends once all faces of the die are blank.

\n\n

Let $S(d, c)$ be the expected profit that the player receives from an optimally-played game of Super Ramvok, given a fair $d$-sided die to start (with all sides visible), and cost constant $c$. For example, $S(6, 1) = 208.3$.

\n\n

Let $F(n) = \\sum_{4 \\le d \\le n} \\sum_{0 \\le c \\le n} S(d, c)$.

\n\n

Calculate $F(20)$, rounded to the nearest integer.

", "url": "https://projecteuler.net/problem=470", "answer": "147668794"} {"id": 471, "problem": "The triangle $\\triangle ABC$ is inscribed in an ellipse with equation $\\frac {x^2} {a^2} + \\frac {y^2} {b^2} = 1$, $0 \\lt 2b \\lt a$, $a$ and $b$ integers.\n\nLet $r(a, b)$ be the radius of the incircle of $\\triangle ABC$ when the incircle has center $(2b, 0)$ and $A$ has coordinates $\\left( \\frac a 2, \\frac {\\sqrt 3} 2 b\\right)$.\n\nFor example, $r(3,1)=\\frac12$, $r(6,2)=1$, $r(12,3)=2$.\n\nLet $G(n) = \\sum_{a=3}^n \\sum_{b=1}^{\\lfloor \\frac {a - 1} 2 \\rfloor} r(a, b)$\n\nYou are given $G(10) = 20.59722222$, $G(100) = 19223.60980$ (rounded to $10$ significant digits).\n\nFind $G(10^{11})$.\n\nGive your answer in scientific notation rounded to $10$ significant digits. Use a lowercase e to separate mantissa and exponent.\n\nFor $G(10)$ the answer would have been 2.059722222e1.", "raw_html": "

The triangle $\\triangle ABC$ is inscribed in an ellipse with equation $\\frac {x^2} {a^2} + \\frac {y^2} {b^2} = 1$, $0 \\lt 2b \\lt a$, $a$ and $b$ integers.

\n

Let $r(a, b)$ be the radius of the incircle of $\\triangle ABC$ when the incircle has center $(2b, 0)$ and $A$ has coordinates $\\left( \\frac a 2, \\frac {\\sqrt 3} 2 b\\right)$.

\n

For example, $r(3,1)=\\frac12$, $r(6,2)=1$, $r(12,3)=2$.

\n

\"0471-triangle-inscribed-in-ellipse-1.png\"

\n

\"0471-triangle-inscribed-in-ellipse-2.png\"

\n

Let $G(n) = \\sum_{a=3}^n \\sum_{b=1}^{\\lfloor \\frac {a - 1} 2 \\rfloor} r(a, b)$

\n

You are given $G(10) = 20.59722222$, $G(100) = 19223.60980$ (rounded to $10$ significant digits).

\n

Find $G(10^{11})$.

\n

Give your answer in scientific notation rounded to $10$ significant digits. Use a lowercase e to separate mantissa and exponent.

\n

For $G(10)$ the answer would have been 2.059722222e1.

", "url": "https://projecteuler.net/problem=471", "answer": "1.895093981e31"} {"id": 472, "problem": "There are $N$ seats in a row. $N$ people come one after another to fill the seats according to the following rules:\n\n- No person sits beside another.\n\n- The first person chooses any seat.\n\n- Each subsequent person chooses the seat furthest from anyone else already seated, as long as it does not violate rule 1. If there is more than one choice satisfying this condition, then the person chooses the leftmost choice.\n\nNote that due to rule 1, some seats will surely be left unoccupied, and the maximum number of people that can be seated is less than $N$ (for $N \\gt 1$).\n\nHere are the possible seating arrangements for $N = 15$:\n\nWe see that if the first person chooses correctly, the $15$ seats can seat up to $7$ people.\n\nWe can also see that the first person has $9$ choices to maximize the number of people that may be seated.\n\nLet $f(N)$ be the number of choices the first person has to maximize the number of occupants for $N$ seats in a row. Thus, $f(1) = 1$, $f(15) = 9$, $f(20) = 6$, and $f(500) = 16$.\n\nAlso, $\\sum f(N) = 83$ for $1 \\le N \\le 20$ and $\\sum f(N) = 13343$ for $1 \\le N \\le 500$.\n\nFind $\\sum f(N)$ for $1 \\le N \\le 10^{12}$. Give the last $8$ digits of your answer.", "raw_html": "

There are $N$ seats in a row. $N$ people come one after another to fill the seats according to the following rules:\n

  1. No person sits beside another.
  2. \n
  3. The first person chooses any seat.
  4. \n
  5. Each subsequent person chooses the seat furthest from anyone else already seated, as long as it does not violate rule 1. If there is more than one choice satisfying this condition, then the person chooses the leftmost choice.
  6. \n

Note that due to rule 1, some seats will surely be left unoccupied, and the maximum number of people that can be seated is less than $N$ (for $N \\gt 1$).

\n\n

Here are the possible seating arrangements for $N = 15$:\n

\"0472_n15.png\"

\n\n\n

We see that if the first person chooses correctly, the $15$ seats can seat up to $7$ people.
\nWe can also see that the first person has $9$ choices to maximize the number of people that may be seated.

\n\n

Let $f(N)$ be the number of choices the first person has to maximize the number of occupants for $N$ seats in a row. Thus, $f(1) = 1$, $f(15) = 9$, $f(20) = 6$, and $f(500) = 16$.

\n\n

Also, $\\sum f(N) = 83$ for $1 \\le N \\le 20$ and $\\sum f(N) = 13343$ for $1 \\le N \\le 500$.

\n\n

Find $\\sum f(N)$ for $1 \\le N \\le 10^{12}$. Give the last $8$ digits of your answer.

", "url": "https://projecteuler.net/problem=472", "answer": "73811586"} {"id": 473, "problem": "Let $\\varphi$ be the golden ratio: $\\varphi=\\frac{1+\\sqrt{5}}{2}.$\n\nRemarkably it is possible to write every positive integer as a sum of powers of $\\varphi$ even if we require that every power of $\\varphi$ is used at most once in this sum.\n\nEven then this representation is not unique.\n\nWe can make it unique by requiring that no powers with consecutive exponents are used and that the representation is finite.\n\nE.g:\n$2=\\varphi+\\varphi^{-2}$ and $3=\\varphi^{2}+\\varphi^{-2}$\n\nTo represent this sum of powers of $\\varphi$ we use a string of 0's and 1's with a point to indicate where the negative exponents start.\n\nWe call this the representation in the phigital numberbase.\n\nSo $1=1_{\\varphi}$, $2=10.01_{\\varphi}$, $3=100.01_{\\varphi}$ and $14=100100.001001_{\\varphi}$.\n\nThe strings representing $1$, $2$ and $14$ in the phigital number base are palindromic, while the string representing $3$ is not.\n(the phigital point is not the middle character).\n\nThe sum of the positive integers not exceeding $1000$ whose phigital representation is palindromic is $4345$.\n\nFind the sum of the positive integers not exceeding $10^{10}$ whose phigital representation is palindromic.", "raw_html": "

\nLet $\\varphi$ be the golden ratio: $\\varphi=\\frac{1+\\sqrt{5}}{2}.$
\nRemarkably it is possible to write every positive integer as a sum of powers of $\\varphi$ even if we require that every power of $\\varphi$ is used at most once in this sum.
\nEven then this representation is not unique.
\nWe can make it unique by requiring that no powers with consecutive exponents are used and that the representation is finite.
\nE.g: \n$2=\\varphi+\\varphi^{-2}$ and $3=\\varphi^{2}+\\varphi^{-2}$\n

\n

\nTo represent this sum of powers of $\\varphi$ we use a string of 0's and 1's with a point to indicate where the negative exponents start.
\nWe call this the representation in the phigital numberbase.
\nSo $1=1_{\\varphi}$, $2=10.01_{\\varphi}$, $3=100.01_{\\varphi}$ and $14=100100.001001_{\\varphi}$.
\nThe strings representing $1$, $2$ and $14$ in the phigital number base are palindromic, while the string representing $3$ is not.
(the phigital point is not the middle character).\n

\n

\nThe sum of the positive integers not exceeding $1000$ whose phigital representation is palindromic is $4345$.\n

\n

\nFind the sum of the positive integers not exceeding $10^{10}$ whose phigital representation is palindromic.

", "url": "https://projecteuler.net/problem=473", "answer": "35856681704365"} {"id": 474, "problem": "For a positive integer $n$ and digits $d$, we define $F(n, d)$ as the number of the divisors of $n$ whose last digits equal $d$.\n\nFor example, $F(84, 4) = 3$. Among the divisors of $84$ ($1, 2, 3, 4, 6, 7, 12, 14, 21, 28, 42, 84$), three of them ($4, 14, 84$) have the last digit $4$.\n\nWe can also verify that $F(12!, 12) = 11$ and $F(50!, 123) = 17888$.\n\nFind $F(10^6!, 65432)$ modulo ($10^{16} + 61$).", "raw_html": "

\nFor a positive integer $n$ and digits $d$, we define $F(n, d)$ as the number of the divisors of $n$ whose last digits equal $d$.
\nFor example, $F(84, 4) = 3$. Among the divisors of $84$ ($1, 2, 3, 4, 6, 7, 12, 14, 21, 28, 42, 84$), three of them ($4, 14, 84$) have the last digit $4$.\n

\n

\nWe can also verify that $F(12!, 12) = 11$ and $F(50!, 123) = 17888$.\n

\n

\nFind $F(10^6!, 65432)$ modulo ($10^{16} + 61$).\n

", "url": "https://projecteuler.net/problem=474", "answer": "9690646731515010"} {"id": 475, "problem": "$12n$ musicians participate at a music festival. On the first day, they form $3n$ quartets and practice all day.\n\nIt is a disaster. At the end of the day, all musicians decide they will never again agree to play with any member of their quartet.\n\nOn the second day, they form $4n$ trios, with every musician avoiding any previous quartet partners.\n\nLet $f(12n)$ be the number of ways to organize the trios amongst the $12n$ musicians.\n\nYou are given $f(12) = 576$ and $f(24) \\bmod 1\\,000\\,000\\,007 = 509089824$.\n\nFind $f(600) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

$12n$ musicians participate at a music festival. On the first day, they form $3n$ quartets and practice all day.

\n

It is a disaster. At the end of the day, all musicians decide they will never again agree to play with any member of their quartet.

\n

On the second day, they form $4n$ trios, with every musician avoiding any previous quartet partners.

\n\n

Let $f(12n)$ be the number of ways to organize the trios amongst the $12n$ musicians.

\n

You are given $f(12) = 576$ and $f(24) \\bmod 1\\,000\\,000\\,007 = 509089824$.

\n\n

Find $f(600) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=475", "answer": "75780067"} {"id": 476, "problem": "Let $R(a, b, c)$ be the maximum area covered by three non-overlapping circles inside a triangle with edge lengths $a$, $b$ and $c$.\n\nLet $S(n)$ be the average value of $R(a, b, c)$ over all integer triplets $(a, b, c)$ such that $1 \\le a \\le b \\le c \\lt a + b \\le n$.\n\nYou are given $S(2) = R(1, 1, 1) \\approx 0.31998$, $S(5) \\approx 1.25899$.\n\nFind $S(1803)$ rounded to $5$ decimal places behind the decimal point.", "raw_html": "

Let $R(a, b, c)$ be the maximum area covered by three non-overlapping circles inside a triangle with edge lengths $a$, $b$ and $c$.

\n

Let $S(n)$ be the average value of $R(a, b, c)$ over all integer triplets $(a, b, c)$ such that $1 \\le a \\le b \\le c \\lt a + b \\le n$.

\n

You are given $S(2) = R(1, 1, 1) \\approx 0.31998$, $S(5) \\approx 1.25899$.

\n

Find $S(1803)$ rounded to $5$ decimal places behind the decimal point.

", "url": "https://projecteuler.net/problem=476", "answer": "110242.87794"} {"id": 477, "problem": "The number sequence game starts with a sequence $S$ of $N$ numbers written on a line.\n\nTwo players alternate turns. The players on their respective turns must select and remove either the first or the last number remaining in the sequence.\n\nA player's own score is (determined by) the sum of all the numbers that player has taken. Each player attempts to maximize their own sum.\n\nIf $N = 4$ and $S = \\{1, 2, 10, 3\\}$, then each player maximizes their own score as follows:\n\n- Player 1: removes the first number ($1$)\n\n- Player 2: removes the last number from the remaining sequence ($3$)\n\n- Player 1: removes the last number from the remaining sequence ($10$)\n\n- Player 2: removes the remaining number ($2$)\n\nPlayer 1 score is $1 + 10 = 11$.\n\nLet $F(N)$ be the score of player 1 if both players follow the optimal strategy for the sequence $S = \\{s_1, s_2, \\dots, s_N\\}$ defined as:\n\n- $s_1 = 0$\n\n- $s_{i + 1} = (s_i^2 + 45)$ modulo $1\\,000\\,000\\,007$\n\nThe sequence begins with $S=\\{0, 45, 2070, 4284945, 753524550, 478107844, 894218625, \\dots\\}$.\n\nYou are given $F(2)=45$, $F(4)=4284990$, $F(100)=26365463243$, $F(10^4)=2495838522951$.\n\nFind $F(10^8)$.", "raw_html": "

The number sequence game starts with a sequence $S$ of $N$ numbers written on a line.

\n

Two players alternate turns. The players on their respective turns must select and remove either the first or the last number remaining in the sequence.

\n

A player's own score is (determined by) the sum of all the numbers that player has taken. Each player attempts to maximize their own sum.

\nIf $N = 4$ and $S = \\{1, 2, 10, 3\\}$, then each player maximizes their own score as follows:\n
  • Player 1: removes the first number ($1$)
  • \n
  • Player 2: removes the last number from the remaining sequence ($3$)
  • \n
  • Player 1: removes the last number from the remaining sequence ($10$)
  • \n
  • Player 2: removes the remaining number ($2$)
  • \n

Player 1 score is $1 + 10 = 11$.

\n

Let $F(N)$ be the score of player 1 if both players follow the optimal strategy for the sequence $S = \\{s_1, s_2, \\dots, s_N\\}$ defined as:

\n
  • $s_1 = 0$
  • \n
  • $s_{i + 1} = (s_i^2 + 45)$ modulo $1\\,000\\,000\\,007$
  • \n

The sequence begins with $S=\\{0, 45, 2070, 4284945, 753524550, 478107844, 894218625, \\dots\\}$.

\n

You are given $F(2)=45$, $F(4)=4284990$, $F(100)=26365463243$, $F(10^4)=2495838522951$.

\n

Find $F(10^8)$.

", "url": "https://projecteuler.net/problem=477", "answer": "25044905874565165"} {"id": 478, "problem": "Let us consider mixtures of three substances: A, B and C. A mixture can be described by a ratio of the amounts of A, B, and C in it, i.e., $(a : b : c)$. For example, a mixture described by the ratio $(2 : 3 : 5)$ contains $20\\%$ A, $30\\%$ B and $50\\%$ C.\n\nFor the purposes of this problem, we cannot separate the individual components from a mixture. However, we can combine different amounts of different mixtures to form mixtures with new ratios.\n\nFor example, say we have three mixtures with ratios $(3 : 0 : 2)$, $(3: 6 : 11)$ and $(3 : 3 : 4)$. By mixing $10$ units of the first, $20$ units of the second and $30$ units of the third, we get a new mixture with ratio $(6 : 5 : 9)$, since:\n\n$(10 \\cdot \\tfrac 3 5$ + $20 \\cdot \\tfrac 3 {20} + 30 \\cdot \\tfrac 3 {10} : 10 \\cdot \\tfrac 0 5 + 20 \\cdot \\tfrac 6 {20} + 30 \\cdot \\tfrac 3 {10} : 10 \\cdot \\tfrac 2 5 + 20 \\cdot \\tfrac {11} {20} + 30 \\cdot \\tfrac 4 {10})\n= (18 : 15 : 27) = (6 : 5 : 9)$\n\nHowever, with the same three mixtures, it is impossible to form the ratio $(3 : 2 : 1)$, since the amount of B is always less than the amount of C.\n\nLet $n$ be a positive integer. Suppose that for every triple of integers $(a, b, c)$ with $0 \\le a, b, c \\le n$ and $\\gcd(a, b, c) = 1$, we have a mixture with ratio $(a : b : c)$. Let $M(n)$ be the set of all such mixtures.\n\nFor example, $M(2)$ contains the $19$ mixtures with the following ratios:\n\n$$\\begin{align}\n\\{&(0 : 0 : 1), (0 : 1 : 0), (0 : 1 : 1), (0 : 1 : 2), (0 : 2 : 1),\\\\\n&(1 : 0 : 0), (1 : 0 : 1), (1 : 0 : 2), (1 : 1 : 0), (1 : 1 : 1),\\\\\n&(1 : 1 : 2), (1 : 2 : 0), (1 : 2 : 1), (1 : 2 : 2), (2 : 0 : 1),\\\\\n&(2 : 1 : 0), (2 : 1 : 1), (2 : 1 : 2), (2 : 2 : 1)\\}.\n\\end{align}$$\n\nLet $E(n)$ be the number of subsets of $M(n)$ which can produce the mixture with ratio $(1 : 1 : 1)$, i.e., the mixture with equal parts A, B and C.\n\nWe can verify that $E(1) = 103$, $E(2) = 520447$, $E(10) \\bmod 11^8 = 82608406$ and $E(500) \\bmod 11^8 = 13801403$.\n\nFind $E(10\\,000\\,000) \\bmod 11^8$.", "raw_html": "

Let us consider mixtures of three substances: A, B and C. A mixture can be described by a ratio of the amounts of A, B, and C in it, i.e., $(a : b : c)$. For example, a mixture described by the ratio $(2 : 3 : 5)$ contains $20\\%$ A, $30\\%$ B and $50\\%$ C.

\n\n

For the purposes of this problem, we cannot separate the individual components from a mixture. However, we can combine different amounts of different mixtures to form mixtures with new ratios.

\n\n

For example, say we have three mixtures with ratios $(3 : 0 : 2)$, $(3: 6 : 11)$ and $(3 : 3 : 4)$. By mixing $10$ units of the first, $20$ units of the second and $30$ units of the third, we get a new mixture with ratio $(6 : 5 : 9)$, since:
\n$(10 \\cdot \\tfrac 3 5$ + $20 \\cdot \\tfrac 3 {20} + 30 \\cdot \\tfrac 3 {10} : 10 \\cdot \\tfrac 0 5 + 20 \\cdot \\tfrac 6 {20} + 30 \\cdot \\tfrac 3 {10} : 10 \\cdot \\tfrac 2 5 + 20 \\cdot \\tfrac {11} {20} + 30 \\cdot \\tfrac 4 {10})\n= (18 : 15 : 27) = (6 : 5 : 9)$\n

\n\n

However, with the same three mixtures, it is impossible to form the ratio $(3 : 2 : 1)$, since the amount of B is always less than the amount of C.

\n\n

Let $n$ be a positive integer. Suppose that for every triple of integers $(a, b, c)$ with $0 \\le a, b, c \\le n$ and $\\gcd(a, b, c) = 1$, we have a mixture with ratio $(a : b : c)$. Let $M(n)$ be the set of all such mixtures.

\n\n

For example, $M(2)$ contains the $19$ mixtures with the following ratios:

\n$$\\begin{align}\n\\{&(0 : 0 : 1), (0 : 1 : 0), (0 : 1 : 1), (0 : 1 : 2), (0 : 2 : 1),\\\\\n&(1 : 0 : 0), (1 : 0 : 1), (1 : 0 : 2), (1 : 1 : 0), (1 : 1 : 1),\\\\\n&(1 : 1 : 2), (1 : 2 : 0), (1 : 2 : 1), (1 : 2 : 2), (2 : 0 : 1),\\\\\n&(2 : 1 : 0), (2 : 1 : 1), (2 : 1 : 2), (2 : 2 : 1)\\}.\n\\end{align}$$\n\n

Let $E(n)$ be the number of subsets of $M(n)$ which can produce the mixture with ratio $(1 : 1 : 1)$, i.e., the mixture with equal parts A, B and C.
\nWe can verify that $E(1) = 103$, $E(2) = 520447$, $E(10) \\bmod 11^8 = 82608406$ and $E(500) \\bmod 11^8 = 13801403$.
\nFind $E(10\\,000\\,000) \\bmod 11^8$.

", "url": "https://projecteuler.net/problem=478", "answer": "59510340"} {"id": 479, "problem": "Let $a_k$, $b_k$, and $c_k$ represent the three solutions (real or complex numbers) to the equation\n$\\frac 1 x = (\\frac k x)^2(k+x^2)-k x$.\n\nFor instance, for $k=5$, we see that $\\{a_5, b_5, c_5 \\}$ is approximately $\\{5.727244, -0.363622+2.057397i, -0.363622-2.057397i\\}$.\n\nLet $\\displaystyle S(n) = \\sum_{p=1}^n\\sum_{k=1}^n(a_k+b_k)^p(b_k+c_k)^p(c_k+a_k)^p$.\n\nInterestingly, $S(n)$ is always an integer. For example, $S(4) = 51160$.\n\nFind $S(10^6)$ modulo $1\\,000\\,000\\,007$.", "raw_html": "

Let $a_k$, $b_k$, and $c_k$ represent the three solutions (real or complex numbers) to the equation\n$\\frac 1 x = (\\frac k x)^2(k+x^2)-k x$.

\n\n

For instance, for $k=5$, we see that $\\{a_5, b_5, c_5 \\}$ is approximately $\\{5.727244, -0.363622+2.057397i, -0.363622-2.057397i\\}$.

\n\n

Let $\\displaystyle S(n) = \\sum_{p=1}^n\\sum_{k=1}^n(a_k+b_k)^p(b_k+c_k)^p(c_k+a_k)^p$.

\n\n

Interestingly, $S(n)$ is always an integer. For example, $S(4) = 51160$.

\n\n

Find $S(10^6)$ modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=479", "answer": "191541795"} {"id": 480, "problem": "Consider all the words which can be formed by selecting letters, in any order, from the phrase:\n\nthereisasyetinsufficientdataforameaningfulanswer\n\nSuppose those with 15 letters or less are listed in alphabetical order and numbered sequentially starting at 1.\n\nThe list would include:\n\n- 1 : a\n\n- 2 : aa\n\n- 3 : aaa\n\n- 4 : aaaa\n\n- 5 : aaaaa\n\n- 6 : aaaaaa\n\n- 7 : aaaaaac\n\n- 8 : aaaaaacd\n\n- 9 : aaaaaacde\n\n- 10 : aaaaaacdee\n\n- 11 : aaaaaacdeee\n\n- 12 : aaaaaacdeeee\n\n- 13 : aaaaaacdeeeee\n\n- 14 : aaaaaacdeeeeee\n\n- 15 : aaaaaacdeeeeeef\n\n- 16 : aaaaaacdeeeeeeg\n\n- 17 : aaaaaacdeeeeeeh\n\n- ...\n\n- 28 : aaaaaacdeeeeeey\n\n- 29 : aaaaaacdeeeeef\n\n- 30 : aaaaaacdeeeeefe\n\n- ...\n\n- 115246685191495242: euleoywuttttsss\n\n- 115246685191495243: euler\n\n- 115246685191495244: eulera\n\n- ...\n\n- 525069350231428029: ywuuttttssssrrr\n\nDefine P(w) as the position of the word w.\n\nDefine W(p) as the word in position p.\n\nWe can see that P(w) and W(p) are inverses: P(W(p)) = p and W(P(w)) = w.\n\nExamples:\n\n- W(10) = aaaaaacdee\n\n- P(aaaaaacdee) = 10\n\n- W(115246685191495243) = euler\n\n- P(euler) = 115246685191495243\n\nFind W(P(legionary) + P(calorimeters) - P(annihilate) + P(orchestrated) - P(fluttering)).\n\nGive your answer using lowercase characters (no punctuation or space).", "raw_html": "

Consider all the words which can be formed by selecting letters, in any order, from the phrase:

\n

thereisasyetinsufficientdataforameaningfulanswer
\n

Suppose those with 15 letters or less are listed in alphabetical order and numbered sequentially starting at 1.
\nThe list would include:

\n
  • 1 : a
  • \n
  • 2 : aa
  • \n
  • 3 : aaa
  • \n
  • 4 : aaaa
  • \n
  • 5 : aaaaa
  • \n
  • 6 : aaaaaa
  • \n
  • 7 : aaaaaac
  • \n
  • 8 : aaaaaacd
  • \n
  • 9 : aaaaaacde
  • \n
  • 10 : aaaaaacdee
  • \n
  • 11 : aaaaaacdeee
  • \n
  • 12 : aaaaaacdeeee
  • \n
  • 13 : aaaaaacdeeeee
  • \n
  • 14 : aaaaaacdeeeeee
  • \n
  • 15 : aaaaaacdeeeeeef
  • \n
  • 16 : aaaaaacdeeeeeeg
  • \n
  • 17 : aaaaaacdeeeeeeh
  • \n
  • ...
  • \n
  • 28 : aaaaaacdeeeeeey
  • \n
  • 29 : aaaaaacdeeeeef
  • \n
  • 30 : aaaaaacdeeeeefe
  • \n
  • ...
  • \n
  • 115246685191495242: euleoywuttttsss
  • \n
  • 115246685191495243: euler
  • \n
  • 115246685191495244: eulera
  • \n
  • ...
  • \n
  • 525069350231428029: ywuuttttssssrrr

Define P(w) as the position of the word w.
\nDefine W(p) as the word in position p.
\nWe can see that P(w) and W(p) are inverses: P(W(p)) = p and W(P(w)) = w.

\n

Examples:

\n
  • W(10) = aaaaaacdee
  • \n
  • P(aaaaaacdee) = 10
  • \n
  • W(115246685191495243) = euler
  • \n
  • P(euler) = 115246685191495243

Find W(P(legionary) + P(calorimeters) - P(annihilate) + P(orchestrated) - P(fluttering)).
\nGive your answer using lowercase characters (no punctuation or space).

", "url": "https://projecteuler.net/problem=480", "answer": "turnthestarson"} {"id": 481, "problem": "A group of chefs (numbered #$1$, #$2$, etc) participate in a turn-based strategic cooking competition. On each chef's turn, he/she cooks up a dish to the best of his/her ability and gives it to a separate panel of judges for taste-testing. Let $S(k)$ represent chef #$k$'s skill level (which is publicly known). More specifically, $S(k)$ is the probability that chef #$k$'s dish will be assessed favorably by the judges (on any/all turns). If the dish receives a favorable rating, then the chef must choose one other chef to be eliminated from the competition. The last chef remaining in the competition is the winner.\n\nThe game always begins with chef #$1$, with the turn order iterating sequentially over the rest of the chefs still in play. Then the cycle repeats from the lowest-numbered chef. All chefs aim to optimize their chances of winning within the rules as stated, assuming that the other chefs behave in the same manner. In the event that a chef has more than one equally-optimal elimination choice, assume that the chosen chef is always the one with the next-closest turn.\n\nDefine $W_n(k)$ as the probability that chef #$k$ wins in a competition with $n$ chefs. If we have $S(1) = 0.25$, $S(2) = 0.5$, and $S(3) = 1$, then $W_3(1) = 0.29375$.\n\nGoing forward, we assign $S(k) = F_k/F_{n+1}$ over all $1 \\le k \\le n$, where $F_k$ is a Fibonacci number: $F_k = F_{k-1} + F_{k-2}$ with base cases $F_1 = F_2 = 1$. Then, for example, when considering a competition with $n = 7$ chefs, we have $W_7(1) = 0.08965042$, $W_7(2) = 0.20775702$, $W_7(3) = 0.15291406$, $W_7(4) = 0.14554098$, $W_7(5) = 0.15905291$, $W_7(6) = 0.10261412$, and $W_7(7) = 0.14247050$, rounded to $8$ decimal places each.\n\nLet $E(n)$ represent the expected number of dishes cooked in a competition with $n$ chefs. For instance, $E(7) = 42.28176050$.\n\nFind $E(14)$ rounded to $8$ decimal places.", "raw_html": "

A group of chefs (numbered #$1$, #$2$, etc) participate in a turn-based strategic cooking competition. On each chef's turn, he/she cooks up a dish to the best of his/her ability and gives it to a separate panel of judges for taste-testing. Let $S(k)$ represent chef #$k$'s skill level (which is publicly known). More specifically, $S(k)$ is the probability that chef #$k$'s dish will be assessed favorably by the judges (on any/all turns). If the dish receives a favorable rating, then the chef must choose one other chef to be eliminated from the competition. The last chef remaining in the competition is the winner.

\n\n

The game always begins with chef #$1$, with the turn order iterating sequentially over the rest of the chefs still in play. Then the cycle repeats from the lowest-numbered chef. All chefs aim to optimize their chances of winning within the rules as stated, assuming that the other chefs behave in the same manner. In the event that a chef has more than one equally-optimal elimination choice, assume that the chosen chef is always the one with the next-closest turn.

\n\n

Define $W_n(k)$ as the probability that chef #$k$ wins in a competition with $n$ chefs. If we have $S(1) = 0.25$, $S(2) = 0.5$, and $S(3) = 1$, then $W_3(1) = 0.29375$.

\n\n

Going forward, we assign $S(k) = F_k/F_{n+1}$ over all $1 \\le k \\le n$, where $F_k$ is a Fibonacci number: $F_k = F_{k-1} + F_{k-2}$ with base cases $F_1 = F_2 = 1$. Then, for example, when considering a competition with $n = 7$ chefs, we have $W_7(1) = 0.08965042$, $W_7(2) = 0.20775702$, $W_7(3) = 0.15291406$, $W_7(4) = 0.14554098$, $W_7(5) = 0.15905291$, $W_7(6) = 0.10261412$, and $W_7(7) = 0.14247050$, rounded to $8$ decimal places each.

\n\n

Let $E(n)$ represent the expected number of dishes cooked in a competition with $n$ chefs. For instance, $E(7) = 42.28176050$.

\n\n

Find $E(14)$ rounded to $8$ decimal places.

", "url": "https://projecteuler.net/problem=481", "answer": "729.12106947"} {"id": 482, "problem": "$ABC$ is an integer sided triangle with incenter $I$ and perimeter $p$.\n\nThe segments $IA$, $IB$ and $IC$ have integral length as well.\n\nLet $L = p + |IA| + |IB| + |IC|$.\n\nLet $S(P) = \\sum L$ for all such triangles where $p \\le P$. For example, $S(10^3) = 3619$.\n\nFind $S(10^7)$.", "raw_html": "

\n$ABC$ is an integer sided triangle with incenter $I$ and perimeter $p$.
\nThe segments $IA$, $IB$ and $IC$ have integral length as well. \n

\n

\nLet $L = p + |IA| + |IB| + |IC|$. \n

\n

\nLet $S(P) = \\sum L$ for all such triangles where $p \\le P$. For example, $S(10^3) = 3619$.\n

\n

\nFind $S(10^7)$.\n

", "url": "https://projecteuler.net/problem=482", "answer": "1400824879147"} {"id": 483, "problem": "We define a permutation as an operation that rearranges the order of the elements $\\{1, 2, 3, ..., n\\}$.\nThere are $n!$ such permutations, one of which leaves the elements in their initial order.\nFor $n = 3$ we have $3! = 6$ permutations:\n\n- $P_1 =$ keep the initial order\n\n- $P_2 =$ exchange the 1st and 2nd elements\n\n- $P_3 =$ exchange the 1st and 3rd elements\n\n- $P_4 =$ exchange the 2nd and 3rd elements\n\n- $P_5 =$ rotate the elements to the right\n\n- $P_6 =$ rotate the elements to the left\n\nIf we select one of these permutations, and we re-apply the same permutation repeatedly, we eventually restore the initial order.\nFor a permutation $P_i$, let $f(P_i)$ be the number of steps required to restore the initial order by applying the permutation $P_i$ repeatedly.\nFor $n = 3$, we obtain:\n\n- $f(P_1) = 1$ : $(1,2,3) \\to (1,2,3)$\n\n- $f(P_2) = 2$ : $(1,2,3) \\to (2,1,3) \\to (1,2,3)$\n\n- $f(P_3) = 2$ : $(1,2,3) \\to (3,2,1) \\to (1,2,3)$\n\n- $f(P_4) = 2$ : $(1,2,3) \\to (1,3,2) \\to (1,2,3)$\n\n- $f(P_5) = 3$ : $(1,2,3) \\to (3,1,2) \\to (2,3,1) \\to (1,2,3)$\n\n- $f(P_6) = 3$ : $(1,2,3) \\to (2,3,1) \\to (3,1,2) \\to (1,2,3)$\n\nLet $g(n)$ be the average value of $f^2(P_i)$ over all permutations $P_i$ of length $n$.\n$g(3) = (1^2 + 2^2 + 2^2 + 2^2 + 3^2 + 3^2)/3! = 31/6 \\approx 5.166666667\\mathrm e0$\n$g(5) = 2081/120 \\approx 1.734166667\\mathrm e1$\n$g(20) = 12422728886023769167301/2432902008176640000 \\approx 5.106136147\\mathrm e3$\n\nFind $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.", "raw_html": "

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

    \n
  • $P_1 =$ keep the initial order
  • \n
  • $P_2 =$ exchange the 1st and 2nd elements
  • \n
  • $P_3 =$ exchange the 1st and 3rd elements
  • \n
  • $P_4 =$ exchange the 2nd and 3rd elements
  • \n
  • $P_5 =$ rotate the elements to the right
  • \n
  • $P_6 =$ rotate the elements to the left
\n\n

\nIf we select one of these permutations, and we re-apply the same permutation repeatedly, we eventually restore the initial order.
For a permutation $P_i$, let $f(P_i)$ be the number of steps required to restore the initial order by applying the permutation $P_i$ repeatedly.
For $n = 3$, we obtain:

\n
    \n
  • $f(P_1) = 1$ : $(1,2,3) \\to (1,2,3)$
  • \n
  • $f(P_2) = 2$ : $(1,2,3) \\to (2,1,3) \\to (1,2,3)$
  • \n
  • $f(P_3) = 2$ : $(1,2,3) \\to (3,2,1) \\to (1,2,3)$
  • \n
  • $f(P_4) = 2$ : $(1,2,3) \\to (1,3,2) \\to (1,2,3)$
  • \n
  • $f(P_5) = 3$ : $(1,2,3) \\to (3,1,2) \\to (2,3,1) \\to (1,2,3)$
  • \n
  • $f(P_6) = 3$ : $(1,2,3) \\to (2,3,1) \\to (3,1,2) \\to (1,2,3)$
\n\n

\nLet $g(n)$ be the average value of $f^2(P_i)$ over all permutations $P_i$ of length $n$.
$g(3) = (1^2 + 2^2 + 2^2 + 2^2 + 3^2 + 3^2)/3! = 31/6 \\approx 5.166666667\\mathrm e0$
$g(5) = 2081/120 \\approx 1.734166667\\mathrm e1$
$g(20) = 12422728886023769167301/2432902008176640000 \\approx 5.106136147\\mathrm e3$\n

\n

\nFind $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.\n

", "url": "https://projecteuler.net/problem=483", "answer": "4.993401567e22"} {"id": 484, "problem": "The arithmetic derivative is defined by\n\n- $p^\\prime = 1$ for any prime $p$\n\n- $(ab)^\\prime = a^\\prime b + ab^\\prime$ for all integers $a, b$ (Leibniz rule)\n\nFor example, $20^\\prime = 24$.\n\nFind $\\sum \\operatorname{\\mathbf{gcd}}(k,k^\\prime)$ for $1 \\lt k \\le 5 \\times 10^{15}$.\n\nNote: $\\operatorname{\\mathbf{gcd}}(x,y)$ denotes the greatest common divisor of $x$ and $y$.", "raw_html": "

The arithmetic derivative is defined by

\n
  • $p^\\prime = 1$ for any prime $p$
  • \n
  • $(ab)^\\prime = a^\\prime b + ab^\\prime$ for all integers $a, b$ (Leibniz rule)
  • \n

For example, $20^\\prime = 24$.

\n\n

Find $\\sum \\operatorname{\\mathbf{gcd}}(k,k^\\prime)$ for $1 \\lt k \\le 5 \\times 10^{15}$.

\n\n

Note: $\\operatorname{\\mathbf{gcd}}(x,y)$ denotes the greatest common divisor of $x$ and $y$.

", "url": "https://projecteuler.net/problem=484", "answer": "8907904768686152599"} {"id": 485, "problem": "Let $d(n)$ be the number of divisors of $n$.\n\nLet $M(n,k)$ be the maximum value of $d(j)$ for $n \\le j \\le n+k-1$.\n\nLet $S(u,k)$ be the sum of $M(n,k)$ for $1 \\le n \\le u-k+1$.\n\nYou are given that $S(1000,10)=17176$.\n\nFind $S(100\\,000\\,000, 100\\,000)$.", "raw_html": "

\nLet $d(n)$ be the number of divisors of $n$.
\nLet $M(n,k)$ be the maximum value of $d(j)$ for $n \\le j \\le n+k-1$.
\nLet $S(u,k)$ be the sum of $M(n,k)$ for $1 \\le n \\le u-k+1$.\n

\n

\nYou are given that $S(1000,10)=17176$.\n

\n

\nFind $S(100\\,000\\,000, 100\\,000)$.\n

", "url": "https://projecteuler.net/problem=485", "answer": "51281274340"} {"id": 486, "problem": "Let $F_5(n)$ be the number of strings $s$ such that:\n\n- $s$ consists only of '0's and '1's,\n\n- $s$ has length at most $n$, and\n\n- $s$ contains a palindromic substring of length at least $5$.\n\nFor example, $F_5(4) = 0$, $F_5(5) = 8$,\n$F_5(6) = 42$ and $F_5(11) = 3844$.\n\nLet $D(L)$ be the number of integers $n$ such that $5 \\le n \\le L$ and $F_5(n)$ is divisible by $87654321$.\n\nFor example, $D(10^7) = 0$ and $D(5 \\cdot 10^9) = 51$.\n\nFind $D(10^{18})$.", "raw_html": "

Let $F_5(n)$ be the number of strings $s$ such that:

\n
  • $s$ consists only of '0's and '1's,\n
  • $s$ has length at most $n$, and\n
  • $s$ contains a palindromic substring of length at least $5$.\n

For example, $F_5(4) = 0$, $F_5(5) = 8$, \n$F_5(6) = 42$ and $F_5(11) = 3844$.

\n\n

Let $D(L)$ be the number of integers $n$ such that $5 \\le n \\le L$ and $F_5(n)$ is divisible by $87654321$.

\n\n

For example, $D(10^7) = 0$ and $D(5 \\cdot 10^9) = 51$.

\n\n

Find $D(10^{18})$.

", "url": "https://projecteuler.net/problem=486", "answer": "11408450515"} {"id": 487, "problem": "Let $f_k(n)$ be the sum of the $k$th powers of the first $n$ positive integers.\n\nFor example, $f_2(10) = 1^2 + 2^2 + 3^2 + 4^2 + 5^2 + 6^2 + 7^2 + 8^2 + 9^2 + 10^2 = 385$.\n\nLet $S_k(n)$ be the sum of $f_k(i)$ for $1 \\le i \\le n$. For example, $S_4(100) = 35375333830$.\n\nWhat is $\\sum (S_{10000}(10^{12}) \\bmod p)$ over all primes $p$ between $2 \\cdot 10^9$ and $2 \\cdot 10^9 + 2000$?", "raw_html": "

Let $f_k(n)$ be the sum of the $k$th powers of the first $n$ positive integers.

\n\n

For example, $f_2(10) = 1^2 + 2^2 + 3^2 + 4^2 + 5^2 + 6^2 + 7^2 + 8^2 + 9^2 + 10^2 = 385$.

\n\n

Let $S_k(n)$ be the sum of $f_k(i)$ for $1 \\le i \\le n$. For example, $S_4(100) = 35375333830$.

\n\n

What is $\\sum (S_{10000}(10^{12}) \\bmod p)$ over all primes $p$ between $2 \\cdot 10^9$ and $2 \\cdot 10^9 + 2000$?

", "url": "https://projecteuler.net/problem=487", "answer": "106650212746"} {"id": 488, "problem": "Alice and Bob have enjoyed playing Nim every day. However, they finally got bored of playing ordinary three-heap Nim.\n\nSo, they added an extra rule:\n\n- Must not make two heaps of the same size.\n\nThe triple $(a, b, c)$ indicates the size of three heaps.\n\nUnder this extra rule, $(2,4,5)$ is one of the losing positions for the next player.\n\nTo illustrate:\n\n- Alice moves to $(2,4,3)$\n\n- Bob moves to $(0,4,3)$\n\n- Alice moves to $(0,2,3)$\n\n- Bob moves to $(0,2,1)$\n\nUnlike ordinary three-heap Nim, $(0,1,2)$ and its permutations are the end states of this game.\n\nFor an integer $N$, we define $F(N)$ as the sum of $a + b + c$ for all the losing positions for the next player, with $0 \\lt a \\lt b \\lt c \\lt N$.\n\nFor example, $F(8) = 42$, because there are $4$ losing positions for the next player, $(1,3,5)$, $(1,4,6)$, $(2,3,6)$ and $(2,4,5)$.\n\nWe can also verify that $F(128) = 496062$.\n\nFind the last $9$ digits of $F(10^{18})$.", "raw_html": "

Alice and Bob have enjoyed playing Nim every day. However, they finally got bored of playing ordinary three-heap Nim.
\nSo, they added an extra rule:

\n\n

- Must not make two heaps of the same size.

\n\n

The triple $(a, b, c)$ indicates the size of three heaps.
\nUnder this extra rule, $(2,4,5)$ is one of the losing positions for the next player.

\n\n

To illustrate:
\n- Alice moves to $(2,4,3)$
\n- Bob moves to $(0,4,3)$
\n- Alice moves to $(0,2,3)$
\n- Bob moves to $(0,2,1)$

\n\n

Unlike ordinary three-heap Nim, $(0,1,2)$ and its permutations are the end states of this game.

\n\n

For an integer $N$, we define $F(N)$ as the sum of $a + b + c$ for all the losing positions for the next player, with $0 \\lt a \\lt b \\lt c \\lt N$.

\n\n

For example, $F(8) = 42$, because there are $4$ losing positions for the next player, $(1,3,5)$, $(1,4,6)$, $(2,3,6)$ and $(2,4,5)$.
\nWe can also verify that $F(128) = 496062$.

\n\n

Find the last $9$ digits of $F(10^{18})$.

", "url": "https://projecteuler.net/problem=488", "answer": "216737278"} {"id": 489, "problem": "Let $G(a, b)$ be the smallest non-negative integer $n$ for which $\\operatorname{\\mathbf{gcd}}$Greatest common divisor$(n^3 + b, (n + a)^3 + b)$ is maximized.\n\nFor example, $G(1, 1) = 5$ because $\\gcd(n^3 + 1, (n + 1)^3 + 1)$ reaches its maximum value of $7$ for $n = 5$, and is smaller for $0 \\le n \\lt 5$.\n\nLet $H(m, n) = \\sum G(a, b)$ for $1 \\le a \\le m$, $1 \\le b \\le n$.\n\nYou are given $H(5, 5) = 128878$ and $H(10, 10) = 32936544$.\n\nFind $H(18, 1900)$.", "raw_html": "

Let $G(a, b)$ be the smallest non-negative integer $n$ for which $\\operatorname{\\mathbf{gcd}}$Greatest common divisor$(n^3 + b, (n + a)^3 + b)$ is maximized.
\nFor example, $G(1, 1) = 5$ because $\\gcd(n^3 + 1, (n + 1)^3 + 1)$ reaches its maximum value of $7$ for $n = 5$, and is smaller for $0 \\le n \\lt 5$.
\nLet $H(m, n) = \\sum G(a, b)$ for $1 \\le a \\le m$, $1 \\le b \\le n$.
\nYou are given $H(5, 5) = 128878$ and $H(10, 10) = 32936544$.\n

Find $H(18, 1900)$.

", "url": "https://projecteuler.net/problem=489", "answer": "1791954757162"} {"id": 490, "problem": "There are $n$ stones in a pond, numbered $1$ to $n$. Consecutive stones are spaced one unit apart.\n\nA frog sits on stone $1$. He wishes to visit each stone exactly once, stopping on stone $n$. However, he can only jump from one stone to another if they are at most $3$ units apart. In other words, from stone $i$, he can reach a stone $j$ if $1 \\le j \\le n$ and $j$ is in the set $\\{i-3, i-2, i-1, i+1, i+2, i+3\\}$.\n\nLet $f(n)$ be the number of ways he can do this. For example, $f(6) = 14$, as shown below:\n\n$1 \\to 2 \\to 3 \\to 4 \\to 5 \\to 6$\n\n$1 \\to 2 \\to 3 \\to 5 \\to 4 \\to 6$\n\n$1 \\to 2 \\to 4 \\to 3 \\to 5 \\to 6$\n\n$1 \\to 2 \\to 4 \\to 5 \\to 3 \\to 6$\n\n$1 \\to 2 \\to 5 \\to 3 \\to 4 \\to 6$\n\n$1 \\to 2 \\to 5 \\to 4 \\to 3 \\to 6$\n\n$1 \\to 3 \\to 2 \\to 4 \\to 5 \\to 6$\n\n$1 \\to 3 \\to 2 \\to 5 \\to 4 \\to 6$\n\n$1 \\to 3 \\to 4 \\to 2 \\to 5 \\to 6$\n\n$1 \\to 3 \\to 5 \\to 2 \\to 4 \\to 6$\n\n$1 \\to 4 \\to 2 \\to 3 \\to 5 \\to 6$\n\n$1 \\to 4 \\to 2 \\to 5 \\to 3 \\to 6$\n\n$1 \\to 4 \\to 3 \\to 2 \\to 5 \\to 6$\n\n$1 \\to 4 \\to 5 \\to 2 \\to 3 \\to 6$\n\nOther examples are $f(10) = 254$ and $f(40) = 1439682432976$.\n\nLet $S(L) = \\sum f(n)^3$ for $1 \\le n \\le L$.\n\nExamples:\n\n$S(10) = 18230635$\n\n$S(20) = 104207881192114219$\n\n$S(1\\,000) \\bmod 10^9 = 225031475$\n\n$S(1\\,000\\,000) \\bmod 10^9 = 363486179$\n\nFind $S(10^{14}) \\bmod 10^9$.", "raw_html": "

There are $n$ stones in a pond, numbered $1$ to $n$. Consecutive stones are spaced one unit apart.

\n\n

A frog sits on stone $1$. He wishes to visit each stone exactly once, stopping on stone $n$. However, he can only jump from one stone to another if they are at most $3$ units apart. In other words, from stone $i$, he can reach a stone $j$ if $1 \\le j \\le n$ and $j$ is in the set $\\{i-3, i-2, i-1, i+1, i+2, i+3\\}$.

\n\n

Let $f(n)$ be the number of ways he can do this. For example, $f(6) = 14$, as shown below:
\n$1 \\to 2 \\to 3 \\to 4 \\to 5 \\to 6$
\n$1 \\to 2 \\to 3 \\to 5 \\to 4 \\to 6$
\n$1 \\to 2 \\to 4 \\to 3 \\to 5 \\to 6$
\n$1 \\to 2 \\to 4 \\to 5 \\to 3 \\to 6$
\n$1 \\to 2 \\to 5 \\to 3 \\to 4 \\to 6$
\n$1 \\to 2 \\to 5 \\to 4 \\to 3 \\to 6$
\n$1 \\to 3 \\to 2 \\to 4 \\to 5 \\to 6$
\n$1 \\to 3 \\to 2 \\to 5 \\to 4 \\to 6$
\n$1 \\to 3 \\to 4 \\to 2 \\to 5 \\to 6$
\n$1 \\to 3 \\to 5 \\to 2 \\to 4 \\to 6$
\n$1 \\to 4 \\to 2 \\to 3 \\to 5 \\to 6$
\n$1 \\to 4 \\to 2 \\to 5 \\to 3 \\to 6$
\n$1 \\to 4 \\to 3 \\to 2 \\to 5 \\to 6$
\n$1 \\to 4 \\to 5 \\to 2 \\to 3 \\to 6$

\n\n

Other examples are $f(10) = 254$ and $f(40) = 1439682432976$.

\n\n

Let $S(L) = \\sum f(n)^3$ for $1 \\le n \\le L$.
\nExamples:
\n$S(10) = 18230635$
\n$S(20) = 104207881192114219$
\n$S(1\\,000) \\bmod 10^9 = 225031475$
\n$S(1\\,000\\,000) \\bmod 10^9 = 363486179$

\n\n

Find $S(10^{14}) \\bmod 10^9$.

", "url": "https://projecteuler.net/problem=490", "answer": "777577686"} {"id": 491, "problem": "We call a positive integer double pandigital if it uses all the digits $0$ to $9$ exactly twice (with no leading zero). For example, $40561817703823564929$ is one such number.\n\nHow many double pandigital numbers are divisible by $11$?", "raw_html": "

We call a positive integer double pandigital if it uses all the digits $0$ to $9$ exactly twice (with no leading zero). For example, $40561817703823564929$ is one such number.

\n\n

How many double pandigital numbers are divisible by $11$?

", "url": "https://projecteuler.net/problem=491", "answer": "194505988824000"} {"id": 492, "problem": "Define the sequence $a_1, a_2, a_3, \\dots$ as:\n\n- $a_1 = 1$\n\n- $a_{n+1} = 6a_n^2 + 10a_n + 3$ for $n \\ge 1$.\n\nExamples:\n\n$a_3 = 2359$\n\n$a_6 = 269221280981320216750489044576319$\n\n$a_6 \\bmod 1\\,000\\,000\\,007 = 203064689$\n\n$a_{100} \\bmod 1\\,000\\,000\\,007 = 456482974$\n\nDefine $B(x,y,n)$ as $\\sum (a_n \\bmod p)$ for every prime $p$ such that $x \\le p \\le x+y$.\n\nExamples:\n\n$B(10^9, 10^3, 10^3) = 23674718882$\n\n$B(10^9, 10^3, 10^{15}) = 20731563854$\n\nFind $B(10^9, 10^7, 10^{15})$.", "raw_html": "

Define the sequence $a_1, a_2, a_3, \\dots$ as:

\n
  • $a_1 = 1$
  • \n
  • $a_{n+1} = 6a_n^2 + 10a_n + 3$ for $n \\ge 1$.
  • \n

\nExamples:
\n$a_3 = 2359$
\n$a_6 = 269221280981320216750489044576319$
\n$a_6 \\bmod 1\\,000\\,000\\,007 = 203064689$
\n$a_{100} \\bmod 1\\,000\\,000\\,007 = 456482974$\n

\n\n

\nDefine $B(x,y,n)$ as $\\sum (a_n \\bmod p)$ for every prime $p$ such that $x \\le p \\le x+y$.\n

\n\n

\nExamples:
\n$B(10^9, 10^3, 10^3) = 23674718882$
\n$B(10^9, 10^3, 10^{15}) = 20731563854$\n

\n\n

Find $B(10^9, 10^7, 10^{15})$.

", "url": "https://projecteuler.net/problem=492", "answer": "242586962923928"} {"id": 493, "problem": "$70$ coloured balls are placed in an urn, $10$ for each of the seven rainbow colours.\n\nWhat is the expected number of distinct colours in $20$ randomly picked balls?\n\nGive your answer with nine digits after the decimal point (a.bcdefghij).", "raw_html": "

$70$ coloured balls are placed in an urn, $10$ for each of the seven rainbow colours.

\n

What is the expected number of distinct colours in $20$ randomly picked balls?

\n

Give your answer with nine digits after the decimal point (a.bcdefghij).

", "url": "https://projecteuler.net/problem=493", "answer": "6.818741802"} {"id": 494, "problem": "The Collatz sequence is defined as:\n$a_{i+1} = \\left\\{ \\large{\\frac {a_i} 2 \\atop 3 a_i+1} {\\text{if }a_i\\text{ is even} \\atop \\text{if }a_i\\text{ is odd}} \\right.$.\n\nThe Collatz conjecture states that starting from any positive integer, the sequence eventually reaches the cycle $1,4,2,1, \\dots$.\n\nWe shall define the sequence prefix $p(n)$ for the Collatz sequence starting with $a_1 = n$ as the sub-sequence of all numbers not a power of $2$ ($2^0=1$ is considered a power of $2$ for this problem). For example:\n$p(13) = \\{13, 40, 20, 10, 5\\}$\n$p(8) = \\{\\}$\n\nAny number invalidating the conjecture would have an infinite length sequence prefix.\n\nLet $S_m$ be the set of all sequence prefixes of length $m$. Two sequences $\\{a_1, a_2, \\dots, a_m\\}$ and $\\{b_1, b_2, \\dots, b_m\\}$ in $S_m$ are said to belong to the same prefix family if $a_i \\lt a_j$ if and only if $b_i \\lt b_j$ for all $1 \\le i,j \\le m$.\n\nFor example, in $S_4$, $\\{6, 3, 10, 5\\}$ is in the same family as $\\{454, 227, 682, 341\\}$, but not $\\{113, 340, 170, 85\\}$.\n\nLet $f(m)$ be the number of distinct prefix families in $S_m$.\n\nYou are given $f(5) = 5$, $f(10) = 55$, $f(20) = 6771$.\n\nFind $f(90)$.", "raw_html": "

\nThe Collatz sequence is defined as:\n$a_{i+1} = \\left\\{ \\large{\\frac {a_i} 2 \\atop 3 a_i+1} {\\text{if }a_i\\text{ is even} \\atop \\text{if }a_i\\text{ is odd}} \\right.$.\n

\n

\nThe Collatz conjecture states that starting from any positive integer, the sequence eventually reaches the cycle $1,4,2,1, \\dots$.
\nWe shall define the sequence prefix $p(n)$ for the Collatz sequence starting with $a_1 = n$ as the sub-sequence of all numbers not a power of $2$ ($2^0=1$ is considered a power of $2$ for this problem). For example:
$p(13) = \\{13, 40, 20, 10, 5\\}$
$p(8) = \\{\\}$
\nAny number invalidating the conjecture would have an infinite length sequence prefix.\n

\n

\nLet $S_m$ be the set of all sequence prefixes of length $m$. Two sequences $\\{a_1, a_2, \\dots, a_m\\}$ and $\\{b_1, b_2, \\dots, b_m\\}$ in $S_m$ are said to belong to the same prefix family if $a_i \\lt a_j$ if and only if $b_i \\lt b_j$ for all $1 \\le i,j \\le m$.\n

\n

\nFor example, in $S_4$, $\\{6, 3, 10, 5\\}$ is in the same family as $\\{454, 227, 682, 341\\}$, but not $\\{113, 340, 170, 85\\}$.
\nLet $f(m)$ be the number of distinct prefix families in $S_m$.
\nYou are given $f(5) = 5$, $f(10) = 55$, $f(20) = 6771$.\n

\n

\nFind $f(90)$.\n

", "url": "https://projecteuler.net/problem=494", "answer": "2880067194446832666"} {"id": 495, "problem": "Let $W(n,k)$ be the number of ways in which $n$ can be written as the product of $k$ distinct positive integers.\n\nFor example, $W(144,4) = 7$. There are $7$ ways in which $144$ can be written as a product of $4$ distinct positive integers:\n\n- $144 = 1 \\times 2 \\times 4 \\times 18$\n\n- $144 = 1 \\times 2 \\times 8 \\times 9$\n\n- $144 = 1 \\times 2 \\times 3 \\times 24$\n\n- $144 = 1 \\times 2 \\times 6 \\times 12$\n\n- $144 = 1 \\times 3 \\times 4 \\times 12$\n\n- $144 = 1 \\times 3 \\times 6 \\times 8$\n\n- $144 = 2 \\times 3 \\times 4 \\times 6$\n\nNote that permutations of the integers themselves are not considered distinct.\n\nFurthermore, $W(100!,10)$ modulo $1\\,000\\,000\\,007 = 287549200$.\n\nFind $W(10000!,30)$ modulo $1\\,000\\,000\\,007$.", "raw_html": "

Let $W(n,k)$ be the number of ways in which $n$ can be written as the product of $k$ distinct positive integers.

\n

For example, $W(144,4) = 7$. There are $7$ ways in which $144$ can be written as a product of $4$ distinct positive integers:

\n

  • $144 = 1 \\times 2 \\times 4 \\times 18$
  • \n
  • $144 = 1 \\times 2 \\times 8 \\times 9$
  • \n
  • $144 = 1 \\times 2 \\times 3 \\times 24$
  • \n
  • $144 = 1 \\times 2 \\times 6 \\times 12$
  • \n
  • $144 = 1 \\times 3 \\times 4 \\times 12$
  • \n
  • $144 = 1 \\times 3 \\times 6 \\times 8$
  • \n
  • $144 = 2 \\times 3 \\times 4 \\times 6$
  • \n

Note that permutations of the integers themselves are not considered distinct.

\n

Furthermore, $W(100!,10)$ modulo $1\\,000\\,000\\,007 = 287549200$.

\n

Find $W(10000!,30)$ modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=495", "answer": "789107601"} {"id": 496, "problem": "Given an integer sided triangle $ABC$:\n\nLet $I$ be the incenter of $ABC$.\n\nLet $D$ be the intersection between the line $AI$ and the circumcircle of $ABC$ ($A \\ne D$).\n\nWe define $F(L)$ as the sum of $BC$ for the triangles $ABC$ that satisfy $AC = DI$ and $BC \\le L$.\n\nFor example, $F(15) = 45$ because the triangles $ABC$ with $(BC,AC,AB) = (6,4,5), (12,8,10), (12,9,7), (15,9,16)$ satisfy the conditions.\n\nFind $F(10^9)$.", "raw_html": "

Given an integer sided triangle $ABC$:
\nLet $I$ be the incenter of $ABC$.
\nLet $D$ be the intersection between the line $AI$ and the circumcircle of $ABC$ ($A \\ne D$).

\n\n

We define $F(L)$ as the sum of $BC$ for the triangles $ABC$ that satisfy $AC = DI$ and $BC \\le L$.

\n\n

For example, $F(15) = 45$ because the triangles $ABC$ with $(BC,AC,AB) = (6,4,5), (12,8,10), (12,9,7), (15,9,16)$ satisfy the conditions.

\n\n

Find $F(10^9)$.

", "url": "https://projecteuler.net/problem=496", "answer": "2042473533769142717"} {"id": 497, "problem": "Bob is very familiar with the famous mathematical puzzle/game, \"Tower of Hanoi,\" which consists of three upright rods and disks of different sizes that can slide onto any of the rods. The game begins with a stack of $n$ disks placed on the leftmost rod in descending order by size. The objective of the game is to move all of the disks from the leftmost rod to the rightmost rod, given the following restrictions:\n\n- Only one disk can be moved at a time.\n\n- A valid move consists of taking the top disk from one stack and placing it onto another stack (or an empty rod).\n\n- No disk can be placed on top of a smaller disk.\n\nMoving on to a variant of this game, consider a long room $k$ units (square tiles) wide, labeled from $1$ to $k$ in ascending order. Three rods are placed at squares $a$, $b$, and $c$, and a stack of $n$ disks is placed on the rod at square $a$.\n\nBob begins the game standing at square $b$. His objective is to play the Tower of Hanoi game by moving all of the disks to the rod at square $c$. However, Bob can only pick up or set down a disk if he is on the same square as the rod/stack in question.\n\nUnfortunately, Bob is also drunk. On a given move, Bob will either stumble one square to the left or one square to the right with equal probability, unless Bob is at either end of the room, in which case he can only move in one direction. Despite Bob's inebriated state, he is still capable of following the rules of the game itself, as well as choosing when to pick up or put down a disk.\n\nThe following animation depicts a side-view of a sample game for $n = 3$, $k = 7$, $a = 2$, $b = 4$, and $c = 6$:\n\nLet $E(n, k, a, b, c)$ be the expected number of squares that Bob travels during a single optimally-played game. A game is played optimally if the number of disk-pickups is minimized.\n\nInterestingly enough, the result is always an integer. For example, $E(2,5,1,3,5) = 60$ and $E(3,20,4,9,17) = 2358$.\n\nFind the last nine digits of $\\sum_{1\\le n \\le 10000} E(n,10^n,3^n,6^n,9^n)$.", "raw_html": "

Bob is very familiar with the famous mathematical puzzle/game, \"Tower of Hanoi,\" which consists of three upright rods and disks of different sizes that can slide onto any of the rods. The game begins with a stack of $n$ disks placed on the leftmost rod in descending order by size. The objective of the game is to move all of the disks from the leftmost rod to the rightmost rod, given the following restrictions:

\n\n
  1. Only one disk can be moved at a time.
  2. \n
  3. A valid move consists of taking the top disk from one stack and placing it onto another stack (or an empty rod).
  4. \n
  5. No disk can be placed on top of a smaller disk.
  6. \n

Moving on to a variant of this game, consider a long room $k$ units (square tiles) wide, labeled from $1$ to $k$ in ascending order. Three rods are placed at squares $a$, $b$, and $c$, and a stack of $n$ disks is placed on the rod at square $a$.

\n\n

Bob begins the game standing at square $b$. His objective is to play the Tower of Hanoi game by moving all of the disks to the rod at square $c$. However, Bob can only pick up or set down a disk if he is on the same square as the rod/stack in question.

\n\n

Unfortunately, Bob is also drunk. On a given move, Bob will either stumble one square to the left or one square to the right with equal probability, unless Bob is at either end of the room, in which case he can only move in one direction. Despite Bob's inebriated state, he is still capable of following the rules of the game itself, as well as choosing when to pick up or put down a disk.

\n\n

The following animation depicts a side-view of a sample game for $n = 3$, $k = 7$, $a = 2$, $b = 4$, and $c = 6$:

\n\n

\"0497_hanoi.gif\"

\n\n

Let $E(n, k, a, b, c)$ be the expected number of squares that Bob travels during a single optimally-played game. A game is played optimally if the number of disk-pickups is minimized.

\n\n

Interestingly enough, the result is always an integer. For example, $E(2,5,1,3,5) = 60$ and $E(3,20,4,9,17) = 2358$.

\n\n

Find the last nine digits of $\\sum_{1\\le n \\le 10000} E(n,10^n,3^n,6^n,9^n)$.

", "url": "https://projecteuler.net/problem=497", "answer": "684901360"} {"id": 498, "problem": "For positive integers $n$ and $m$, we define two polynomials $F_n(x) = x^n$ and $G_m(x) = (x-1)^m$.\n\nWe also define a polynomial $R_{n,m}(x)$ as the remainder of the division of $F_n(x)$ by $G_m(x)$.\n\nFor example, $R_{6,3}(x) = 15x^2 - 24x + 10$.\n\nLet $C(n, m, d)$ be the absolute value of the coefficient of the $d$-th degree term of $R_{n,m}(x)$.\n\nWe can verify that $C(6, 3, 1) = 24$ and $C(100, 10, 4) = 227197811615775$.\n\nFind $C(10^{13}, 10^{12}, 10^4) \\bmod 999999937$.", "raw_html": "

For positive integers $n$ and $m$, we define two polynomials $F_n(x) = x^n$ and $G_m(x) = (x-1)^m$.
\nWe also define a polynomial $R_{n,m}(x)$ as the remainder of the division of $F_n(x)$ by $G_m(x)$.
\nFor example, $R_{6,3}(x) = 15x^2 - 24x + 10$.

\n\n

Let $C(n, m, d)$ be the absolute value of the coefficient of the $d$-th degree term of $R_{n,m}(x)$.
\nWe can verify that $C(6, 3, 1) = 24$ and $C(100, 10, 4) = 227197811615775$.

\n\n

Find $C(10^{13}, 10^{12}, 10^4) \\bmod 999999937$.

", "url": "https://projecteuler.net/problem=498", "answer": "472294837"} {"id": 499, "problem": "A gambler decides to participate in a special lottery. In this lottery the gambler plays a series of one or more games.\n\nEach 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.\n\nThe game ends if the gambler's fortune falls below $m$ pounds.\nLet $p_m(s)$ denote the probability that the gambler will never run out of money in this lottery given an initial fortune $s$ and the cost per game $m$.\n\nFor example $p_2(2) \\approx 0.2522$, $p_2(5) \\approx 0.6873$ and $p_6(10\\,000) \\approx 0.9952$ (note: $p_m(s) = 0$ for $s \\lt m$).\n\nFind $p_{15}(10^9)$ and give your answer rounded to $7$ decimal places behind the decimal point in the form 0.abcdefg.", "raw_html": "

A gambler decides to participate in a special lottery. In this lottery the gambler plays a series of one or more games.
\nEach 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.

\n\n

The game ends if the gambler's fortune falls below $m$ pounds.\nLet $p_m(s)$ denote the probability that the gambler will never run out of money in this lottery given an initial fortune $s$ and the cost per game $m$.
\nFor example $p_2(2) \\approx 0.2522$, $p_2(5) \\approx 0.6873$ and $p_6(10\\,000) \\approx 0.9952$ (note: $p_m(s) = 0$ for $s \\lt m$).

\n\n

Find $p_{15}(10^9)$ and give your answer rounded to $7$ decimal places behind the decimal point in the form 0.abcdefg.

", "url": "https://projecteuler.net/problem=499", "answer": "0.8660312"} {"id": 500, "problem": "The number of divisors of $120$ is $16$.\n\nIn fact $120$ is the smallest number having $16$ divisors.\n\nFind the smallest number with $2^{500500}$ divisors.\n\nGive your answer modulo $500500507$.", "raw_html": "

The number of divisors of $120$ is $16$.
\nIn fact $120$ is the smallest number having $16$ divisors.\n

\n

\nFind the smallest number with $2^{500500}$ divisors.
\nGive your answer modulo $500500507$.\n

", "url": "https://projecteuler.net/problem=500", "answer": "35407281"} {"id": 501, "problem": "The eight divisors of $24$ are $1, 2, 3, 4, 6, 8, 12$ and $24$.\nThe ten numbers not exceeding $100$ having exactly eight divisors are $24, 30, 40, 42, 54, 56, 66, 70, 78$ and $88$.\nLet $f(n)$ be the count of numbers not exceeding $n$ with exactly eight divisors.\n\nYou are given $f(100) = 10$, $f(1000) = 180$ and $f(10^6) = 224427$.\n\nFind $f(10^{12})$.", "raw_html": "

The eight divisors of $24$ are $1, 2, 3, 4, 6, 8, 12$ and $24$.\nThe ten numbers not exceeding $100$ having exactly eight divisors are $24, 30, 40, 42, 54, 56, 66, 70, 78$ and $88$.\nLet $f(n)$ be the count of numbers not exceeding $n$ with exactly eight divisors.
\nYou are given $f(100) = 10$, $f(1000) = 180$ and $f(10^6) = 224427$.
\nFind $f(10^{12})$.

", "url": "https://projecteuler.net/problem=501", "answer": "197912312715"} {"id": 502, "problem": "We define a block to be a rectangle with a height of $1$ and an integer-valued length. Let a castle be a configuration of stacked blocks.\n\nGiven a game grid that is $w$ units wide and $h$ units tall, a castle is generated according to the following rules:\n\n- Blocks can be placed on top of other blocks as long as nothing sticks out past the edges or hangs out over open space.\n\n- All blocks are aligned/snapped to the grid.\n\n- Any two neighboring blocks on the same row have at least one unit of space between them.\n\n- The bottom row is occupied by a block of length $w$.\n\n- The maximum achieved height of the entire castle is exactly $h$.\n\n- The castle is made from an even number of blocks.\n\nThe following is a sample castle for $w=8$ and $h=5$:\n\nLet $F(w,h)$ represent the number of valid castles, given grid parameters $w$ and $h$.\n\nFor example, $F(4,2) = 10$, $F(13,10) = 3729050610636$, $F(10,13) = 37959702514$, and $F(100,100) \\bmod 1\\,000\\,000\\,007 = 841913936$.\n\nFind $(F(10^{12},100) + F(10000,10000) + F(100,10^{12})) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

We define a block to be a rectangle with a height of $1$ and an integer-valued length. Let a castle be a configuration of stacked blocks.

\n\n

Given a game grid that is $w$ units wide and $h$ units tall, a castle is generated according to the following rules:

\n\n\n
  1. Blocks can be placed on top of other blocks as long as nothing sticks out past the edges or hangs out over open space.
  2. \n
  3. All blocks are aligned/snapped to the grid.
  4. \n
  5. Any two neighboring blocks on the same row have at least one unit of space between them.
  6. \n
  7. The bottom row is occupied by a block of length $w$.
  8. \n
  9. The maximum achieved height of the entire castle is exactly $h$.
  10. \n
  11. The castle is made from an even number of blocks.
  12. \n

The following is a sample castle for $w=8$ and $h=5$:

\n\n

\"0502_castles.png\"

\n\n

Let $F(w,h)$ represent the number of valid castles, given grid parameters $w$ and $h$.

\n\n

For example, $F(4,2) = 10$, $F(13,10) = 3729050610636$, $F(10,13) = 37959702514$, and $F(100,100) \\bmod 1\\,000\\,000\\,007 = 841913936$.

\n\n

Find $(F(10^{12},100) + F(10000,10000) + F(100,10^{12})) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=502", "answer": "749485217"} {"id": 503, "problem": "Alice is playing a game with $n$ cards numbered $1$ to $n$.\n\nA game consists of iterations of the following steps.\n\n(1) Alice picks one of the cards at random.\n\n(2) Alice cannot see the number on it. Instead, Bob, one of her friends, sees the number and tells Alice how many previously-seen numbers are bigger than the number which he is seeing.\n\n(3) Alice can end or continue the game. If she decides to end, the number becomes her score. If she decides to continue, the card is removed from the game and she returns to (1). If there is no card left, she is forced to end the game.\n\nLet $F(n)$ be Alice's expected score if she takes the optimized strategy to minimize her score.\n\nFor example, $F(3) = 5/3$. At the first iteration, she should continue the game. At the second iteration, she should end the game if Bob says that one previously-seen number is bigger than the number which he is seeing, otherwise she should continue the game.\n\nWe can also verify that $F(4) = 15/8$ and $F(10) \\approx 2.5579365079$.\n\nFind $F(10^6)$. Give your answer rounded to $10$ decimal places behind the decimal point.", "raw_html": "

Alice is playing a game with $n$ cards numbered $1$ to $n$.

\n\n

A game consists of iterations of the following steps.
\n(1) Alice picks one of the cards at random.
\n(2) Alice cannot see the number on it. Instead, Bob, one of her friends, sees the number and tells Alice how many previously-seen numbers are bigger than the number which he is seeing.
\n(3) Alice can end or continue the game. If she decides to end, the number becomes her score. If she decides to continue, the card is removed from the game and she returns to (1). If there is no card left, she is forced to end the game.

\n\n

Let $F(n)$ be Alice's expected score if she takes the optimized strategy to minimize her score.

\n\n

For example, $F(3) = 5/3$. At the first iteration, she should continue the game. At the second iteration, she should end the game if Bob says that one previously-seen number is bigger than the number which he is seeing, otherwise she should continue the game.

\n\n

We can also verify that $F(4) = 15/8$ and $F(10) \\approx 2.5579365079$.

\n\n

Find $F(10^6)$. Give your answer rounded to $10$ decimal places behind the decimal point.

", "url": "https://projecteuler.net/problem=503", "answer": "3.8694550145"} {"id": 504, "problem": "Let $ABCD$ be a quadrilateral whose vertices are lattice points lying on the coordinate axes as follows:\n\n$A(a, 0)$, $B(0, b)$, $C(-c, 0)$, $D(0, -d)$, where $1 \\le a, b, c, d \\le m$ and $a, b, c, d, m$ are integers.\n\nIt can be shown that for $m = 4$ there are exactly $256$ valid ways to construct $ABCD$. Of these $256$ quadrilaterals, $42$ of them strictly contain a square number of lattice points.\n\nHow many quadrilaterals $ABCD$ strictly contain a square number of lattice points for $m = 100$?", "raw_html": "

Let $ABCD$ be a quadrilateral whose vertices are lattice points lying on the coordinate axes as follows:

\n\n

$A(a, 0)$, $B(0, b)$, $C(-c, 0)$, $D(0, -d)$, where $1 \\le a, b, c, d \\le m$ and $a, b, c, d, m$ are integers.

\n\n

It can be shown that for $m = 4$ there are exactly $256$ valid ways to construct $ABCD$. Of these $256$ quadrilaterals, $42$ of them strictly contain a square number of lattice points.

\n\n

How many quadrilaterals $ABCD$ strictly contain a square number of lattice points for $m = 100$?

", "url": "https://projecteuler.net/problem=504", "answer": "694687"} {"id": 505, "problem": "Let:\n\n$\\begin{array}{ll} x(0)&=0 \\\\ x(1)&=1 \\\\ x(2k)&=(3x(k)+2x(\\lfloor \\frac k 2 \\rfloor)) \\text{ mod } 2^{60} \\text{ for } k \\ge 1 \\text {, where } \\lfloor \\text { } \\rfloor \\text { is the floor function} \\\\ x(2k+1)&=(2x(k)+3x(\\lfloor \\frac k 2 \\rfloor)) \\text{ mod } 2^{60} \\text{ for } k \\ge 1 \\\\ y_n(k)&=\\left\\{{\\begin{array}{lc} x(k) && \\text{if } k \\ge n \\\\ 2^{60} - 1 - max(y_n(2k),y_n(2k+1)) && \\text{if } k < n \\end{array}} \\right. \\\\ A(n)&=y_n(1) \\end{array}$\n\nYou are given:\n\n$\\begin{array}{ll} x(2)&=3 \\\\ x(3)&=2 \\\\ x(4)&=11 \\\\ y_4(4)&=11 \\\\ y_4(3)&=2^{60}-9\\\\ y_4(2)&=2^{60}-12 \\\\ y_4(1)&=A(4)=8 \\\\ A(10)&=2^{60}-34\\\\ A(10^3)&=101881 \\end{array}$\n\nFind $A(10^{12})$.", "raw_html": "

Let:

\n

$\\begin{array}{ll} x(0)&=0 \\\\ x(1)&=1 \\\\ x(2k)&=(3x(k)+2x(\\lfloor \\frac k 2 \\rfloor)) \\text{ mod } 2^{60} \\text{ for } k \\ge 1 \\text {, where } \\lfloor \\text { } \\rfloor \\text { is the floor function} \\\\ x(2k+1)&=(2x(k)+3x(\\lfloor \\frac k 2 \\rfloor)) \\text{ mod } 2^{60} \\text{ for } k \\ge 1 \\\\ y_n(k)&=\\left\\{{\\begin{array}{lc} x(k) && \\text{if } k \\ge n \\\\ 2^{60} - 1 - max(y_n(2k),y_n(2k+1)) && \\text{if } k < n \\end{array}} \\right. \\\\ A(n)&=y_n(1) \\end{array}$

\n

You are given:

\n

$\\begin{array}{ll} x(2)&=3 \\\\ x(3)&=2 \\\\ x(4)&=11 \\\\ y_4(4)&=11 \\\\ y_4(3)&=2^{60}-9\\\\ y_4(2)&=2^{60}-12 \\\\ y_4(1)&=A(4)=8 \\\\ A(10)&=2^{60}-34\\\\ A(10^3)&=101881 \\end{array}$

\nFind $A(10^{12})$.", "url": "https://projecteuler.net/problem=505", "answer": "714591308667615832"} {"id": 506, "problem": "Consider the infinite repeating sequence of digits:\n\n1234321234321234321...\n\nAmazingly, you can break this sequence of digits into a sequence of integers such that the sum of the digits in the $n$-th value is $n$.\n\nThe sequence goes as follows:\n\n1, 2, 3, 4, 32, 123, 43, 2123, 432, 1234, 32123, ...\n\nLet $v_n$ be the $n$-th value in this sequence. For example, $v_2=2$, $v_5=32$ and $v_{11}=32123$.\n\nLet $S(n)$ be $v_1+v_2+\\cdots+v_n$. For example, $S(11)=36120$, and $S(1000)\\bmod 123454321=18232686$.\n\nFind $S(10^{14})\\bmod 123454321$.", "raw_html": "

Consider the infinite repeating sequence of digits:
\n1234321234321234321...

\n

Amazingly, you can break this sequence of digits into a sequence of integers such that the sum of the digits in the $n$-th value is $n$.

\n

The sequence goes as follows:
\n1, 2, 3, 4, 32, 123, 43, 2123, 432, 1234, 32123, ...

\n

Let $v_n$ be the $n$-th value in this sequence. For example, $v_2=2$, $v_5=32$ and $v_{11}=32123$.

\n

Let $S(n)$ be $v_1+v_2+\\cdots+v_n$. For example, $S(11)=36120$, and $S(1000)\\bmod 123454321=18232686$.

\n

Find $S(10^{14})\\bmod 123454321$.

", "url": "https://projecteuler.net/problem=506", "answer": "18934502"} {"id": 507, "problem": "Let $t_n$ be the tribonacci numbers defined as:\n\n$t_0 = t_1 = 0$;\n\n$t_2 = 1$;\n\n$t_n = t_{n-1} + t_{n-2} + t_{n-3}$ for $n \\ge 3$\n\nand let $r_n = t_n \\text{ mod } 10^7$.\n\nFor each pair of Vectors $V_n=(v_1,v_2,v_3)$ and $W_n=(w_1,w_2,w_3)$ with $v_1=r_{12n-11}-r_{12n-10}, v_2=r_{12n-9}+r_{12n-8}, v_3=r_{12n-7} \\cdot r_{12n-6}$ and\n$w_1=r_{12n-5}-r_{12n-4}, w_2=r_{12n-3}+r_{12n-2}, w_3=r_{12n-1} \\cdot r_{12n}$\n\nwe define $S(n)$ as the minimal value of the manhattan length of the vector $D=k \\cdot V_n+l \\cdot W_n$ measured as $|k \\cdot v_1+l \\cdot w_1|+|k \\cdot v_2+l \\cdot w_2|+|k \\cdot v_3+l \\cdot w_3|$\nfor any integers $k$ and $l$ with $(k,l)\\neq (0,0)$.\n\nThe first vector pair is $(-1, 3, 28)$, $(-11, 125, 40826)$.\n\nYou are given that $S(1)=32$ and $\\sum_{n=1}^{10} S(n)=130762273722$.\n\nFind $\\sum_{n=1}^{20000000} S(n)$.", "raw_html": "

\nLet $t_n$ be the tribonacci numbers defined as:
\n$t_0 = t_1 = 0$;
\n$t_2 = 1$;
\n$t_n = t_{n-1} + t_{n-2} + t_{n-3}$ for $n \\ge 3$
\nand let $r_n = t_n \\text{ mod } 10^7$.\n

\n

\nFor each pair of Vectors $V_n=(v_1,v_2,v_3)$ and $W_n=(w_1,w_2,w_3)$ with $v_1=r_{12n-11}-r_{12n-10}, v_2=r_{12n-9}+r_{12n-8}, v_3=r_{12n-7} \\cdot r_{12n-6}$ and
$w_1=r_{12n-5}-r_{12n-4}, w_2=r_{12n-3}+r_{12n-2}, w_3=r_{12n-1} \\cdot r_{12n}$\n
\n\nwe define $S(n)$ as the minimal value of the manhattan length of the vector $D=k \\cdot V_n+l \\cdot W_n$ measured as $|k \\cdot v_1+l \\cdot w_1|+|k \\cdot v_2+l \\cdot w_2|+|k \\cdot v_3+l \\cdot w_3|$\n for any integers $k$ and $l$ with $(k,l)\\neq (0,0)$.\n

\nThe first vector pair is $(-1, 3, 28)$, $(-11, 125, 40826)$.
\nYou are given that $S(1)=32$ and $\\sum_{n=1}^{10} S(n)=130762273722$.\n

\n

\nFind $\\sum_{n=1}^{20000000} S(n)$.\n

", "url": "https://projecteuler.net/problem=507", "answer": "316558047002627270"} {"id": 508, "problem": "Consider the Gaussian integer $i-1$. A base $i-1$ representation of a Gaussian integer $a+bi$ is a finite sequence of digits $d_{n - 1}d_{n - 2}\\cdots d_1 d_0$ such that:\n\n- $a+bi = d_{n - 1}(i - 1)^{n - 1} + d_{n - 2}(i - 1)^{n - 2} + \\cdots + d_1(i - 1) + d_0$\n\n- Each $d_k$ is in $\\{0,1\\}$\n\n- There are no leading zeroes, i.e. $d_{n-1} \\ne 0$, unless $a+bi$ is itself $0$\n\nHere are base $i-1$ representations of a few Gaussian integers:\n\n$11+24i \\to 111010110001101$\n\n$24-11i \\to 110010110011$\n\n$8+0i \\to 111000000$\n\n$-5+0i \\to 11001101$\n\n$0+0i \\to 0$\n\nRemarkably, every Gaussian integer has a unique base $i-1$ representation!\n\nDefine $f(a + bi)$ as the number of $1$s in the unique base $i-1$ representation of $a + bi$. For example, $f(11+24i) = 9$ and $f(24-11i) = 7$.\n\nDefine $B(L)$ as the sum of $f(a + bi)$ for all integers $a, b$ such that $|a| \\le L$ and $|b| \\le L$. For example, $B(500) = 10795060$.\n\nFind $B(10^{15}) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Consider the Gaussian integer $i-1$. A base $i-1$ representation of a Gaussian integer $a+bi$ is a finite sequence of digits $d_{n - 1}d_{n - 2}\\cdots d_1 d_0$ such that:

\n\n
  • $a+bi = d_{n - 1}(i - 1)^{n - 1} + d_{n - 2}(i - 1)^{n - 2} + \\cdots + d_1(i - 1) + d_0$
  • \n
  • Each $d_k$ is in $\\{0,1\\}$
  • \n
  • There are no leading zeroes, i.e. $d_{n-1} \\ne 0$, unless $a+bi$ is itself $0$
  • \n

Here are base $i-1$ representations of a few Gaussian integers:

\n$11+24i \\to 111010110001101$
\n$24-11i \\to 110010110011$
\n$8+0i \\to 111000000$
\n$-5+0i \\to 11001101$
\n$0+0i \\to 0$

\n\n

\nRemarkably, every Gaussian integer has a unique base $i-1$ representation!

\n\n

\nDefine $f(a + bi)$ as the number of $1$s in the unique base $i-1$ representation of $a + bi$. For example, $f(11+24i) = 9$ and $f(24-11i) = 7$.

\n\n

\nDefine $B(L)$ as the sum of $f(a + bi)$ for all integers $a, b$ such that $|a| \\le L$ and $|b| \\le L$. For example, $B(500) = 10795060$.

\n\n

\nFind $B(10^{15}) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=508", "answer": "891874596"} {"id": 509, "problem": "Anton and Bertrand love to play three pile Nim.\n\nHowever, after a lot of games of Nim they got bored and changed the rules somewhat.\n\nThey may only take a number of stones from a pile that is a proper divisora proper divisor of $n$ is a divisor of $n$ smaller than $n$ of the number of stones present in the pile.\nE.g. if a pile at a certain moment contains $24$ stones they may take only $1,2,3,4,6,8$ or $12$ stones from that pile.\n\nSo if a pile contains one stone they can't take the last stone from it as $1$ isn't a proper divisor of $1$.\n\nThe first player that can't make a valid move loses the game.\n\nOf course both Anton and Bertrand play optimally.\n\nThe triple $(a, b, c)$ indicates the number of stones in the three piles.\n\nLet $S(n)$ be the number of winning positions for the next player for $1 \\le a, b, c \\le n$.\n$S(10) = 692$ and $S(100) = 735494$.\n\nFind $S(123456787654321)$ modulo $1234567890$.", "raw_html": "

\nAnton and Bertrand love to play three pile Nim.
\nHowever, after a lot of games of Nim they got bored and changed the rules somewhat.
\nThey may only take a number of stones from a pile that is a proper divisora proper divisor of $n$ is a divisor of $n$ smaller than $n$ of the number of stones present in the pile.
E.g. if a pile at a certain moment contains $24$ stones they may take only $1,2,3,4,6,8$ or $12$ stones from that pile.
\nSo if a pile contains one stone they can't take the last stone from it as $1$ isn't a proper divisor of $1$.
\nThe first player that can't make a valid move loses the game.
\nOf course both Anton and Bertrand play optimally.

\n

\nThe triple $(a, b, c)$ indicates the number of stones in the three piles.
\nLet $S(n)$ be the number of winning positions for the next player for $1 \\le a, b, c \\le n$.
$S(10) = 692$ and $S(100) = 735494$.

\n

\nFind $S(123456787654321)$ modulo $1234567890$.\n

", "url": "https://projecteuler.net/problem=509", "answer": "151725678"} {"id": 510, "problem": "Circles $A$ and $B$ are tangent to each other and to line $L$ at three distinct points.\n\nCircle $C$ is inside the space between $A$, $B$ and $L$, and tangent to all three.\n\nLet $r_A$, $r_B$ and $r_C$ be the radii of $A$, $B$ and $C$ respectively.\n\nLet $S(n) = \\sum r_A + r_B + r_C$, for $0 \\lt r_A \\le r_B \\le n$ where $r_A$, $r_B$ and $r_C$ are integers.\nThe only solution for $0 \\lt r_A \\le r_B \\le 5$ is $r_A = 4$, $r_B = 4$ and $r_C = 1$, so $S(5) = 4 + 4 + 1 = 9$.\nYou are also given $S(100) = 3072$.\n\nFind $S(10^9)$.", "raw_html": "

Circles $A$ and $B$ are tangent to each other and to line $L$ at three distinct points.
\nCircle $C$ is inside the space between $A$, $B$ and $L$, and tangent to all three.
\nLet $r_A$, $r_B$ and $r_C$ be the radii of $A$, $B$ and $C$ respectively.

\"0510_tangent_circles.png\"
\n

Let $S(n) = \\sum r_A + r_B + r_C$, for $0 \\lt r_A \\le r_B \\le n$ where $r_A$, $r_B$ and $r_C$ are integers.\nThe only solution for $0 \\lt r_A \\le r_B \\le 5$ is $r_A = 4$, $r_B = 4$ and $r_C = 1$, so $S(5) = 4 + 4 + 1 = 9$.\nYou are also given $S(100) = 3072$.

\n

Find $S(10^9)$.

", "url": "https://projecteuler.net/problem=510", "answer": "315306518862563689"} {"id": 511, "problem": "Let $Seq(n,k)$ be the number of positive-integer sequences $\\{a_i\\}_{1 \\le i \\le n}$ of length $n$ such that:\n\n- $n$ is divisible by $a_i$ for $1 \\le i \\le n$, and\n\n- $n + a_1 + a_2 + \\cdots + a_n$ is divisible by $k$.\n\nExamples:\n\n$Seq(3,4) = 4$, and the $4$ sequences are:\n\n$\\{1, 1, 3\\}$\n\n$\\{1, 3, 1\\}$\n\n$\\{3, 1, 1\\}$\n\n$\\{3, 3, 3\\}$\n\n$Seq(4,11) = 8$, and the $8$ sequences are:\n\n$\\{1, 1, 1, 4\\}$\n\n$\\{1, 1, 4, 1\\}$\n\n$\\{1, 4, 1, 1\\}$\n\n$\\{4, 1, 1, 1\\}$\n\n$\\{2, 2, 2, 1\\}$\n\n$\\{2, 2, 1, 2\\}$\n\n$\\{2, 1, 2, 2\\}$\n\n$\\{1, 2, 2, 2\\}$\n\nThe last nine digits of $Seq(1111,24)$ are $840643584$.\n\nFind the last nine digits of $Seq(1234567898765,4321)$.", "raw_html": "

Let $Seq(n,k)$ be the number of positive-integer sequences $\\{a_i\\}_{1 \\le i \\le n}$ of length $n$ such that:

\n
  • $n$ is divisible by $a_i$ for $1 \\le i \\le n$, and
  • \n
  • $n + a_1 + a_2 + \\cdots + a_n$ is divisible by $k$.
  • \n

Examples:

\n

$Seq(3,4) = 4$, and the $4$ sequences are:
\n$\\{1, 1, 3\\}$
\n$\\{1, 3, 1\\}$
\n$\\{3, 1, 1\\}$
\n$\\{3, 3, 3\\}$

\n

$Seq(4,11) = 8$, and the $8$ sequences are:
\n$\\{1, 1, 1, 4\\}$
\n$\\{1, 1, 4, 1\\}$
\n$\\{1, 4, 1, 1\\}$
\n$\\{4, 1, 1, 1\\}$
\n$\\{2, 2, 2, 1\\}$
\n$\\{2, 2, 1, 2\\}$
\n$\\{2, 1, 2, 2\\}$
\n$\\{1, 2, 2, 2\\}$

\n

The last nine digits of $Seq(1111,24)$ are $840643584$.

\n

Find the last nine digits of $Seq(1234567898765,4321)$.

", "url": "https://projecteuler.net/problem=511", "answer": "935247012"} {"id": 512, "problem": "Let $\\varphi(n)$ be Euler's totient function.\n\nLet $f(n)=(\\sum_{i=1}^{n}\\varphi(n^i)) \\bmod (n+1)$.\n\nLet $g(n)=\\sum_{i=1}^{n} f(i)$.\n\n$g(100)=2007$.\n\nFind $g(5 \\times 10^8)$.", "raw_html": "

Let $\\varphi(n)$ be Euler's totient function.

\nLet $f(n)=(\\sum_{i=1}^{n}\\varphi(n^i)) \\bmod (n+1)$.

\nLet $g(n)=\\sum_{i=1}^{n} f(i)$.

\n$g(100)=2007$.\n

\n

\nFind $g(5 \\times 10^8)$.\n

", "url": "https://projecteuler.net/problem=512", "answer": "50660591862310323"} {"id": 513, "problem": "$ABC$ is an integral sided triangle with sides $a \\le b \\le c$.\n\n$m_C$ is the median connecting $C$ and the midpoint of $AB$.\n\n$F(n)$ is the number of such triangles with $c \\le n$ for which $m_C$ has integral length as well.\n\n$F(10)=3$ and $F(50)=165$.\n\nFind $F(100000)$.", "raw_html": "

\n$ABC$ is an integral sided triangle with sides $a \\le b \\le c$.
\n$m_C$ is the median connecting $C$ and the midpoint of $AB$.
\n$F(n)$ is the number of such triangles with $c \\le n$ for which $m_C$ has integral length as well.
\n$F(10)=3$ and $F(50)=165$.

\n

\nFind $F(100000)$.\n

", "url": "https://projecteuler.net/problem=513", "answer": "2925619196"} {"id": 514, "problem": "A geoboard (of order $N$) is a square board with equally-spaced pins protruding from the surface, representing an integer point lattice for coordinates $0 \\le x, y \\le N$.\n\nJohn begins with a pinless geoboard. Each position on the board is a hole that can be filled with a pin. John decides to generate a random integer between $1$ and $N+1$ (inclusive) for each hole in the geoboard. If the random integer is equal to $1$ for a given hole, then a pin is placed in that hole.\n\nAfter John is finished generating numbers for all $(N+1)^2$ holes and placing any/all corresponding pins, he wraps a tight rubberband around the entire group of pins protruding from the board. Let $S$ represent the shape that is formed. $S$ can also be defined as the smallest convex shape that contains all the pins.\n\nThe above image depicts a sample layout for $N = 4$. The green markers indicate positions where pins have been placed, and the blue lines collectively represent the rubberband. For this particular arrangement, $S$ has an area of $6$. If there are fewer than three pins on the board (or if all pins are collinear), $S$ can be assumed to have zero area.\n\nLet $E(N)$ be the expected area of $S$ given a geoboard of order $N$. For example, $E(1) = 0.18750$, $E(2) = 0.94335$, and $E(10) = 55.03013$ when rounded to five decimal places each.\n\nCalculate $E(100)$ rounded to five decimal places.", "raw_html": "

A geoboard (of order $N$) is a square board with equally-spaced pins protruding from the surface, representing an integer point lattice for coordinates $0 \\le x, y \\le N$.

\n\n

John begins with a pinless geoboard. Each position on the board is a hole that can be filled with a pin. John decides to generate a random integer between $1$ and $N+1$ (inclusive) for each hole in the geoboard. If the random integer is equal to $1$ for a given hole, then a pin is placed in that hole.

\n\n

After John is finished generating numbers for all $(N+1)^2$ holes and placing any/all corresponding pins, he wraps a tight rubberband around the entire group of pins protruding from the board. Let $S$ represent the shape that is formed. $S$ can also be defined as the smallest convex shape that contains all the pins.

\n\n
\"0514_geoboard.png\"
\n\n

The above image depicts a sample layout for $N = 4$. The green markers indicate positions where pins have been placed, and the blue lines collectively represent the rubberband. For this particular arrangement, $S$ has an area of $6$. If there are fewer than three pins on the board (or if all pins are collinear), $S$ can be assumed to have zero area.

\n\n

Let $E(N)$ be the expected area of $S$ given a geoboard of order $N$. For example, $E(1) = 0.18750$, $E(2) = 0.94335$, and $E(10) = 55.03013$ when rounded to five decimal places each.

\n\n

Calculate $E(100)$ rounded to five decimal places.

", "url": "https://projecteuler.net/problem=514", "answer": "8986.86698"} {"id": 515, "problem": "Let $d(p, n, 0)$ be the multiplicative inverse of $n$ modulo prime $p$, defined as $n \\times d(p, n, 0) = 1 \\bmod p$.\n\nLet $d(p, n, k) = \\sum_{i = 1}^n d(p, i, k - 1)$ for $k \\ge 1$.\n\nLet $D(a, b, k) = \\sum (d(p, p-1, k) \\bmod p)$ for all primes $a \\le p \\lt a + b$.\n\nYou are given:\n\n- $D(101,1,10) = 45$\n\n- $D(10^3,10^2,10^2) = 8334$\n\n- $D(10^6,10^3,10^3) = 38162302$\n\nFind $D(10^9,10^5,10^5)$.", "raw_html": "

Let $d(p, n, 0)$ be the multiplicative inverse of $n$ modulo prime $p$, defined as $n \\times d(p, n, 0) = 1 \\bmod p$.
\nLet $d(p, n, k) = \\sum_{i = 1}^n d(p, i, k - 1)$ for $k \\ge 1$.
\nLet $D(a, b, k) = \\sum (d(p, p-1, k) \\bmod p)$ for all primes $a \\le p \\lt a + b$.

\n

You are given:

\n
  • $D(101,1,10) = 45$
  • \n
  • $D(10^3,10^2,10^2) = 8334$
  • \n
  • $D(10^6,10^3,10^3) = 38162302$

Find $D(10^9,10^5,10^5)$.

", "url": "https://projecteuler.net/problem=515", "answer": "2422639000800"} {"id": 516, "problem": "$5$-smooth numbers are numbers whose largest prime factor doesn't exceed $5$.\n\n$5$-smooth numbers are also called Hamming numbers.\n\nLet $S(L)$ be the sum of the numbers $n$ not exceeding $L$ such that Euler's totient function $\\phi(n)$ is a Hamming number.\n\n$S(100)=3728$.\n\nFind $S(10^{12})$. Give your answer modulo $2^{32}$.", "raw_html": "

\n$5$-smooth numbers are numbers whose largest prime factor doesn't exceed $5$.
\n$5$-smooth numbers are also called Hamming numbers.
\nLet $S(L)$ be the sum of the numbers $n$ not exceeding $L$ such that Euler's totient function $\\phi(n)$ is a Hamming number.
\n$S(100)=3728$.\n

\n

\nFind $S(10^{12})$. Give your answer modulo $2^{32}$.\n

", "url": "https://projecteuler.net/problem=516", "answer": "939087315"} {"id": 517, "problem": "For every real number $a \\gt 1$ is given the sequence $g_a$ by:\n\n$g_{a}(x)=1$ for $x \\lt a$\n\n$g_{a}(x)=g_{a}(x-1)+g_a(x-a)$ for $x \\ge a$\n\n$G(n)=g_{\\sqrt {n}}(n)$\n\n$G(90)=7564511$.\n\nFind $\\sum G(p)$ for $p$ prime and $10000000 \\lt p \\lt 10010000$\n\nGive your answer modulo $1000000007$.", "raw_html": "

\nFor every real number $a \\gt 1$ is given the sequence $g_a$ by:
\n$g_{a}(x)=1$ for $x \\lt a$
\n$g_{a}(x)=g_{a}(x-1)+g_a(x-a)$ for $x \\ge a$
\n\n$G(n)=g_{\\sqrt {n}}(n)$
\n$G(90)=7564511$.

\n

\nFind $\\sum G(p)$ for $p$ prime and $10000000 \\lt p \\lt 10010000$
\nGive your answer modulo $1000000007$.\n

", "url": "https://projecteuler.net/problem=517", "answer": "581468882"} {"id": 518, "problem": "Let $S(n) = \\sum a + b + c$ over all triples $(a, b, c)$ such that:\n\n- $a$, $b$ and $c$ are prime numbers.\n\n- $a \\lt b \\lt c \\lt n$.\n\n- $a+1$, $b+1$, and $c+1$ form a geometric sequence.\n\nFor example, $S(100) = 1035$ with the following triples:\n\n$(2, 5, 11)$, $(2, 11, 47)$, $(5, 11, 23)$, $(5, 17, 53)$, $(7, 11, 17)$, $(7, 23, 71)$, $(11, 23, 47)$, $(17, 23, 31)$, $(17, 41, 97)$, $(31, 47, 71)$, $(71, 83, 97)$\n\nFind $S(10^8)$.", "raw_html": "

Let $S(n) = \\sum a + b + c$ over all triples $(a, b, c)$ such that:

\n\n
  • $a$, $b$ and $c$ are prime numbers.
  • \n
  • $a \\lt b \\lt c \\lt n$.
  • \n
  • $a+1$, $b+1$, and $c+1$ form a geometric sequence.
  • \n

For example, $S(100) = 1035$ with the following triples:

\n\n

$(2, 5, 11)$, $(2, 11, 47)$, $(5, 11, 23)$, $(5, 17, 53)$, $(7, 11, 17)$, $(7, 23, 71)$, $(11, 23, 47)$, $(17, 23, 31)$, $(17, 41, 97)$, $(31, 47, 71)$, $(71, 83, 97)$

\n\n

Find $S(10^8)$.

", "url": "https://projecteuler.net/problem=518", "answer": "100315739184392"} {"id": 519, "problem": "An arrangement of coins in one or more rows with the bottom row being a block without gaps and every coin in a higher row touching exactly two coins in the row below is called a fountain of coins. Let $f(n)$ be the number of possible fountains with $n$ coins. For $4$ coins there are three possible arrangements:\n\nTherefore $f(4) = 3$ while $f(10) = 78$.\n\nLet $T(n)$ be the number of all possible colourings with three colours for all $f(n)$ different fountains with $n$ coins, given the condition that no two touching coins have the same colour. Below you see the possible colourings for one of the three valid fountains for $4$ coins:\n\nYou are given that $T(4) = 48$ and $T(10) = 17760$.\n\nFind the last $9$ digits of $T(20000)$.", "raw_html": "

An arrangement of coins in one or more rows with the bottom row being a block without gaps and every coin in a higher row touching exactly two coins in the row below is called a fountain of coins. Let $f(n)$ be the number of possible fountains with $n$ coins. For $4$ coins there are three possible arrangements:

\n
\"0519_coin_fountain.png\"
\n

Therefore $f(4) = 3$ while $f(10) = 78$.

\n

Let $T(n)$ be the number of all possible colourings with three colours for all $f(n)$ different fountains with $n$ coins, given the condition that no two touching coins have the same colour. Below you see the possible colourings for one of the three valid fountains for $4$ coins:

\n
\"0519_tricolored_coin_fountain.png\"
\n

You are given that $T(4) = 48$ and $T(10) = 17760$.

\n

Find the last $9$ digits of $T(20000)$.

", "url": "https://projecteuler.net/problem=519", "answer": "804739330"} {"id": 520, "problem": "We define a simber to be a positive integer in which any odd digit, if present, occurs an odd number of times, and any even digit, if present, occurs an even number of times.\n\nFor example, $141221242$ is a $9$-digit simber because it has three $1$'s, four $2$'s and two $4$'s.\n\nLet $Q(n)$ be the count of all simbers with at most $n$ digits.\n\n\n\nYou are given $Q(7) = 287975$ and $Q(100) \\bmod 1\\,000\\,000\\,123 = 123864868$.\n\nFind $(\\sum_{1 \\le u \\le 39} Q(2^u)) \\bmod 1\\,000\\,000\\,123$.", "raw_html": "

We define a simber to be a positive integer in which any odd digit, if present, occurs an odd number of times, and any even digit, if present, occurs an even number of times.

\n\n

For example, $141221242$ is a $9$-digit simber because it has three $1$'s, four $2$'s and two $4$'s.

\n\n

Let $Q(n)$ be the count of all simbers with at most $n$ digits.

\n\n

You are given $Q(7) = 287975$ and $Q(100) \\bmod 1\\,000\\,000\\,123 = 123864868$.

\n\n

Find $(\\sum_{1 \\le u \\le 39} Q(2^u)) \\bmod 1\\,000\\,000\\,123$.

", "url": "https://projecteuler.net/problem=520", "answer": "238413705"} {"id": 521, "problem": "Let $\\operatorname{smpf}(n)$ be the smallest prime factor of $n$.\n\n$\\operatorname{smpf}(91)=7$ because $91=7\\times 13$ and $\\operatorname{smpf}(45)=3$ because $45=3\\times 3\\times 5$.\n\nLet $S(n)$ be the sum of $\\operatorname{smpf}(i)$ for $2 \\le i \\le n$.\n\nE.g. $S(100)=1257$.\n\nFind $S(10^{12}) \\bmod 10^9$.", "raw_html": "

\nLet $\\operatorname{smpf}(n)$ be the smallest prime factor of $n$.
\n$\\operatorname{smpf}(91)=7$ because $91=7\\times 13$ and $\\operatorname{smpf}(45)=3$ because $45=3\\times 3\\times 5$.
\nLet $S(n)$ be the sum of $\\operatorname{smpf}(i)$ for $2 \\le i \\le n$.
\nE.g. $S(100)=1257$.\n

\n\n

\nFind $S(10^{12}) \\bmod 10^9$.\n

", "url": "https://projecteuler.net/problem=521", "answer": "44389811"} {"id": 522, "problem": "Despite the popularity of Hilbert's infinite hotel, Hilbert decided to try managing extremely large finite hotels, instead.\n\n\n\nTo cut costs, Hilbert wished to power the new hotel with his own special generator. Each floor would send power to the floor above it, with the top floor sending power back down to the bottom floor. That way, Hilbert could have the generator placed on any given floor (as he likes having the option) and have electricity flow freely throughout the entire hotel.\n\nUnfortunately, the contractors misinterpreted the schematics when they built the hotel. They informed Hilbert that each floor sends power to another floor at random, instead. This may compromise Hilbert's freedom to have the generator placed anywhere, since blackouts could occur on certain floors.\n\nFor example, consider a sample flow diagram for a three-story hotel:\n\nIf the generator were placed on the first floor, then every floor would receive power. But if it were placed on the second or third floors instead, then there would be a blackout on the first floor. Note that while a given floor can receive power from many other floors at once, it can only send power to one other floor.\n\nTo resolve the blackout concerns, Hilbert decided to have a minimal number of floors rewired. To rewire a floor is to change the floor it sends power to. In the sample diagram above, all possible blackouts can be avoided by rewiring the second floor to send power to the first floor instead of the third floor.\n\nLet $F(n)$ be the sum of the minimum number of floor rewirings needed over all possible power-flow arrangements in a hotel of $n$ floors. For example, $F(3) = 6$, $F(8) = 16276736$, and $F(100) \\bmod 135707531 = 84326147$.\n\nFind $F(12344321) \\bmod 135707531$.", "raw_html": "

Despite the popularity of Hilbert's infinite hotel, Hilbert decided to try managing extremely large finite hotels, instead.

\n\n

To cut costs, Hilbert wished to power the new hotel with his own special generator. Each floor would send power to the floor above it, with the top floor sending power back down to the bottom floor. That way, Hilbert could have the generator placed on any given floor (as he likes having the option) and have electricity flow freely throughout the entire hotel.

\n\n

Unfortunately, the contractors misinterpreted the schematics when they built the hotel. They informed Hilbert that each floor sends power to another floor at random, instead. This may compromise Hilbert's freedom to have the generator placed anywhere, since blackouts could occur on certain floors.

\n\n

For example, consider a sample flow diagram for a three-story hotel:

\n\n

\"0522_hilberts_blackout.png\"

\n\n

If the generator were placed on the first floor, then every floor would receive power. But if it were placed on the second or third floors instead, then there would be a blackout on the first floor. Note that while a given floor can receive power from many other floors at once, it can only send power to one other floor.

\n\n

To resolve the blackout concerns, Hilbert decided to have a minimal number of floors rewired. To rewire a floor is to change the floor it sends power to. In the sample diagram above, all possible blackouts can be avoided by rewiring the second floor to send power to the first floor instead of the third floor.

\n\n

Let $F(n)$ be the sum of the minimum number of floor rewirings needed over all possible power-flow arrangements in a hotel of $n$ floors. For example, $F(3) = 6$, $F(8) = 16276736$, and $F(100) \\bmod 135707531 = 84326147$.

\n\n

Find $F(12344321) \\bmod 135707531$.

", "url": "https://projecteuler.net/problem=522", "answer": "96772715"} {"id": 523, "problem": "Consider the following algorithm for sorting a list:\n\n- 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.\n\n- 2. If the elements are out of order:\n\n- a. Move the smallest element of the pair at the beginning of the list.\n\n- b. Restart the process from step 1.\n\n- 3. If all pairs are in order, stop.\n\nFor example, the list $\\{\\,4\\,1\\,3\\,2\\,\\}$ is sorted as follows:\n\n- $\\underline{4\\,1}\\,3\\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)\n\n- $1\\,\\underline{4\\,3}\\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)\n\n- $\\underline{3\\,1}\\,4\\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)\n\n- $1\\,3\\,\\underline{4\\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)\n\n- $\\underline{2\\,1}\\,3\\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)\n\n- $1\\,2\\,3\\,4$ (The list is now sorted)\n\nLet $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\\{\\,4\\,1\\,3\\,2\\,\\}) = 5$.\n\nLet $E(n)$ be the expected value of $F(P)$ over all permutations $P$ of the integers $\\{1, 2, \\dots, n\\}$.\n\nYou are given $E(4) = 3.25$ and $E(10) = 115.725$.\n\nFind $E(30)$. Give your answer rounded to two digits after the decimal point.", "raw_html": "

Consider the following algorithm for sorting a list:

\n
  • 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.
  • \n
  • 2. If the elements are out of order:\n
    • a. Move the smallest element of the pair at the beginning of the list.
    • \n
    • b. Restart the process from step 1.
  • \n
  • 3. If all pairs are in order, stop.
\n

For example, the list $\\{\\,4\\,1\\,3\\,2\\,\\}$ is sorted as follows:

\n
  • $\\underline{4\\,1}\\,3\\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)
  • \n
  • $1\\,\\underline{4\\,3}\\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)
  • \n
  • $\\underline{3\\,1}\\,4\\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)
  • \n
  • $1\\,3\\,\\underline{4\\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)
  • \n
  • $\\underline{2\\,1}\\,3\\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)
  • \n
  • $1\\,2\\,3\\,4$ (The list is now sorted)
\n\n

Let $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\\{\\,4\\,1\\,3\\,2\\,\\}) = 5$.

\n\n

Let $E(n)$ be the expected value of $F(P)$ over all permutations $P$ of the integers $\\{1, 2, \\dots, n\\}$.
\nYou are given $E(4) = 3.25$ and $E(10) = 115.725$.

\n\n

Find $E(30)$. Give your answer rounded to two digits after the decimal point.

", "url": "https://projecteuler.net/problem=523", "answer": "37125450.44"} {"id": 524, "problem": "Consider the following algorithm for sorting a list:\n\n- 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.\n\n- 2. If the elements are out of order:\n\n- a. Move the smallest element of the pair at the beginning of the list.\n\n- b. Restart the process from step 1.\n\n- 3. If all pairs are in order, stop.\n\nFor example, the list $\\{\\,4\\,1\\,3\\,2\\,\\}$ is sorted as follows:\n\n- $\\underline{4\\,1}\\,3\\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)\n\n- $1\\,\\underline{4\\,3}\\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)\n\n- $\\underline{3\\,1}\\,4\\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)\n\n- $1\\,3\\,\\underline{4\\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)\n\n- $\\underline{2\\,1}\\,3\\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)\n\n- $1\\,2\\,3\\,4$ (The list is now sorted)\n\nLet $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\\{\\,4\\,1\\,3\\,2\\,\\}) = 5$.\n\nWe can list all permutations $P$ of the integers $\\{1, 2, \\dots, n\\}$ in lexicographical order, and assign to each permutation an index $I_n(P)$ from $1$ to $n!$ corresponding to its position in the list.\n\nLet $Q(n, k) = \\min(I_n(P))$ for $F(P) = k$, the index of the first permutation requiring exactly $k$ steps to sort with First Sort. If there is no permutation for which $F(P) = k$, then $Q(n, k)$ is undefined.\n\nFor $n = 4$ we have:\n\n| P | I4(P) | F(P) | |\n| --- | --- | --- | --- |\n| {1, 2, 3, 4} | 1 | 0 | Q(4, 0) = 1 |\n| {1, 2, 4, 3} | 2 | 4 | Q(4, 4) = 2 |\n| {1, 3, 2, 4} | 3 | 2 | Q(4, 2) = 3 |\n| {1, 3, 4, 2} | 4 | 2 | |\n| {1, 4, 2, 3} | 5 | 6 | Q(4, 6) = 5 |\n| {1, 4, 3, 2} | 6 | 4 | |\n| {2, 1, 3, 4} | 7 | 1 | Q(4, 1) = 7 |\n| {2, 1, 4, 3} | 8 | 5 | Q(4, 5) = 8 |\n| {2, 3, 1, 4} | 9 | 1 | |\n| {2, 3, 4, 1} | 10 | 1 | |\n| {2, 4, 1, 3} | 11 | 5 | |\n| {2, 4, 3, 1} | 12 | 3 | Q(4, 3) = 12 |\n| {3, 1, 2, 4} | 13 | 3 | |\n| {3, 1, 4, 2} | 14 | 3 | |\n| {3, 2, 1, 4} | 15 | 2 | |\n| {3, 2, 4, 1} | 16 | 2 | |\n| {3, 4, 1, 2} | 17 | 3 | |\n| {3, 4, 2, 1} | 18 | 2 | |\n| {4, 1, 2, 3} | 19 | 7 | Q(4, 7) = 19 |\n| {4, 1, 3, 2} | 20 | 5 | |\n| {4, 2, 1, 3} | 21 | 6 | |\n| {4, 2, 3, 1} | 22 | 4 | |\n| {4, 3, 1, 2} | 23 | 4 | |\n| {4, 3, 2, 1} | 24 | 3 | |\n\nLet $R(k) = \\min(Q(n, k))$ over all $n$ for which $Q(n, k)$ is defined.\n\nFind $R(12^{12})$.", "raw_html": "

Consider the following algorithm for sorting a list:

\n
  • 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.
  • \n
  • 2. If the elements are out of order:\n
    • a. Move the smallest element of the pair at the beginning of the list.
    • \n
    • b. Restart the process from step 1.
  • \n
  • 3. If all pairs are in order, stop.
\n

For example, the list $\\{\\,4\\,1\\,3\\,2\\,\\}$ is sorted as follows:

\n
  • $\\underline{4\\,1}\\,3\\,2$ ($4$ and $1$ are out of order so move $1$ to the front of the list)
  • \n
  • $1\\,\\underline{4\\,3}\\,2$ ($4$ and $3$ are out of order so move $3$ to the front of the list)
  • \n
  • $\\underline{3\\,1}\\,4\\,2$ ($3$ and $1$ are out of order so move $1$ to the front of the list)
  • \n
  • $1\\,3\\,\\underline{4\\,2}$ ($4$ and $2$ are out of order so move $2$ to the front of the list)
  • \n
  • $\\underline{2\\,1}\\,3\\,4$ ($2$ and $1$ are out of order so move $1$ to the front of the list)
  • \n
  • $1\\,2\\,3\\,4$ (The list is now sorted)
\n\n

Let $F(L)$ be the number of times step 2a is executed to sort list $L$. For example, $F(\\{\\,4\\,1\\,3\\,2\\,\\}) = 5$.

\n\n

We can list all permutations $P$ of the integers $\\{1, 2, \\dots, n\\}$ in lexicographical order, and assign to each permutation an index $I_n(P)$ from $1$ to $n!$ corresponding to its position in the list.\n\n

Let $Q(n, k) = \\min(I_n(P))$ for $F(P) = k$, the index of the first permutation requiring exactly $k$ steps to sort with First Sort. If there is no permutation for which $F(P) = k$, then $Q(n, k)$ is undefined.

\n\n

For $n = 4$ we have:

\n\n

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
PI4(P)F(P)
{1, 2, 3, 4}10Q(4, 0) = 1
{1, 2, 4, 3}24Q(4, 4) = 2
{1, 3, 2, 4}32Q(4, 2) = 3
{1, 3, 4, 2}42
{1, 4, 2, 3}56Q(4, 6) = 5
{1, 4, 3, 2}64
{2, 1, 3, 4}71Q(4, 1) = 7
{2, 1, 4, 3}85Q(4, 5) = 8
{2, 3, 1, 4}91
{2, 3, 4, 1}101
{2, 4, 1, 3}115
{2, 4, 3, 1}123Q(4, 3) = 12
{3, 1, 2, 4}133
{3, 1, 4, 2}143
{3, 2, 1, 4}152
{3, 2, 4, 1}162
{3, 4, 1, 2}173
{3, 4, 2, 1}182
{4, 1, 2, 3}197Q(4, 7) = 19
{4, 1, 3, 2}205
{4, 2, 1, 3}216
{4, 2, 3, 1}224
{4, 3, 1, 2}234
{4, 3, 2, 1}243
\n\n

Let $R(k) = \\min(Q(n, k))$ over all $n$ for which $Q(n, k)$ is defined.

\n\n

Find $R(12^{12})$.

", "url": "https://projecteuler.net/problem=524", "answer": "2432925835413407847"} {"id": 525, "problem": "An ellipse $E(a, b)$ is given at its initial position by equation:\n\n$\\frac {x^2} {a^2} + \\frac {(y - b)^2} {b^2} = 1$\n\nThe ellipse rolls without slipping along the $x$ axis for one complete turn. Interestingly, the length of the curve generated by a focus is independent from the size of the minor axis:\n\n$F(a,b) = 2 \\pi \\max(a,b)$\n\nThis is not true for the curve generated by the ellipse center. Let $C(a, b)$ be the length of the curve generated by the center of the ellipse as it rolls without slipping for one turn.\n\nYou are given $C(2, 4) \\approx 21.38816906$.\n\nFind $C(1, 4) + C(3, 4)$. Give your answer rounded to $8$ digits behind the decimal point in the form ab.cdefghij.", "raw_html": "

An ellipse $E(a, b)$ is given at its initial position by equation:
\n$\\frac {x^2} {a^2} + \\frac {(y - b)^2} {b^2} = 1$

\n\n

The ellipse rolls without slipping along the $x$ axis for one complete turn. Interestingly, the length of the curve generated by a focus is independent from the size of the minor axis:
\n$F(a,b) = 2 \\pi \\max(a,b)$

\n\n
\"0525-rolling-ellipse-1.gif\"
\n\n

This is not true for the curve generated by the ellipse center. Let $C(a, b)$ be the length of the curve generated by the center of the ellipse as it rolls without slipping for one turn.

\n\n
\"0525-rolling-ellipse-2.gif\"
\n\n

You are given $C(2, 4) \\approx 21.38816906$.

\n\n

Find $C(1, 4) + C(3, 4)$. Give your answer rounded to $8$ digits behind the decimal point in the form ab.cdefghij.

", "url": "https://projecteuler.net/problem=525", "answer": "44.69921807"} {"id": 526, "problem": "Let $f(n)$ be the largest prime factor of $n$.\n\nLet $g(n) = f(n) + f(n + 1) + f(n + 2) + f(n + 3) + f(n + 4) + f(n + 5) + f(n + 6) + f(n + 7) + f(n + 8)$, the sum of the largest prime factor of each of nine consecutive numbers starting with $n$.\n\nLet $h(n)$ be the maximum value of $g(k)$ for $2 \\le k \\le n$.\n\nYou are given:\n\n- $f(100) = 5$\n\n- $f(101) = 101$\n\n- $g(100) = 409$\n\n- $h(100) = 417$\n\n- $h(10^9) = 4896292593$\n\nFind $h(10^{16})$.", "raw_html": "

Let $f(n)$ be the largest prime factor of $n$.

\n

Let $g(n) = f(n) + f(n + 1) + f(n + 2) + f(n + 3) + f(n + 4) + f(n + 5) + f(n + 6) + f(n + 7) + f(n + 8)$, the sum of the largest prime factor of each of nine consecutive numbers starting with $n$.

\n

Let $h(n)$ be the maximum value of $g(k)$ for $2 \\le k \\le n$.

\n

You are given:

\n
  • $f(100) = 5$
  • \n
  • $f(101) = 101$
  • \n
  • $g(100) = 409$
  • \n
  • $h(100) = 417$
  • \n
  • $h(10^9) = 4896292593$
\n

Find $h(10^{16})$.

", "url": "https://projecteuler.net/problem=526", "answer": "49601160286750947"} {"id": 527, "problem": "A secret integer $t$ is selected at random within the range $1 \\le t \\le n$.\n\nThe goal is to guess the value of $t$ by making repeated guesses, via integer $g$. After a guess is made, there are three possible outcomes, in which it will be revealed that either $g \\lt t$, $g = t$, or $g \\gt t$. Then the process can repeat as necessary.\n\nNormally, the number of guesses required on average can be minimized with a binary search: Given a lower bound $L$ and upper bound $H$ (initialized to $L = 1$ and $H = n$), let $g = \\lfloor(L+H)/2\\rfloor$ where $\\lfloor \\cdot \\rfloor$ is the integer floor function. If $g = t$, the process ends. Otherwise, if $g \\lt t$, set $L = g+1$, but if $g \\gt t$ instead, set $H = g - 1$. After setting the new bounds, the search process repeats, and ultimately ends once $t$ is found. Even if $t$ can be deduced without searching, assume that a search will be required anyway to confirm the value.\n\nYour friend Bob believes that the standard binary search is not that much better than his randomized variant: Instead of setting $g = \\lfloor(L+H)/2\\rfloor$, simply let $g$ be a random integer between $L$ and $H$, inclusive. The rest of the algorithm is the same as the standard binary search. This new search routine will be referred to as a random binary search.\n\nGiven that $1 \\le t \\le n$ for random $t$, let $B(n)$ be the expected number of guesses needed to find $t$ using the standard binary search, and let $R(n)$ be the expected number of guesses needed to find $t$ using the random binary search. For example, $B(6) = 2.33333333$ and $R(6) = 2.71666667$ when rounded to $8$ decimal places.\n\nFind $R(10^{10}) - B(10^{10})$ rounded to $8$ decimal places.", "raw_html": "

A secret integer $t$ is selected at random within the range $1 \\le t \\le n$.

\n\n

The goal is to guess the value of $t$ by making repeated guesses, via integer $g$. After a guess is made, there are three possible outcomes, in which it will be revealed that either $g \\lt t$, $g = t$, or $g \\gt t$. Then the process can repeat as necessary.

\n\n

Normally, the number of guesses required on average can be minimized with a binary search: Given a lower bound $L$ and upper bound $H$ (initialized to $L = 1$ and $H = n$), let $g = \\lfloor(L+H)/2\\rfloor$ where $\\lfloor \\cdot \\rfloor$ is the integer floor function. If $g = t$, the process ends. Otherwise, if $g \\lt t$, set $L = g+1$, but if $g \\gt t$ instead, set $H = g - 1$. After setting the new bounds, the search process repeats, and ultimately ends once $t$ is found. Even if $t$ can be deduced without searching, assume that a search will be required anyway to confirm the value.

\n\n

Your friend Bob believes that the standard binary search is not that much better than his randomized variant: Instead of setting $g = \\lfloor(L+H)/2\\rfloor$, simply let $g$ be a random integer between $L$ and $H$, inclusive. The rest of the algorithm is the same as the standard binary search. This new search routine will be referred to as a random binary search.

\n\n

Given that $1 \\le t \\le n$ for random $t$, let $B(n)$ be the expected number of guesses needed to find $t$ using the standard binary search, and let $R(n)$ be the expected number of guesses needed to find $t$ using the random binary search. For example, $B(6) = 2.33333333$ and $R(6) = 2.71666667$ when rounded to $8$ decimal places.

\n\n

Find $R(10^{10}) - B(10^{10})$ rounded to $8$ decimal places.

", "url": "https://projecteuler.net/problem=527", "answer": "11.92412011"} {"id": 528, "problem": "Let $S(n, k, b)$ represent the number of valid solutions to $x_1 + x_2 + \\cdots + x_k \\le n$, where $0 \\le x_m \\le b^m$ for all $1 \\le m \\le k$.\n\nFor example, $S(14,3,2) = 135$, $S(200,5,3) = 12949440$, and $S(1000,10,5) \\bmod 1\\,000\\,000\\,007 = 624839075$.\n\nFind $(\\sum_{10 \\le k \\le 15} S(10^k, k, k)) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Let $S(n, k, b)$ represent the number of valid solutions to $x_1 + x_2 + \\cdots + x_k \\le n$, where $0 \\le x_m \\le b^m$ for all $1 \\le m \\le k$.

\n\n

For example, $S(14,3,2) = 135$, $S(200,5,3) = 12949440$, and $S(1000,10,5) \\bmod 1\\,000\\,000\\,007 = 624839075$.

\n\n

Find $(\\sum_{10 \\le k \\le 15} S(10^k, k, k)) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=528", "answer": "779027989"} {"id": 529, "problem": "A $10$-substring of a number is a substring of its digits that sum to $10$. For example, the $10$-substrings of the number $3523014$ are:\n\n- 3523014\n\n- 3523014\n\n- 3523014\n\n- 3523014\n\nA number is called $10$-substring-friendly if every one of its digits belongs to a $10$-substring. For example, $3523014$ is $10$-substring-friendly, but $28546$ is not.\n\nLet $T(n)$ be the number of $10$-substring-friendly numbers from $1$ to $10^n$ (inclusive).\n\nFor example $T(2) = 9$ and $T(5) = 3492$.\n\nFind $T(10^{18}) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

A $10$-substring of a number is a substring of its digits that sum to $10$. For example, the $10$-substrings of the number $3523014$ are:

\n
  • 3523014
  • \n
  • 3523014
  • \n
  • 3523014
  • \n
  • 3523014
\n

A number is called $10$-substring-friendly if every one of its digits belongs to a $10$-substring. For example, $3523014$ is $10$-substring-friendly, but $28546$ is not.

\n

Let $T(n)$ be the number of $10$-substring-friendly numbers from $1$ to $10^n$ (inclusive).
\nFor example $T(2) = 9$ and $T(5) = 3492$.

\n

Find $T(10^{18}) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=529", "answer": "23624465"} {"id": 530, "problem": "Every divisor $d$ of a number $n$ has a complementary divisor $n/d$.\n\nLet $f(n)$ be the sum of the greatest common divisor of $d$ and $n/d$ over all positive divisors $d$ of $n$, that is\n$f(n)=\\displaystyle\\sum_{d\\mid n}\\gcd(d,\\frac n d)$.\n\nLet $F$ be the summatory function of $f$, that is\n$F(k)=\\displaystyle\\sum_{n=1}^k f(n)$.\n\nYou are given that $F(10)=32$ and $F(1000)=12776$.\n\nFind $F(10^{15})$.", "raw_html": "

Every divisor $d$ of a number $n$ has a complementary divisor $n/d$.

\n\n

Let $f(n)$ be the sum of the greatest common divisor of $d$ and $n/d$ over all positive divisors $d$ of $n$, that is\n$f(n)=\\displaystyle\\sum_{d\\mid n}\\gcd(d,\\frac n d)$.

\n\n

Let $F$ be the summatory function of $f$, that is\n$F(k)=\\displaystyle\\sum_{n=1}^k f(n)$.

\n\n

You are given that $F(10)=32$ and $F(1000)=12776$.

\n\n

Find $F(10^{15})$.

", "url": "https://projecteuler.net/problem=530", "answer": "207366437157977206"} {"id": 531, "problem": "Let $g(a, n, b, m)$ be the smallest non-negative solution $x$ to the system:\n\n$x = a \\bmod n$\n\n$x = b \\bmod m$\n\nif such a solution exists, otherwise $0$.\n\nE.g. $g(2,4,4,6)=10$, but $g(3,4,4,6)=0$.\n\nLet $\\phi(n)$ be Euler's totient function.\n\nLet $f(n,m)=g(\\phi(n),n,\\phi(m),m)$\n\nFind $\\sum f(n,m)$ for $1000000 \\le n \\lt m \\lt 1005000$.", "raw_html": "

\nLet $g(a, n, b, m)$ be the smallest non-negative solution $x$ to the system:
\n$x = a \\bmod n$
\n$x = b \\bmod m$
\nif such a solution exists, otherwise $0$.\n

\n

\nE.g. $g(2,4,4,6)=10$, but $g(3,4,4,6)=0$.\n

\n

\nLet $\\phi(n)$ be Euler's totient function.\n

\n

\nLet $f(n,m)=g(\\phi(n),n,\\phi(m),m)$\n

\n

\nFind $\\sum f(n,m)$ for $1000000 \\le n \\lt m \\lt 1005000$.\n

", "url": "https://projecteuler.net/problem=531", "answer": "4515432351156203105"} {"id": 532, "problem": "Bob is a manufacturer of nanobots and wants to impress his customers by giving them a ball coloured by his new nanobots as a present.\n\nHis nanobots can be programmed to select and locate exactly one other bot precisely and, after activation, move towards this bot along the shortest possible path and draw a coloured line onto the surface while moving. Placed on a plane, the bots will start to move towards their selected bots in a straight line. In contrast, being placed on a ball, they will start to move along a geodesic as the shortest possible path. However, in both cases, whenever their target moves they will adjust their direction instantaneously to the new shortest possible path. All bots will move at the same speed after their simultaneous activation until each bot reaches its goal.\n\nNow Bob places $n$ bots on the ball (with radius $1$) equidistantly on a small circle with radius $0.999$ and programs each of them to move toward the next nanobot sitting counterclockwise on that small circle. After activation, the bots move in a sort of spiral until they finally meet at one point on the ball.\n\nUsing three bots, Bob finds that every bot will draw a line of length $2.84$, resulting in a total length of $8.52$ for all three bots, each time rounded to two decimal places. The coloured ball looks like this:\n\nIn order to show off a little with his presents, Bob decides to use just enough bots to make sure that the line each bot draws is longer than $1000$. What is the total length of all lines drawn with this number of bots, rounded to two decimal places?", "raw_html": "

Bob is a manufacturer of nanobots and wants to impress his customers by giving them a ball coloured by his new nanobots as a present.

\n\n

His nanobots can be programmed to select and locate exactly one other bot precisely and, after activation, move towards this bot along the shortest possible path and draw a coloured line onto the surface while moving. Placed on a plane, the bots will start to move towards their selected bots in a straight line. In contrast, being placed on a ball, they will start to move along a geodesic as the shortest possible path. However, in both cases, whenever their target moves they will adjust their direction instantaneously to the new shortest possible path. All bots will move at the same speed after their simultaneous activation until each bot reaches its goal.

\n\n

Now Bob places $n$ bots on the ball (with radius $1$) equidistantly on a small circle with radius $0.999$ and programs each of them to move toward the next nanobot sitting counterclockwise on that small circle. After activation, the bots move in a sort of spiral until they finally meet at one point on the ball.

\n\n

Using three bots, Bob finds that every bot will draw a line of length $2.84$, resulting in a total length of $8.52$ for all three bots, each time rounded to two decimal places. The coloured ball looks like this:

\n\n
\"0532-nanobots.jpg\"
\n\n

In order to show off a little with his presents, Bob decides to use just enough bots to make sure that the line each bot draws is longer than $1000$. What is the total length of all lines drawn with this number of bots, rounded to two decimal places?

", "url": "https://projecteuler.net/problem=532", "answer": "827306.56"} {"id": 533, "problem": "The Carmichael function $\\lambda(n)$ is defined as the smallest positive integer $m$ such that $a^m = 1$ modulo $n$ for all integers $a$ coprime with $n$.\n\nFor example $\\lambda(8) = 2$ and $\\lambda(240) = 4$.\n\nDefine $L(n)$ as the smallest positive integer $m$ such that $\\lambda(k) \\ge n$ for all $k \\ge m$.\n\nFor example, $L(6) = 241$ and $L(100) = 20\\,174\\,525\\,281$.\n\nFind $L(20\\,000\\,000)$. Give the last $9$ digits of your answer.", "raw_html": "

The Carmichael function $\\lambda(n)$ is defined as the smallest positive integer $m$ such that $a^m = 1$ modulo $n$ for all integers $a$ coprime with $n$.
\nFor example $\\lambda(8) = 2$ and $\\lambda(240) = 4$.

\n\n

Define $L(n)$ as the smallest positive integer $m$ such that $\\lambda(k) \\ge n$ for all $k \\ge m$.
\nFor example, $L(6) = 241$ and $L(100) = 20\\,174\\,525\\,281$.

\n\n

Find $L(20\\,000\\,000)$. Give the last $9$ digits of your answer.

", "url": "https://projecteuler.net/problem=533", "answer": "789453601"} {"id": 534, "problem": "The classical eight queens puzzle is the well known problem of placing eight chess queens on an $8 \\times 8$ chessboard so that no two queens threaten each other. Allowing configurations to reappear in rotated or mirrored form, a total of $92$ distinct configurations can be found for eight queens. The general case asks for the number of distinct ways of placing $n$ queens on an $n \\times n$ board, e.g. you can find $2$ distinct configurations for $n=4$.\n\nLet's define a weak queen on an $n \\times n$ board to be a piece which can move any number of squares if moved horizontally, but a maximum of $n - 1 - w$ squares if moved vertically or diagonally, $0 \\le w \\lt n$ being the \"weakness factor\". For example, a weak queen on an $n \\times n$ board with a weakness factor of $w=1$ located in the bottom row will not be able to threaten any square in the top row as the weak queen would need to move $n - 1$ squares vertically or diagonally to get there, but may only move $n - 2$ squares in these directions. In contrast, the weak queen is not handicapped horizontally, thus threatening every square in its own row, independently from its current position in that row.\n\nLet $Q(n,w)$ be the number of ways $n$ weak queens with weakness factor $w$ can be placed on an $n \\times n$ board so that no two queens threaten each other. It can be shown, for example, that $Q(4,0)=2$, $Q(4,2)=16$ and $Q(4,3)=256$.\n\nLet $S(n)=\\displaystyle\\sum_{w=0}^{n-1} Q(n,w)$.\n\nYou are given that $S(4)=276$ and $S(5)=3347$.\n\nFind $S(14)$.", "raw_html": "

The classical eight queens puzzle is the well known problem of placing eight chess queens on an $8 \\times 8$ chessboard so that no two queens threaten each other. Allowing configurations to reappear in rotated or mirrored form, a total of $92$ distinct configurations can be found for eight queens. The general case asks for the number of distinct ways of placing $n$ queens on an $n \\times n$ board, e.g. you can find $2$ distinct configurations for $n=4$.

\n\n

Let's define a weak queen on an $n \\times n$ board to be a piece which can move any number of squares if moved horizontally, but a maximum of $n - 1 - w$ squares if moved vertically or diagonally, $0 \\le w \\lt n$ being the \"weakness factor\". For example, a weak queen on an $n \\times n$ board with a weakness factor of $w=1$ located in the bottom row will not be able to threaten any square in the top row as the weak queen would need to move $n - 1$ squares vertically or diagonally to get there, but may only move $n - 2$ squares in these directions. In contrast, the weak queen is not handicapped horizontally, thus threatening every square in its own row, independently from its current position in that row.

\n\n

Let $Q(n,w)$ be the number of ways $n$ weak queens with weakness factor $w$ can be placed on an $n \\times n$ board so that no two queens threaten each other. It can be shown, for example, that $Q(4,0)=2$, $Q(4,2)=16$ and $Q(4,3)=256$.

\n\n

Let $S(n)=\\displaystyle\\sum_{w=0}^{n-1} Q(n,w)$.

\n\n

You are given that $S(4)=276$ and $S(5)=3347$.

\n\n

Find $S(14)$.

", "url": "https://projecteuler.net/problem=534", "answer": "11726115562784664"} {"id": 535, "problem": "Consider the infinite integer sequence S starting with:\n\n$S = 1, 1, 2, 1, 3, 2, 4, 1, 5, 3, 6, 2, 7, 8, 4, 9, 1, 10, 11, 5, \\dots$\n\nCircle the first occurrence of each integer.\n\n$S = \\enclose{circle}1, 1, \\enclose{circle}2, 1, \\enclose{circle}3, 2, \\enclose{circle}4, 1, \\enclose{circle}5, 3, \\enclose{circle}6, 2, \\enclose{circle}7, \\enclose{circle}8, 4, \\enclose{circle}9, 1, \\enclose{circle}{10}, \\enclose{circle}{11}, 5, \\dots$\n\nThe sequence is characterized by the following properties:\n\n- The circled numbers are consecutive integers starting with $1$.\n\n- Immediately preceding each non-circled numbers $a_i$, there are exactly $\\lfloor \\sqrt{a_i} \\rfloor$ adjacent circled numbers, where $\\lfloor\\,\\rfloor$ is the floor function.\n\n- If we remove all circled numbers, the remaining numbers form a sequence identical to $S$, so $S$ is a fractal sequence.\n\nLet $T(n)$ be the sum of the first $n$ elements of the sequence.\n\nYou are given $T(1) = 1$, $T(20) = 86$, $T(10^3) = 364089$ and $T(10^9) = 498676527978348241$.\n\nFind $T(10^{18})$. Give the last $9$ digits of your answer.", "raw_html": "

Consider the infinite integer sequence S starting with:
\n$S = 1, 1, 2, 1, 3, 2, 4, 1, 5, 3, 6, 2, 7, 8, 4, 9, 1, 10, 11, 5, \\dots$

\n\n

Circle the first occurrence of each integer.
\n$S = \\enclose{circle}1, 1, \\enclose{circle}2, 1, \\enclose{circle}3, 2, \\enclose{circle}4, 1, \\enclose{circle}5, 3, \\enclose{circle}6, 2, \\enclose{circle}7, \\enclose{circle}8, 4, \\enclose{circle}9, 1, \\enclose{circle}{10}, \\enclose{circle}{11}, 5, \\dots$

\n\n

The sequence is characterized by the following properties:

\n
  • The circled numbers are consecutive integers starting with $1$.
  • \n
  • Immediately preceding each non-circled numbers $a_i$, there are exactly $\\lfloor \\sqrt{a_i} \\rfloor$ adjacent circled numbers, where $\\lfloor\\,\\rfloor$ is the floor function.
  • \n
  • If we remove all circled numbers, the remaining numbers form a sequence identical to $S$, so $S$ is a fractal sequence.
\n\n

Let $T(n)$ be the sum of the first $n$ elements of the sequence.
\nYou are given $T(1) = 1$, $T(20) = 86$, $T(10^3) = 364089$ and $T(10^9) = 498676527978348241$.

\n\n

Find $T(10^{18})$. Give the last $9$ digits of your answer.

", "url": "https://projecteuler.net/problem=535", "answer": "611778217"} {"id": 536, "problem": "Let $S(n)$ be the sum of all positive integers $m$ not exceeding $n$ having the following property:\n\n$a^{m + 4} \\equiv a \\pmod m$ for all integers $a$.\n\nThe values of $m \\le 100$ that satisfy this property are $1, 2, 3, 5$ and $21$, thus $S(100) = 1+2+3+5+21 = 32$.\n\nYou are given $S(10^6) = 22868117$.\n\nFind $S(10^{12})$.", "raw_html": "

\nLet $S(n)$ be the sum of all positive integers $m$ not exceeding $n$ having the following property:
\n$a^{m + 4} \\equiv a \\pmod m$ for all integers $a$.\n

\n

\nThe values of $m \\le 100$ that satisfy this property are $1, 2, 3, 5$ and $21$, thus $S(100) = 1+2+3+5+21 = 32$.
\nYou are given $S(10^6) = 22868117$.\n

\n

\nFind $S(10^{12})$.\n

", "url": "https://projecteuler.net/problem=536", "answer": "3557005261906288"} {"id": 537, "problem": "Let $\\pi(x)$ be the prime counting function, i.e. the number of prime numbers less than or equal to $x$.\n\nFor example,$\\pi(1)=0$, $\\pi(2)=1$, $\\pi(100)=25$.\n\nLet $T(n, k)$ be the number of $k$-tuples $(x_1, \\dots, x_k)$ which satisfy:\n\n1. every $x_i$ is a positive integer;\n\n2. $\\displaystyle \\sum_{i=1}^k \\pi(x_i)=n$\n\nFor example $T(3,3)=19$.\n\nThe $19$ tuples are $(1,1,5)$, $(1,5,1)$, $(5,1,1)$, $(1,1,6)$, $(1,6,1)$, $(6,1,1)$, $(1,2,3)$, $(1,3,2)$, $(2,1,3)$, $(2,3,1)$, $(3,1,2)$, $(3,2,1)$, $(1,2,4)$, $(1,4,2)$, $(2,1,4)$, $(2,4,1)$, $(4,1,2)$, $(4,2,1)$, $(2,2,2)$.\n\nYou are given $T(10, 10) = 869\\,985$ and $T(10^3,10^3) \\equiv 578\\,270\\,566 \\pmod{1\\,004\\,535\\,809}$.\n\nFind $T(20\\,000, 20\\,000) \\pmod{1\\,004\\,535\\,809}$.", "raw_html": "

\nLet $\\pi(x)$ be the prime counting function, i.e. the number of prime numbers less than or equal to $x$.
\nFor example,$\\pi(1)=0$, $\\pi(2)=1$, $\\pi(100)=25$.\n

\n

\nLet $T(n, k)$ be the number of $k$-tuples $(x_1, \\dots, x_k)$ which satisfy:
\n1. every $x_i$ is a positive integer;
\n2. $\\displaystyle \\sum_{i=1}^k \\pi(x_i)=n$\n

\n

\nFor example $T(3,3)=19$.
\nThe $19$ tuples are $(1,1,5)$, $(1,5,1)$, $(5,1,1)$, $(1,1,6)$, $(1,6,1)$, $(6,1,1)$, $(1,2,3)$, $(1,3,2)$, $(2,1,3)$, $(2,3,1)$, $(3,1,2)$, $(3,2,1)$, $(1,2,4)$, $(1,4,2)$, $(2,1,4)$, $(2,4,1)$, $(4,1,2)$, $(4,2,1)$, $(2,2,2)$.\n

\n

\nYou are given $T(10, 10) = 869\\,985$ and $T(10^3,10^3) \\equiv 578\\,270\\,566 \\pmod{1\\,004\\,535\\,809}$.\n

\nFind $T(20\\,000, 20\\,000) \\pmod{1\\,004\\,535\\,809}$.\n

", "url": "https://projecteuler.net/problem=537", "answer": "779429131"} {"id": 538, "problem": "Consider a positive integer sequence $S = (s_1, s_2, \\dots, s_n)$.\n\nLet $f(S)$ be the perimeter of the maximum-area quadrilateral whose side lengths are $4$ elements $(s_i, s_j, s_k, s_l)$ of $S$ (all $i, j, k, l$ distinct). If there are many quadrilaterals with the same maximum area, then choose the one with the largest perimeter.\n\nFor example, if $S = (8, 9, 14, 9, 27)$, then we can take the elements $(9, 14, 9, 27)$ and form an isosceles trapeziumAn isosceles trapezium (US: trapezoid) is a quadrilateral where one pair of opposite sides are parallel and of different lengths, and the other pair has the same length. with parallel side lengths $14$ and $27$ and both leg lengths $9$. The area of this quadrilateral is $127.611470879\\cdots$ It can be shown that this is the largest area for any quadrilateral that can be formed using side lengths from $S$. Therefore, $f(S) = 9 + 14 + 9 + 27 = 59$.\n\nLet $u_n = 2^{B(3n)} + 3^{B(2n)} + B(n + 1)$, where $B(k)$ is the number of $1$ bits of $k$ in base $2$.\n\nFor example, $B(6) = 2$, $B(10) = 2$ and $B(15) = 4$, and $u_5 = 2^4 + 3^2 + 2 = 27$.\n\nAlso, let $U_n$ be the sequence $(u_1, u_2, \\dots, u_n)$.\n\nFor example, $U_{10} = (8, 9, 14, 9, 27, 16, 36, 9, 27, 28)$.\n\nIt can be shown that $f(U_5) = 59$, $f(U_{10}) = 118$, $f(U_{150}) = 3223$.\n\nIt can also be shown that $\\sum f(U_n) = 234761$ for $4 \\le n \\le 150$.\n\nFind $\\sum f(U_n)$ for $4 \\le n \\le 3\\,000\\,000$.", "raw_html": "

Consider a positive integer sequence $S = (s_1, s_2, \\dots, s_n)$.

\n\n

Let $f(S)$ be the perimeter of the maximum-area quadrilateral whose side lengths are $4$ elements $(s_i, s_j, s_k, s_l)$ of $S$ (all $i, j, k, l$ distinct). If there are many quadrilaterals with the same maximum area, then choose the one with the largest perimeter.

\n\n

For example, if $S = (8, 9, 14, 9, 27)$, then we can take the elements $(9, 14, 9, 27)$ and form an isosceles trapeziumAn isosceles trapezium (US: trapezoid) is a quadrilateral where one pair of opposite sides are parallel and of different lengths, and the other pair has the same length. with parallel side lengths $14$ and $27$ and both leg lengths $9$. The area of this quadrilateral is $127.611470879\\cdots$ It can be shown that this is the largest area for any quadrilateral that can be formed using side lengths from $S$. Therefore, $f(S) = 9 + 14 + 9 + 27 = 59$.

\n\n

Let $u_n = 2^{B(3n)} + 3^{B(2n)} + B(n + 1)$, where $B(k)$ is the number of $1$ bits of $k$ in base $2$.
\nFor example, $B(6) = 2$, $B(10) = 2$ and $B(15) = 4$, and $u_5 = 2^4 + 3^2 + 2 = 27$.

\n\n

Also, let $U_n$ be the sequence $(u_1, u_2, \\dots, u_n)$.
\nFor example, $U_{10} = (8, 9, 14, 9, 27, 16, 36, 9, 27, 28)$.

\n\n

It can be shown that $f(U_5) = 59$, $f(U_{10}) = 118$, $f(U_{150}) = 3223$.
\nIt can also be shown that $\\sum f(U_n) = 234761$ for $4 \\le n \\le 150$.
\nFind $\\sum f(U_n)$ for $4 \\le n \\le 3\\,000\\,000$.

", "url": "https://projecteuler.net/problem=538", "answer": "22472871503401097"} {"id": 539, "problem": "Start from an ordered list of all integers from $1$ to $n$. Going from left to right, remove the first number and every other number afterward until the end of the list. Repeat the procedure from right to left, removing the right most number and every other number from the numbers left. Continue removing every other numbers, alternating left to right and right to left, until a single number remains.\n\nStarting with $n = 9$, we have:\n\n$\\underline 1\\,2\\,\\underline 3\\,4\\,\\underline 5\\,6\\,\\underline 7\\,8\\,\\underline 9$\n\n$2\\,\\underline 4\\,6\\,\\underline 8$\n\n$\\underline 2\\,6$\n\n$6$\n\nLet $P(n)$ be the last number left starting with a list of length $n$.\n\nLet $\\displaystyle S(n) = \\sum_{k=1}^n P(k)$.\n\nYou are given $P(1)=1$, $P(9) = 6$, $P(1000)=510$, $S(1000)=268271$.\n\nFind $S(10^{18}) \\bmod 987654321$.", "raw_html": "

\nStart from an ordered list of all integers from $1$ to $n$. Going from left to right, remove the first number and every other number afterward until the end of the list. Repeat the procedure from right to left, removing the right most number and every other number from the numbers left. Continue removing every other numbers, alternating left to right and right to left, until a single number remains.\n

\n

\nStarting with $n = 9$, we have:
\n$\\underline 1\\,2\\,\\underline 3\\,4\\,\\underline 5\\,6\\,\\underline 7\\,8\\,\\underline 9$
\n$2\\,\\underline 4\\,6\\,\\underline 8$
\n$\\underline 2\\,6$
\n$6$\n

\n

\nLet $P(n)$ be the last number left starting with a list of length $n$.
\nLet $\\displaystyle S(n) = \\sum_{k=1}^n P(k)$.
\nYou are given $P(1)=1$, $P(9) = 6$, $P(1000)=510$, $S(1000)=268271$.\n

\n

\nFind $S(10^{18}) \\bmod 987654321$.\n

", "url": "https://projecteuler.net/problem=539", "answer": "426334056"} {"id": 540, "problem": "A Pythagorean triple consists of three positive integers $a, b$ and $c$ satisfying $a^2+b^2=c^2$.\n\nThe triple is called primitive if $a, b$ and $c$ are relatively prime.\n\nLet $P(n)$ be the number of primitive Pythagorean triples with $a \\lt b \\lt c \\le n$.\n\nFor example $P(20) = 3$, since there are three triples: $(3,4,5)$, $(5,12,13)$ and $(8,15,17)$.\n\nYou are given that $P(10^6) = 159139$.\n\nFind $P(3141592653589793)$.", "raw_html": "

\nA Pythagorean triple consists of three positive integers $a, b$ and $c$ satisfying $a^2+b^2=c^2$.
\nThe triple is called primitive if $a, b$ and $c$ are relatively prime.
\nLet $P(n)$ be the number of primitive Pythagorean triples with $a \\lt b \\lt c \\le n$.
\nFor example $P(20) = 3$, since there are three triples: $(3,4,5)$, $(5,12,13)$ and $(8,15,17)$.\n

\n

\nYou are given that $P(10^6) = 159139$.
\nFind $P(3141592653589793)$.\n

", "url": "https://projecteuler.net/problem=540", "answer": "500000000002845"} {"id": 541, "problem": "The $n$th harmonic number $H_n$ is defined as the sum of the multiplicative inverses of the first $n$ positive integers, and can be written as a reduced fraction $a_n/b_n$.\n\n$H_n = \\displaystyle \\sum_{k=1}^n \\frac 1 k = \\frac {a_n} {b_n}$, with $\\gcd(a_n, b_n)=1$.\n\nLet $M(p)$ be the largest value of $n$ such that $b_n$ is not divisible by $p$.\n\nFor example, $M(3) = 68$ because $H_{68} = \\frac {a_{68}} {b_{68}} = \\frac {14094018321907827923954201611} {2933773379069966367528193600}$, $b_{68}=2933773379069966367528193600$ is not divisible by $3$, but all larger harmonic numbers have denominators divisible by $3$.\n\nYou are given $M(7) = 719102$.\n\nFind $M(137)$.", "raw_html": "

The $n$th harmonic number $H_n$ is defined as the sum of the multiplicative inverses of the first $n$ positive integers, and can be written as a reduced fraction $a_n/b_n$.
\n$H_n = \\displaystyle \\sum_{k=1}^n \\frac 1 k = \\frac {a_n} {b_n}$, with $\\gcd(a_n, b_n)=1$.

\n\n

Let $M(p)$ be the largest value of $n$ such that $b_n$ is not divisible by $p$.

\n\n

For example, $M(3) = 68$ because $H_{68} = \\frac {a_{68}} {b_{68}} = \\frac {14094018321907827923954201611} {2933773379069966367528193600}$, $b_{68}=2933773379069966367528193600$ is not divisible by $3$, but all larger harmonic numbers have denominators divisible by $3$.

\n\n

You are given $M(7) = 719102$.

\n\n

Find $M(137)$.

", "url": "https://projecteuler.net/problem=541", "answer": "4580726482872451"} {"id": 542, "problem": "Let $S(k)$ be the sum of three or more distinct positive integers having the following properties:\n\n- No value exceeds $k$.\n\n- The values form a geometric progression.\n\n- The sum is maximal.\n\n$S(4) = 4 + 2 + 1 = 7$\n\n$S(10) = 9 + 6 + 4 = 19$\n\n$S(12) = 12 + 6 + 3 = 21$\n\n$S(1000) = 1000 + 900 + 810 + 729 = 3439$\n\nLet $T(n) = \\sum_{k=4}^n (-1)^k S(k)$.\n\n$T(1000) = 2268$\n\nFind $T(10^{17})$.", "raw_html": "

Let $S(k)$ be the sum of three or more distinct positive integers having the following properties:

\n
  • No value exceeds $k$.
  • \n
  • The values form a geometric progression.
  • \n
  • The sum is maximal.
\n\n

$S(4) = 4 + 2 + 1 = 7$
\n$S(10) = 9 + 6 + 4 = 19$
\n$S(12) = 12 + 6 + 3 = 21$
\n$S(1000) = 1000 + 900 + 810 + 729 = 3439$

\n\n

Let $T(n) = \\sum_{k=4}^n (-1)^k S(k)$.
\n$T(1000) = 2268$

\n\n

Find $T(10^{17})$.

", "url": "https://projecteuler.net/problem=542", "answer": "697586734240314852"} {"id": 543, "problem": "Define function $P(n, k) = 1$ if $n$ can be written as the sum of $k$ prime numbers (with repetitions allowed), and $P(n, k) = 0$ otherwise.\n\nFor example, $P(10,2) = 1$ because $10$ can be written as either $3 + 7$ or $5 + 5$, but $P(11,2) = 0$ because no two primes can sum to $11$.\n\nLet $S(n)$ be the sum of all $P(i,k)$ over $1 \\le i,k \\le n$.\n\nFor example, $S(10) = 20$, $S(100) = 2402$, and $S(1000) = 248838$.\n\nLet $F(k)$ be the $k$th Fibonacci number (with $F(0) = 0$ and $F(1) = 1$).\n\nFind the sum of all $S(F(k))$ over $3 \\le k \\le 44$.", "raw_html": "

Define function $P(n, k) = 1$ if $n$ can be written as the sum of $k$ prime numbers (with repetitions allowed), and $P(n, k) = 0$ otherwise.

\n\n

For example, $P(10,2) = 1$ because $10$ can be written as either $3 + 7$ or $5 + 5$, but $P(11,2) = 0$ because no two primes can sum to $11$.

\n\n

Let $S(n)$ be the sum of all $P(i,k)$ over $1 \\le i,k \\le n$.

\n\n

For example, $S(10) = 20$, $S(100) = 2402$, and $S(1000) = 248838$.

\n\n

Let $F(k)$ be the $k$th Fibonacci number (with $F(0) = 0$ and $F(1) = 1$).

\n\n

Find the sum of all $S(F(k))$ over $3 \\le k \\le 44$.

", "url": "https://projecteuler.net/problem=543", "answer": "199007746081234640"} {"id": 544, "problem": "Let $F(r, c, n)$ be the number of ways to colour a rectangular grid with $r$ rows and $c$ columns using at most $n$ colours such that no two adjacent cells share the same colour. Cells that are diagonal to each other are not considered adjacent.\n\nFor example, $F(2,2,3) = 18$, $F(2,2,20) = 130340$, and $F(3,4,6) = 102923670$.\n\nLet $S(r, c, n) = \\sum_{k=1}^{n} F(r, c, k)$.\n\nFor example, $S(4,4,15) \\bmod 10^9+7 = 325951319$.\n\nFind $S(9,10,1112131415) \\bmod 10^9+7$.", "raw_html": "

Let $F(r, c, n)$ be the number of ways to colour a rectangular grid with $r$ rows and $c$ columns using at most $n$ colours such that no two adjacent cells share the same colour. Cells that are diagonal to each other are not considered adjacent.

\n\n

For example, $F(2,2,3) = 18$, $F(2,2,20) = 130340$, and $F(3,4,6) = 102923670$.

\n\n

Let $S(r, c, n) = \\sum_{k=1}^{n} F(r, c, k)$.

\n\n

For example, $S(4,4,15) \\bmod 10^9+7 = 325951319$.

\n\n

Find $S(9,10,1112131415) \\bmod 10^9+7$.

", "url": "https://projecteuler.net/problem=544", "answer": "640432376"} {"id": 545, "problem": "The sum of the $k$th powers of the first $n$ positive integers can be expressed as a polynomial of degree $k+1$ with rational coefficients, the Faulhaber's Formulas:\n\n$1^k + 2^k + ... + n^k = \\sum_{i=1}^n i^k = \\sum_{i=1}^{k+1} a_{i} n^i = a_{1} n + a_{2} n^2 + ... + a_{k} n^k + a_{k+1} n^{k + 1}$,\n\nwhere $a_i$'s are rational coefficients that can be written as reduced fractions $p_i/q_i$ (if $a_i = 0$, we shall consider $q_i = 1$).\n\nFor example, $1^4 + 2^4 + ... + n^4 = -\\frac 1 {30} n + \\frac 1 3 n^3 + \\frac 1 2 n^4 + \\frac 1 5 n^5.$\n\nDefine $D(k)$ as the value of $q_1$ for the sum of $k$th powers (i.e. the denominator of the reduced fraction $a_1$).\n\nDefine $F(m)$ as the $m$th value of $k \\ge 1$ for which $D(k) = 20010$.\n\nYou are given $D(4) = 30$ (since $a_1 = -1/30$), $D(308) = 20010$, $F(1) = 308$, $F(10) = 96404$.\n\nFind $F(10^5)$.", "raw_html": "

The sum of the $k$th powers of the first $n$ positive integers can be expressed as a polynomial of degree $k+1$ with rational coefficients, the Faulhaber's Formulas:
\n$1^k + 2^k + ... + n^k = \\sum_{i=1}^n i^k = \\sum_{i=1}^{k+1} a_{i} n^i = a_{1} n + a_{2} n^2 + ... + a_{k} n^k + a_{k+1} n^{k + 1}$,
\nwhere $a_i$'s are rational coefficients that can be written as reduced fractions $p_i/q_i$ (if $a_i = 0$, we shall consider $q_i = 1$).

\n\n

For example, $1^4 + 2^4 + ... + n^4 = -\\frac 1 {30} n + \\frac 1 3 n^3 + \\frac 1 2 n^4 + \\frac 1 5 n^5.$

\n\n

Define $D(k)$ as the value of $q_1$ for the sum of $k$th powers (i.e. the denominator of the reduced fraction $a_1$).
\nDefine $F(m)$ as the $m$th value of $k \\ge 1$ for which $D(k) = 20010$.
\nYou are given $D(4) = 30$ (since $a_1 = -1/30$), $D(308) = 20010$, $F(1) = 308$, $F(10) = 96404$.

\n\n

Find $F(10^5)$.

", "url": "https://projecteuler.net/problem=545", "answer": "921107572"} {"id": 546, "problem": "Define $f_k(n) = \\sum_{i=0}^n f_k(\\lfloor\\frac i k \\rfloor)$ where $f_k(0) = 1$ and $\\lfloor x \\rfloor$ denotes the floor function.\n\nFor example, $f_5(10) = 18$, $f_7(100) = 1003$, and $f_2(10^3) = 264830889564$.\n\nFind $(\\sum_{k=2}^{10} f_k(10^{14})) \\bmod (10^9+7)$.", "raw_html": "

Define $f_k(n) = \\sum_{i=0}^n f_k(\\lfloor\\frac i k \\rfloor)$ where $f_k(0) = 1$ and $\\lfloor x \\rfloor$ denotes the floor function.

\n\n

For example, $f_5(10) = 18$, $f_7(100) = 1003$, and $f_2(10^3) = 264830889564$.

\n\n

Find $(\\sum_{k=2}^{10} f_k(10^{14})) \\bmod (10^9+7)$.

", "url": "https://projecteuler.net/problem=546", "answer": "215656873"} {"id": 547, "problem": "Assuming that two points are chosen randomly (with uniform distribution) within a rectangle, it is possible to determine the expected value of the distance between these two points.\n\nFor example, the expected distance between two random points in a unit square is about $0.521405$, while the expected distance between two random points in a rectangle with side lengths $2$ and $3$ is about $1.317067$.\n\nNow we define a hollow square lamina of size $n$ to be an integer sized square with side length $n \\ge 3$ consisting of $n^2$ unit squares from which a rectangle consisting of $x \\times y$ unit squares ($1 \\le x,y \\le n - 2$) within the original square has been removed.\n\nFor $n = 3$ there exists only one hollow square lamina:\n\nFor $n = 4$ you can find $9$ distinct hollow square laminae, allowing shapes to reappear in rotated or mirrored form:\n\nLet $S(n)$ be the sum of the expected distance between two points chosen randomly within each of the possible hollow square laminae of size $n$. The two points have to lie within the area left after removing the inner rectangle, i.e. the gray-colored areas in the illustrations above.\n\nFor example, $S(3) = 1.6514$ and $S(4) = 19.6564$, rounded to four digits after the decimal point.\n\nFind $S(40)$ rounded to four digits after the decimal point.", "raw_html": "

Assuming that two points are chosen randomly (with uniform distribution) within a rectangle, it is possible to determine the expected value of the distance between these two points.

\n\n

For example, the expected distance between two random points in a unit square is about $0.521405$, while the expected distance between two random points in a rectangle with side lengths $2$ and $3$ is about $1.317067$.

\n\n

Now we define a hollow square lamina of size $n$ to be an integer sized square with side length $n \\ge 3$ consisting of $n^2$ unit squares from which a rectangle consisting of $x \\times y$ unit squares ($1 \\le x,y \\le n - 2$) within the original square has been removed.

\n\n

For $n = 3$ there exists only one hollow square lamina:

\n\n

\"0547-holes-1.png\"

\n\n

For $n = 4$ you can find $9$ distinct hollow square laminae, allowing shapes to reappear in rotated or mirrored form:

\n\n

\"0547-holes-2.png\"

\n\n

Let $S(n)$ be the sum of the expected distance between two points chosen randomly within each of the possible hollow square laminae of size $n$. The two points have to lie within the area left after removing the inner rectangle, i.e. the gray-colored areas in the illustrations above.

\n\n

For example, $S(3) = 1.6514$ and $S(4) = 19.6564$, rounded to four digits after the decimal point.

\n\n

Find $S(40)$ rounded to four digits after the decimal point.

", "url": "https://projecteuler.net/problem=547", "answer": "11730879.0023"} {"id": 548, "problem": "A gozinta chain for $n$ is a sequence $\\{1,a,b,\\dots,n\\}$ where each element properly divides the next.\n\nThere are eight gozinta chains for $12$:\n\n$\\{1,12\\}$, $\\{1,2,12\\}$, $\\{1,2,4,12\\}$, $\\{1,2,6,12\\}$, $\\{1,3,12\\}$, $\\{1,3,6,12\\}$, $\\{1,4,12\\}$ and $\\{1,6,12\\}$.\n\nLet $g(n)$ be the number of gozinta chains for $n$, so $g(12)=8$.\n\n$g(48)=48$ and $g(120)=132$.\n\nFind the sum of the numbers $n$ not exceeding $10^{16}$ for which $g(n)=n$.", "raw_html": "

\nA gozinta chain for $n$ is a sequence $\\{1,a,b,\\dots,n\\}$ where each element properly divides the next.
\nThere are eight gozinta chains for $12$:
\n$\\{1,12\\}$, $\\{1,2,12\\}$, $\\{1,2,4,12\\}$, $\\{1,2,6,12\\}$, $\\{1,3,12\\}$, $\\{1,3,6,12\\}$, $\\{1,4,12\\}$ and $\\{1,6,12\\}$.
\nLet $g(n)$ be the number of gozinta chains for $n$, so $g(12)=8$.
\n$g(48)=48$ and $g(120)=132$.\n

\n

\nFind the sum of the numbers $n$ not exceeding $10^{16}$ for which $g(n)=n$.\n

", "url": "https://projecteuler.net/problem=548", "answer": "12144044603581281"} {"id": 549, "problem": "The smallest number $m$ such that $10$ divides $m!$ is $m=5$.\n\nThe smallest number $m$ such that $25$ divides $m!$ is $m=10$.\n\n\nLet $s(n)$ be the smallest number $m$ such that $n$ divides $m!$.\n\nSo $s(10)=5$ and $s(25)=10$.\n\nLet $S(n)$ be $\\sum s(i)$ for $2 \\le i \\le n$.\n\n$S(100)=2012$.\n\nFind $S(10^8)$.", "raw_html": "

\nThe smallest number $m$ such that $10$ divides $m!$ is $m=5$.
\nThe smallest number $m$ such that $25$ divides $m!$ is $m=10$.
\n

\n

\nLet $s(n)$ be the smallest number $m$ such that $n$ divides $m!$.
\nSo $s(10)=5$ and $s(25)=10$.
\nLet $S(n)$ be $\\sum s(i)$ for $2 \\le i \\le n$.
\n$S(100)=2012$.\n

\n

\nFind $S(10^8)$.\n

", "url": "https://projecteuler.net/problem=549", "answer": "476001479068717"} {"id": 550, "problem": "Two players are playing a game, alternating turns. There are $k$ piles of stones.\nOn each turn, a player has to choose a pile and replace it with two piles of stones under the following two conditions:\n\n- Both new piles must have a number of stones more than one and less than the number of stones of the original pile.\n\n- The number of stones of each of the new piles must be a divisor of the number of stones of the original pile.\n\nThe first player unable to make a valid move loses.\n\nLet $f(n,k)$ be the number of winning positions for the first player, assuming perfect play, when the game is played with $k$ piles each having between $2$ and $n$ stones (inclusively).\n$f(10,5)=40085$.\n\nFind $f(10^7,10^{12})$.\nGive your answer modulo $987654321$.", "raw_html": "

\nTwo players are playing a game, alternating turns. There are $k$ piles of stones.\nOn each turn, a player has to choose a pile and replace it with two piles of stones under the following two conditions:\n

\n\n
  • Both new piles must have a number of stones more than one and less than the number of stones of the original pile.
  • \n
  • The number of stones of each of the new piles must be a divisor of the number of stones of the original pile.
\n\n

\nThe first player unable to make a valid move loses.\n
\nLet $f(n,k)$ be the number of winning positions for the first player, assuming perfect play, when the game is played with $k$ piles each having between $2$ and $n$ stones (inclusively).
$f(10,5)=40085$.\n

\n

\nFind $f(10^7,10^{12})$.
Give your answer modulo $987654321$.\n

", "url": "https://projecteuler.net/problem=550", "answer": "328104836"} {"id": 551, "problem": "Let $a_0, a_1, \\dots$ be an integer sequence defined by:\n\n- $a_0 = 1$;\n\n- for $n \\ge 1$, $a_n$ is the sum of the digits of all preceding terms.\n\nThe sequence starts with $1, 1, 2, 4, 8, 16, 23, 28, 38, 49, \\dots$\n\nYou are given $a_{10^6} = 31054319$.\n\nFind $a_{10^{15}}$.", "raw_html": "

Let $a_0, a_1, \\dots$ be an integer sequence defined by:

\n
    \n
  • $a_0 = 1$;
  • \n
  • for $n \\ge 1$, $a_n$ is the sum of the digits of all preceding terms.
  • \n
\n

The sequence starts with $1, 1, 2, 4, 8, 16, 23, 28, 38, 49, \\dots$
\nYou are given $a_{10^6} = 31054319$.

\n

Find $a_{10^{15}}$.

", "url": "https://projecteuler.net/problem=551", "answer": "73597483551591773"} {"id": 552, "problem": "Let $A_n$ be the smallest positive integer satisfying $A_n \\bmod p_i = i$ for all $1 \\le i \\le n$, where $p_i$ is the\n$i$-th prime.\n\nFor example $A_2 = 5$, since this is the smallest positive solution of the system of equations\n\n- $A_2 \\bmod 2 = 1$\n\n- $A_2 \\bmod 3 = 2$\n\nThe system of equations for $A_3$ adds another constraint. That is, $A_3$ is the smallest positive solution of\n\n- $A_3 \\bmod 2 = 1$\n\n- $A_3 \\bmod 3 = 2$\n\n- $A_3 \\bmod 5 = 3$\n\nand hence $A_3 = 23$. Similarly, one gets $A_4 = 53$ and $A_5 = 1523$.\n\nLet $S(n)$ be the sum of all primes up to $n$ that divide at least one element in the sequence $A$.\n\nFor example, $S(50) = 69 = 5 + 23 + 41$, since $5$ divides $A_2$, $23$ divides $A_3$ and $41$ divides $A_{10} = 5765999453$. No other prime number up to $50$ divides an element in $A$.\n\nFind $S(300000)$.", "raw_html": "

\nLet $A_n$ be the smallest positive integer satisfying $A_n \\bmod p_i = i$ for all $1 \\le i \\le n$, where $p_i$ is the\n$i$-th prime.\n
For example $A_2 = 5$, since this is the smallest positive solution of the system of equations

\n
  • $A_2 \\bmod 2 = 1$
  • \n
  • $A_2 \\bmod 3 = 2$
\n

\nThe system of equations for $A_3$ adds another constraint. That is, $A_3$ is the smallest positive solution of

\n
  • $A_3 \\bmod 2 = 1$
  • \n
  • $A_3 \\bmod 3 = 2$
  • \n
  • $A_3 \\bmod 5 = 3$
\n

\nand hence $A_3 = 23$. Similarly, one gets $A_4 = 53$ and $A_5 = 1523$.\n

\n

\nLet $S(n)$ be the sum of all primes up to $n$ that divide at least one element in the sequence $A$.\n
For example, $S(50) = 69 = 5 + 23 + 41$, since $5$ divides $A_2$, $23$ divides $A_3$ and $41$ divides $A_{10} = 5765999453$. No other prime number up to $50$ divides an element in $A$.\n

\n

\nFind $S(300000)$.

", "url": "https://projecteuler.net/problem=552", "answer": "326227335"} {"id": 553, "problem": "Let $P(n)$ be the set of the first $n$ positive integers $\\{1, 2, \\dots, n\\}$.\n\nLet $Q(n)$ be the set of all the non-empty subsets of $P(n)$.\n\nLet $R(n)$ be the set of all the non-empty subsets of $Q(n)$.\n\nAn element $X \\in R(n)$ is a non-empty subset of $Q(n)$, so it is itself a set.\n\nFrom $X$ we can construct a graph as follows:\n\n- Each element $Y \\in X$ corresponds to a vertex and labeled with $Y$;\n\n- Two vertices $Y_1$ and $Y_2$ are connected if $Y_1 \\cap Y_2 \\ne \\emptyset$.\n\nFor example, $X = \\{\\{1\\},\\{1,2,3\\},\\{3\\},\\{5,6\\},\\{6,7\\}\\}$ results in the following graph:\n\nThis graph has two connected components.\n\nLet $C(n, k)$ be the number of elements of $R(n)$ that have exactly $k$ connected components in their graph.\n\nYou are given $C(2, 1) = 6$, $C(3, 1) = 111$, $C(4, 2) = 486$, $C(100, 10) \\bmod 1\\,000\\,000\\,007 = 728209718$.\n\nFind $C(10^4, 10) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Let $P(n)$ be the set of the first $n$ positive integers $\\{1, 2, \\dots, n\\}$.
\nLet $Q(n)$ be the set of all the non-empty subsets of $P(n)$.
\nLet $R(n)$ be the set of all the non-empty subsets of $Q(n)$.

\n\n

An element $X \\in R(n)$ is a non-empty subset of $Q(n)$, so it is itself a set.
\nFrom $X$ we can construct a graph as follows:

\n\n
    \n
  • Each element $Y \\in X$ corresponds to a vertex and labeled with $Y$;
  • \n
  • Two vertices $Y_1$ and $Y_2$ are connected if $Y_1 \\cap Y_2 \\ne \\emptyset$.
  • \n
\n\n

For example, $X = \\{\\{1\\},\\{1,2,3\\},\\{3\\},\\{5,6\\},\\{6,7\\}\\}$ results in the following graph:

\n\n
\"0553-power-sets.gif\"
\n\n

This graph has two connected components.

\n\n

Let $C(n, k)$ be the number of elements of $R(n)$ that have exactly $k$ connected components in their graph.
\nYou are given $C(2, 1) = 6$, $C(3, 1) = 111$, $C(4, 2) = 486$, $C(100, 10) \\bmod 1\\,000\\,000\\,007 = 728209718$.

\n\n

Find $C(10^4, 10) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=553", "answer": "57717170"} {"id": 554, "problem": "On a chess board, a centaur moves like a king or a knight. The diagram below shows the valid moves of a centaur (represented by an inverted king) on an $8 \\times 8$ board.\n\nIt can be shown that at most $n^2$ non-attacking centaurs can be placed on a board of size $2n \\times 2n$.\n\nLet $C(n)$ be the number of ways to place $n^2$ centaurs on a $2n \\times 2n$ board so that no centaur attacks another directly.\n\nFor example $C(1) = 4$, $C(2) = 25$, $C(10) = 1477721$.\n\nLet $F_i$ be the $i$th Fibonacci number defined as $F_1 = F_2 = 1$ and $F_i = F_{i - 1} + F_{i - 2}$ for $i \\gt 2$.\n\nFind $\\displaystyle \\left( \\sum_{i=2}^{90} C(F_i) \\right) \\bmod (10^8+7)$.", "raw_html": "

On a chess board, a centaur moves like a king or a knight. The diagram below shows the valid moves of a centaur (represented by an inverted king) on an $8 \\times 8$ board.

\n\n
\"0554-centaurs.png\"
\n\n

It can be shown that at most $n^2$ non-attacking centaurs can be placed on a board of size $2n \\times 2n$.
\nLet $C(n)$ be the number of ways to place $n^2$ centaurs on a $2n \\times 2n$ board so that no centaur attacks another directly.
\nFor example $C(1) = 4$, $C(2) = 25$, $C(10) = 1477721$.

\n\n

Let $F_i$ be the $i$th Fibonacci number defined as $F_1 = F_2 = 1$ and $F_i = F_{i - 1} + F_{i - 2}$ for $i \\gt 2$.

\n\n

Find $\\displaystyle \\left( \\sum_{i=2}^{90} C(F_i) \\right) \\bmod (10^8+7)$.

", "url": "https://projecteuler.net/problem=554", "answer": "89539872"} {"id": 555, "problem": "The McCarthy 91 function is defined as follows:\n$$\nM_{91}(n) =\n\\begin{cases}\nn - 10 & \\text{if } n > 100 \\\\\nM_{91}(M_{91}(n+11)) & \\text{if } 0 \\leq n \\leq 100\n\\end{cases}\n$$\n\nWe can generalize this definition by abstracting away the constants into new variables:\n\n$$\nM_{m,k,s}(n) =\n\\begin{cases}\nn - s & \\text{if } n > m \\\\\nM_{m,k,s}(M_{m,k,s}(n+k)) & \\text{if } 0 \\leq n \\leq m\n\\end{cases}\n$$\n\nThis way, we have $M_{91} = M_{100,11,10}$.\n\nLet $F_{m,k,s}$ be the set of fixed points of $M_{m,k,s}$. That is,\n\n$$F_{m,k,s}= \\left\\{ n \\in \\mathbb{N} \\, | \\, M_{m,k,s}(n) = n \\right\\}$$\n\nFor example, the only fixed point of $M_{91}$ is $n = 91$. In other words, $F_{100,11,10}= \\{91\\}$.\n\n\n\nNow, define $SF(m,k,s)$ as the sum of the elements in $F_{m,k,s}$ and let $S(p,m) = \\displaystyle \\sum_{1 \\leq s < k \\leq p}{SF(m,k,s)}$.\n\nFor example, $S(10, 10) = 225$ and $S(1000, 1000)=208724467$.\n\nFind $S(10^6, 10^6)$.", "raw_html": "

\nThe McCarthy 91 function is defined as follows:\n$$\nM_{91}(n) = \n \\begin{cases}\n n - 10 & \\text{if } n > 100 \\\\\n M_{91}(M_{91}(n+11)) & \\text{if } 0 \\leq n \\leq 100\n \\end{cases}\n$$\n

\n

\nWe can generalize this definition by abstracting away the constants into new variables:\n\n$$\nM_{m,k,s}(n) = \n \\begin{cases}\n n - s & \\text{if } n > m \\\\\n M_{m,k,s}(M_{m,k,s}(n+k)) & \\text{if } 0 \\leq n \\leq m\n \\end{cases}\n$$\n

\n

\nThis way, we have $M_{91} = M_{100,11,10}$.\n

\n

\nLet $F_{m,k,s}$ be the set of fixed points of $M_{m,k,s}$. That is, \n\n$$F_{m,k,s}= \\left\\{ n \\in \\mathbb{N} \\, | \\, M_{m,k,s}(n) = n \\right\\}$$\n

\n

\nFor example, the only fixed point of $M_{91}$ is $n = 91$. In other words, $F_{100,11,10}= \\{91\\}$.\n

\n

\nNow, define $SF(m,k,s)$ as the sum of the elements in $F_{m,k,s}$ and let $S(p,m) = \\displaystyle \\sum_{1 \\leq s < k \\leq p}{SF(m,k,s)}$.\n

\n

\nFor example, $S(10, 10) = 225$ and $S(1000, 1000)=208724467$.\n

\n

\nFind $S(10^6, 10^6)$.\n

", "url": "https://projecteuler.net/problem=555", "answer": "208517717451208352"} {"id": 556, "problem": "A Gaussian integer is a number $z = a + bi$ where $a$, $b$ are integers and $i^2 = -1$.\n\nGaussian integers are a subset of the complex numbers, and the integers are the subset of Gaussian integers for which $b = 0$.\n\nA Gaussian integer unit is one for which $a^2 + b^2 = 1$, i.e. one of $1, i, -1, -i$.\n\nLet's define a proper Gaussian integer as one for which $a \\gt 0$ and $b \\ge 0$.\n\nA Gaussian integer $z_1 = a_1 + b_1 i$ is said to be divisible by $z_2 = a_2 + b_2 i$ if $z_3 = a_3 + b_3 i = z_1 / z_2$ is a Gaussian integer.\n\n$\\frac {z_1} {z_2} = \\frac {a_1 + b_1 i} {a_2 + b_2 i} = \\frac {(a_1 + b_1 i)(a_2 - b_2 i)} {(a_2 + b_2 i)(a_2 - b_2 i)} = \\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2} + \\frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}i = a_3 + b_3 i$\n\nSo, $z_1$ is divisible by $z_2$ if $\\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2}$ and $\\frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}$ are integers.\n\nFor example, $2$ is divisible by $1 + i$ because $2/(1 + i) = 1 - i$ is a Gaussian integer.\n\nA Gaussian prime is a Gaussian integer that is divisible only by a unit, itself or itself times a unit.\n\nFor example, $1 + 2i$ is a Gaussian prime, because it is only divisible by $1$, $i$, $-1$, $-i$, $1 + 2i$, $i(1 + 2i) = i - 2$, $-(1 + 2i) = -1 - 2i$ and $-i(1 + 2i) = 2 - i$.\n\n$2$ is not a Gaussian prime as it is divisible by $1 + i$.\n\nA Gaussian integer can be uniquely factored as the product of a unit and proper Gaussian primes.\n\nFor example $2 = -i(1 + i)^2$ and $1 + 3i = (1 + i)(2 + i)$.\n\nA Gaussian integer is said to be squarefree if its prime factorization does not contain repeated proper Gaussian primes.\n\nSo $2$ is not squarefree over the Gaussian integers, but $1 + 3i$ is.\n\nUnits and Gaussian primes are squarefree by definition.\n\nLet $f(n)$ be the count of proper squarefree Gaussian integers with $a^2 + b^2 \\le n$.\n\nFor example $f(10) = 7$ because $1$, $1 + i$, $1 + 2i$, $1 + 3i = (1 + i)(2 + i)$, $2 + i$, $3$ and $3 + i = -i(1 + i)(1 + 2i)$ are squarefree, while $2 = -i(1 + i)^2$ and $2 + 2i = -i(1 + i)^3$ are not.\n\nYou are given $f(10^2) = 54$, $f(10^4) = 5218$ and $f(10^8) = 52126906$.\n\nFind $f(10^{14})$.", "raw_html": "

A Gaussian integer is a number $z = a + bi$ where $a$, $b$ are integers and $i^2 = -1$.
\nGaussian integers are a subset of the complex numbers, and the integers are the subset of Gaussian integers for which $b = 0$.

\n\n

A Gaussian integer unit is one for which $a^2 + b^2 = 1$, i.e. one of $1, i, -1, -i$.
\nLet's define a proper Gaussian integer as one for which $a \\gt 0$ and $b \\ge 0$.

\n\n

A Gaussian integer $z_1 = a_1 + b_1 i$ is said to be divisible by $z_2 = a_2 + b_2 i$ if $z_3 = a_3 + b_3 i = z_1 / z_2$ is a Gaussian integer.
\n$\\frac {z_1} {z_2} = \\frac {a_1 + b_1 i} {a_2 + b_2 i} = \\frac {(a_1 + b_1 i)(a_2 - b_2 i)} {(a_2 + b_2 i)(a_2 - b_2 i)} = \\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2} + \\frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}i = a_3 + b_3 i$
\nSo, $z_1$ is divisible by $z_2$ if $\\frac {a_1 a_2 + b_1 b_2} {a_2^2 + b_2^2}$ and $\\frac {a_2 b_1 - a_1 b_2} {a_2^2 + b_2^2}$ are integers.
\nFor example, $2$ is divisible by $1 + i$ because $2/(1 + i) = 1 - i$ is a Gaussian integer.

\n\n

A Gaussian prime is a Gaussian integer that is divisible only by a unit, itself or itself times a unit.
\nFor example, $1 + 2i$ is a Gaussian prime, because it is only divisible by $1$, $i$, $-1$, $-i$, $1 + 2i$, $i(1 + 2i) = i - 2$, $-(1 + 2i) = -1 - 2i$ and $-i(1 + 2i) = 2 - i$.
\n$2$ is not a Gaussian prime as it is divisible by $1 + i$.

\n\n

A Gaussian integer can be uniquely factored as the product of a unit and proper Gaussian primes.
\nFor example $2 = -i(1 + i)^2$ and $1 + 3i = (1 + i)(2 + i)$.
\nA Gaussian integer is said to be squarefree if its prime factorization does not contain repeated proper Gaussian primes.
\nSo $2$ is not squarefree over the Gaussian integers, but $1 + 3i$ is.
\nUnits and Gaussian primes are squarefree by definition.

\n\n

Let $f(n)$ be the count of proper squarefree Gaussian integers with $a^2 + b^2 \\le n$.
\nFor example $f(10) = 7$ because $1$, $1 + i$, $1 + 2i$, $1 + 3i = (1 + i)(2 + i)$, $2 + i$, $3$ and $3 + i = -i(1 + i)(1 + 2i)$ are squarefree, while $2 = -i(1 + i)^2$ and $2 + 2i = -i(1 + i)^3$ are not.
\nYou are given $f(10^2) = 54$, $f(10^4) = 5218$ and $f(10^8) = 52126906$.

\n\n

Find $f(10^{14})$.

", "url": "https://projecteuler.net/problem=556", "answer": "52126939292957"} {"id": 557, "problem": "A triangle is cut into four pieces by two straight lines, each starting at one vertex and ending on the opposite edge. This results in forming three smaller triangular pieces, and one quadrilateral. If the original triangle has an integral area, it is often possible to choose cuts such that all of the four pieces also have integral area. For example, the diagram below shows a triangle of area $55$ that has been cut in this way.\n\nRepresenting the areas as $a, b, c$ and $d$, in the example above, the individual areas are $a = 22$, $b = 8$, $c = 11$ and $d = 14$. It is also possible to cut a triangle of area $55$ such that $a = 20$, $b = 2$, $c = 24$, $d = 9$.\n\nDefine a triangle cutting quadruple $(a, b, c, d)$ as a valid integral division of a triangle, where $a$ is the area of the triangle between the two cut vertices, $d$ is the area of the quadrilateral and $b$ and $c$ are the areas of the two other triangles, with the restriction that $b \\le c$. The two solutions described above are $(22,8,11,14)$ and $(20,2,24,9)$. These are the only two possible quadruples that have a total area of $55$.\n\nDefine $S(n)$ as the sum of the area of the uncut triangles represented by all valid quadruples with $a+b+c+d \\le n$.\nFor example, $S(20) = 259$.\n\nFind $S(10000)$.", "raw_html": "

\nA triangle is cut into four pieces by two straight lines, each starting at one vertex and ending on the opposite edge. This results in forming three smaller triangular pieces, and one quadrilateral. If the original triangle has an integral area, it is often possible to choose cuts such that all of the four pieces also have integral area. For example, the diagram below shows a triangle of area $55$ that has been cut in this way.\n

\n
\"0557-triangle.gif\"
\n

\nRepresenting the areas as $a, b, c$ and $d$, in the example above, the individual areas are $a = 22$, $b = 8$, $c = 11$ and $d = 14$. It is also possible to cut a triangle of area $55$ such that $a = 20$, $b = 2$, $c = 24$, $d = 9$.

\n

\nDefine a triangle cutting quadruple $(a, b, c, d)$ as a valid integral division of a triangle, where $a$ is the area of the triangle between the two cut vertices, $d$ is the area of the quadrilateral and $b$ and $c$ are the areas of the two other triangles, with the restriction that $b \\le c$. The two solutions described above are $(22,8,11,14)$ and $(20,2,24,9)$. These are the only two possible quadruples that have a total area of $55$.\n

\n

\nDefine $S(n)$ as the sum of the area of the uncut triangles represented by all valid quadruples with $a+b+c+d \\le n$.
For example, $S(20) = 259$. \n

\n

\nFind $S(10000)$.\n

", "url": "https://projecteuler.net/problem=557", "answer": "2699929328"} {"id": 558, "problem": "Let $r$ be the real root of the equation $x^3 = x^2 + 1$.\n\nEvery positive integer can be written as the sum of distinct increasing powers of $r$.\n\nIf we require the number of terms to be finite and the difference between any two exponents to be three or more, then the representation is unique.\n\nFor example, $3 = r^{-10} + r^{-5} + r^{-1} + r^2$ and $10 = r^{-10} + r^{-7} + r^6$.\n\nInterestingly, the relation holds for the complex roots of the equation.\n\nLet $w(n)$ be the number of terms in this unique representation of $n$. Thus $w(3) = 4$ and $w(10) = 3$.\n\nMore formally, for all positive integers $n$, we have:\n\n$n = \\displaystyle \\sum_{k=-\\infty}^\\infty b_k r^k$\n\nunder the conditions that:\n\n$b_k$ is $0$ or $1$ for all $k$;\n\n$b_k + b_{k + 1} + b_{k + 2} \\le 1$ for all $k$;\n\n$w(n) = \\displaystyle \\sum_{k=-\\infty}^\\infty b_k$ is finite.\n\nLet $S(m) = \\displaystyle \\sum_{j=1}^m w(j^2)$.\n\nYou are given $S(10) = 61$ and $S(1000) = 19403$.\n\nFind $S(5\\,000\\,000)$.", "raw_html": "

Let $r$ be the real root of the equation $x^3 = x^2 + 1$.
\nEvery positive integer can be written as the sum of distinct increasing powers of $r$.
\nIf we require the number of terms to be finite and the difference between any two exponents to be three or more, then the representation is unique.
\nFor example, $3 = r^{-10} + r^{-5} + r^{-1} + r^2$ and $10 = r^{-10} + r^{-7} + r^6$.
\nInterestingly, the relation holds for the complex roots of the equation.

\n\n

Let $w(n)$ be the number of terms in this unique representation of $n$. Thus $w(3) = 4$ and $w(10) = 3$.

\n\n

More formally, for all positive integers $n$, we have:
\n$n = \\displaystyle \\sum_{k=-\\infty}^\\infty b_k r^k$
\nunder the conditions that:
\n$b_k$ is $0$ or $1$ for all $k$;
\n$b_k + b_{k + 1} + b_{k + 2} \\le 1$ for all $k$;
\n$w(n) = \\displaystyle \\sum_{k=-\\infty}^\\infty b_k$ is finite.

\n\n

Let $S(m) = \\displaystyle \\sum_{j=1}^m w(j^2)$.
\nYou are given $S(10) = 61$ and $S(1000) = 19403$.

\n\n

Find $S(5\\,000\\,000)$.

", "url": "https://projecteuler.net/problem=558", "answer": "226754889"} {"id": 559, "problem": "An ascent of a column $j$ in a matrix occurs if the value of column $j$ is smaller than the value of column $j + 1$ in all rows.\n\nLet $P(k, r, n)$ be the number of $r \\times n$ matrices with the following properties:\n\n- The rows are permutations of $\\{1, 2, 3, \\dots, n\\}$.\n\n- Numbering the first column as $1$, a column ascent occurs at column $j \\lt n$ if and only if $j$ is not a multiple of $k$.\n\nFor example, $P(1, 2, 3) = 19$, $P(2, 4, 6) = 65508751$ and $P(7, 5, 30) \\bmod 1000000123 = 161858102$.\n\nLet $Q(n) = \\displaystyle \\sum_{k=1}^n P(k, n, n)$.\n\nFor example, $Q(5) = 21879393751$ and $Q(50) \\bmod 1000000123 = 819573537$.\n\nFind $Q(50000) \\bmod 1000000123$.", "raw_html": "

An ascent of a column $j$ in a matrix occurs if the value of column $j$ is smaller than the value of column $j + 1$ in all rows.\n

\nLet $P(k, r, n)$ be the number of $r \\times n$ matrices with the following properties:

\n\n
  • The rows are permutations of $\\{1, 2, 3, \\dots, n\\}$.
  • \n
  • Numbering the first column as $1$, a column ascent occurs at column $j \\lt n$ if and only if $j$ is not a multiple of $k$.
  • \n\n

For example, $P(1, 2, 3) = 19$, $P(2, 4, 6) = 65508751$ and $P(7, 5, 30) \\bmod 1000000123 = 161858102$.

\n\nLet $Q(n) = \\displaystyle \\sum_{k=1}^n P(k, n, n)$.
\nFor example, $Q(5) = 21879393751$ and $Q(50) \\bmod 1000000123 = 819573537$.\n\n

Find $Q(50000) \\bmod 1000000123$.

", "url": "https://projecteuler.net/problem=559", "answer": "684724920"} {"id": 560, "problem": "Coprime Nim is just like ordinary normal play Nim, but the players may only remove a number of stones from a pile that is coprime with the current size of the pile. Two players remove stones in turn. The player who removes the last stone wins.\n\nLet $L(n, k)$ be the number of losing starting positions for the first player, assuming perfect play, when the game is played with $k$ piles, each having between $1$ and $n - 1$ stones inclusively.\n\nFor example, $L(5, 2) = 6$ since the losing initial positions are $(1, 1)$, $(2, 2)$, $(2, 4)$, $(3, 3)$, $(4, 2)$ and $(4, 4)$.\n\nYou are also given $L(10, 5) = 9964$, $L(10, 10) = 472400303$, $L(10^3, 10^3) \\bmod 1\\,000\\,000\\,007 = 954021836$.\n\nFind $L(10^7, 10^7)\\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Coprime Nim is just like ordinary normal play Nim, but the players may only remove a number of stones from a pile that is coprime with the current size of the pile. Two players remove stones in turn. The player who removes the last stone wins.

\n\n

Let $L(n, k)$ be the number of losing starting positions for the first player, assuming perfect play, when the game is played with $k$ piles, each having between $1$ and $n - 1$ stones inclusively.

\n\n

For example, $L(5, 2) = 6$ since the losing initial positions are $(1, 1)$, $(2, 2)$, $(2, 4)$, $(3, 3)$, $(4, 2)$ and $(4, 4)$.
\nYou are also given $L(10, 5) = 9964$, $L(10, 10) = 472400303$, $L(10^3, 10^3) \\bmod 1\\,000\\,000\\,007 = 954021836$.

\n\n

Find $L(10^7, 10^7)\\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=560", "answer": "994345168"} {"id": 561, "problem": "Let $S(n)$ be the number of pairs $(a,b)$ of distinct divisors of $n$ such that $a$ divides $b$.\n\nFor $n=6$ we get the following pairs: $(1,2), (1,3), (1,6),( 2,6)$ and $(3,6)$. So $S(6)=5$.\n\nLet $p_m\\#$ be the product of the first $m$ prime numbers, so $p_2\\# = 2*3 = 6$.\n\nLet $E(m, n)$ be the highest integer $k$ such that $2^k$ divides $S((p_m\\#)^n)$.\n\n$E(2,1) = 0$ since $2^0$ is the highest power of 2 that divides S(6)=5.\n\nLet $Q(n)=\\sum_{i=1}^{n} E(904961, i)$\n\n$Q(8)=2714886$.\n\nEvaluate $Q(10^{12})$.", "raw_html": "

\nLet $S(n)$ be the number of pairs $(a,b)$ of distinct divisors of $n$ such that $a$ divides $b$.
\nFor $n=6$ we get the following pairs: $(1,2), (1,3), (1,6),( 2,6)$ and $(3,6)$. So $S(6)=5$.
\nLet $p_m\\#$ be the product of the first $m$ prime numbers, so $p_2\\# = 2*3 = 6$.
\nLet $E(m, n)$ be the highest integer $k$ such that $2^k$ divides $S((p_m\\#)^n)$.
\n$E(2,1) = 0$ since $2^0$ is the highest power of 2 that divides S(6)=5.
\nLet $Q(n)=\\sum_{i=1}^{n} E(904961, i)$
\n$Q(8)=2714886$.\n

\n

\nEvaluate $Q(10^{12})$. \n

", "url": "https://projecteuler.net/problem=561", "answer": "452480999988235494"} {"id": 562, "problem": "Construct triangle $ABC$ such that:\n\n- Vertices $A$, $B$ and $C$ are lattice points inside or on the circle of radius $r$ centered at the origin;\n\n- the triangle contains no other lattice point inside or on its edges;\n\n- the perimeter is maximum.\n\nLet $R$ be the circumradius of triangle $ABC$ and $T(r) = R/r$.\n\nFor $r = 5$, one possible triangle has vertices $(-4,-3)$, $(4,2)$ and $(1,0)$ with perimeter $\\sqrt{13}+\\sqrt{34}+\\sqrt{89}$ and circumradius $R = \\sqrt {\\frac {19669} 2 }$, so $T(5) = \\sqrt {\\frac {19669} {50} }$.\n\nYou are given $T(10) \\approx 97.26729$ and $T(100) \\approx 9157.64707$.\n\nFind $T(10^7)$. Give your answer rounded to the nearest integer.", "raw_html": "

Construct triangle $ABC$ such that:

\n
  • Vertices $A$, $B$ and $C$ are lattice points inside or on the circle of radius $r$ centered at the origin;
  • \n
  • the triangle contains no other lattice point inside or on its edges;
  • \n
  • the perimeter is maximum.
\n

Let $R$ be the circumradius of triangle $ABC$ and $T(r) = R/r$.
\nFor $r = 5$, one possible triangle has vertices $(-4,-3)$, $(4,2)$ and $(1,0)$ with perimeter $\\sqrt{13}+\\sqrt{34}+\\sqrt{89}$ and circumradius $R = \\sqrt {\\frac {19669} 2 }$, so $T(5) = \\sqrt {\\frac {19669} {50} }$.
\nYou are given $T(10) \\approx 97.26729$ and $T(100) \\approx 9157.64707$.

\n\n

Find $T(10^7)$. Give your answer rounded to the nearest integer.

", "url": "https://projecteuler.net/problem=562", "answer": "51208732914368"} {"id": 563, "problem": "A company specialises in producing large rectangular metal sheets, starting from unit square metal plates. The welding is performed by a range of robots of increasing size. Unfortunately, the programming options of these robots are rather limited. Each one can only process up to $25$ identical rectangles of metal, which they can weld along either edge to produce a larger rectangle. The only programmable variables are the number of rectangles to be processed (up to and including $25$), and whether to weld the long or short edge.\n\nFor example, the first robot could be programmed to weld together $11$ raw unit square plates to make a $11 \\times 1$ strip. The next could take $10$ of these $11 \\times 1$ strips, and weld them either to make a longer $110 \\times 1$ strip, or a $11 \\times 10$ rectangle. Many, but not all, possible dimensions of metal sheets can be constructed in this way.\n\nOne regular customer has a particularly unusual order: The finished product should have an exact area, and the long side must not be more than $10\\%$ larger than the short side. If these requirements can be met in more than one way, in terms of the exact dimensions of the two sides, then the customer will demand that all variants be produced. For example, if the order calls for a metal sheet of area $889200$, then there are three final dimensions that can be produced: $900 \\times 988$, $912 \\times 975$ and $936 \\times 950$. The target area of $889200$ is the smallest area which can be manufactured in three different variants, within the limitations of the robot welders.\n\nLet $M(n)$ be the minimal area that can be manufactured in exactly $n$ variants with the longer edge not greater than $10\\%$ bigger than the shorter edge. Hence $M(3) = 889200$.\n\nFind $\\sum_{n=2}^{100} M(n)$.", "raw_html": "

A company specialises in producing large rectangular metal sheets, starting from unit square metal plates. The welding is performed by a range of robots of increasing size. Unfortunately, the programming options of these robots are rather limited. Each one can only process up to $25$ identical rectangles of metal, which they can weld along either edge to produce a larger rectangle. The only programmable variables are the number of rectangles to be processed (up to and including $25$), and whether to weld the long or short edge.

\n\n

For example, the first robot could be programmed to weld together $11$ raw unit square plates to make a $11 \\times 1$ strip. The next could take $10$ of these $11 \\times 1$ strips, and weld them either to make a longer $110 \\times 1$ strip, or a $11 \\times 10$ rectangle. Many, but not all, possible dimensions of metal sheets can be constructed in this way.

\n\n

One regular customer has a particularly unusual order: The finished product should have an exact area, and the long side must not be more than $10\\%$ larger than the short side. If these requirements can be met in more than one way, in terms of the exact dimensions of the two sides, then the customer will demand that all variants be produced. For example, if the order calls for a metal sheet of area $889200$, then there are three final dimensions that can be produced: $900 \\times 988$, $912 \\times 975$ and $936 \\times 950$. The target area of $889200$ is the smallest area which can be manufactured in three different variants, within the limitations of the robot welders.

\n\n

Let $M(n)$ be the minimal area that can be manufactured in exactly $n$ variants with the longer edge not greater than $10\\%$ bigger than the shorter edge. Hence $M(3) = 889200$.

\n\n

Find $\\sum_{n=2}^{100} M(n)$.

", "url": "https://projecteuler.net/problem=563", "answer": "27186308211734760"} {"id": 564, "problem": "A line segment of length $2n-3$ is randomly split into $n$ segments of integer length ($n \\ge 3$). In the sequence given by this split, the segments are then used as consecutive sides of a convex $n$-polygon, formed in such a way that its area is maximal. All of the $\\binom{2n-4} {n-1}$ possibilities for splitting up the initial line segment occur with the same probability.\n\nLet $E(n)$ be the expected value of the area that is obtained by this procedure.\n\nFor example, for $n=3$ the only possible split of the line segment of length $3$ results in three line segments with length $1$, that form an equilateral triangle with an area of $\\frac 1 4 \\sqrt{3}$. Therefore $E(3)=0.433013$, rounded to $6$ decimal places.\n\nFor $n=4$ you can find $4$ different possible splits, each of which is composed of three line segments with length $1$ and one line segment with length $2$. All of these splits lead to the same maximal quadrilateral with an area of $\\frac 3 4 \\sqrt{3}$, thus $E(4)=1.299038$, rounded to $6$ decimal places.\n\nLet $S(k)=\\displaystyle \\sum_{n=3}^k E(n)$.\n\nFor example, $S(3)=0.433013$, $S(4)=1.732051$, $S(5)=4.604767$ and $S(10)=66.955511$, rounded to $6$ decimal places each.\n\nFind $S(50)$, rounded to $6$ decimal places.", "raw_html": "

A line segment of length $2n-3$ is randomly split into $n$ segments of integer length ($n \\ge 3$). In the sequence given by this split, the segments are then used as consecutive sides of a convex $n$-polygon, formed in such a way that its area is maximal. All of the $\\binom{2n-4} {n-1}$ possibilities for splitting up the initial line segment occur with the same probability.

\n\n

Let $E(n)$ be the expected value of the area that is obtained by this procedure.
\nFor example, for $n=3$ the only possible split of the line segment of length $3$ results in three line segments with length $1$, that form an equilateral triangle with an area of $\\frac 1 4 \\sqrt{3}$. Therefore $E(3)=0.433013$, rounded to $6$ decimal places.
\nFor $n=4$ you can find $4$ different possible splits, each of which is composed of three line segments with length $1$ and one line segment with length $2$. All of these splits lead to the same maximal quadrilateral with an area of $\\frac 3 4 \\sqrt{3}$, thus $E(4)=1.299038$, rounded to $6$ decimal places.

\n\n

Let $S(k)=\\displaystyle \\sum_{n=3}^k E(n)$.
\nFor example, $S(3)=0.433013$, $S(4)=1.732051$, $S(5)=4.604767$ and $S(10)=66.955511$, rounded to $6$ decimal places each.

\n\n

Find $S(50)$, rounded to $6$ decimal places.

", "url": "https://projecteuler.net/problem=564", "answer": "12363.698850"} {"id": 565, "problem": "Let $\\sigma(n)$ be the sum of the divisors of $n$.\n\nE.g. the divisors of $4$ are $1$, $2$ and $4$, so $\\sigma(4)=7$.\n\nThe numbers $n$ not exceeding $20$ such that $7$ divides $\\sigma(n)$ are: $4$, $12$, $13$ and $20$, the sum of these numbers being $49$.\n\nLet $S(n, d)$ be the sum of the numbers $i$ not exceeding $n$ such that $d$ divides $\\sigma(i)$.\n\nSo $S(20 , 7)=49$.\n\nYou are given: $S(10^6,2017)=150850429$ and $S(10^9, 2017)=249652238344557$.\n\nFind $S(10^{11}, 2017)$.", "raw_html": "

Let $\\sigma(n)$ be the sum of the divisors of $n$.
\nE.g. the divisors of $4$ are $1$, $2$ and $4$, so $\\sigma(4)=7$.\n

\n

\nThe numbers $n$ not exceeding $20$ such that $7$ divides $\\sigma(n)$ are: $4$, $12$, $13$ and $20$, the sum of these numbers being $49$.\n

\n

\nLet $S(n, d)$ be the sum of the numbers $i$ not exceeding $n$ such that $d$ divides $\\sigma(i)$.
\nSo $S(20 , 7)=49$.\n

\n

\nYou are given: $S(10^6,2017)=150850429$ and $S(10^9, 2017)=249652238344557$.\n

\n

\nFind $S(10^{11}, 2017)$.\n

", "url": "https://projecteuler.net/problem=565", "answer": "2992480851924313898"} {"id": 566, "problem": "Adam plays the following game with his birthday cake.\n\nHe cuts a piece forming a circular sector of $60$ degrees and flips the piece upside down, with the icing on the bottom.\n\nHe then rotates the cake by $60$ degrees counterclockwise, cuts an adjacent $60$ degree piece and flips it upside down.\n\nHe keeps repeating this, until after a total of twelve steps, all the icing is back on top.\n\nAmazingly, this works for any piece size, even if the cutting angle is an irrational number: all the icing will be back on top after a finite number of steps.\n\nNow, Adam tries something different: he alternates cutting pieces of size $x=\\frac{360}{9}$ degrees, $y=\\frac{360}{10}$ degrees and $z=\\frac{360 }{\\sqrt{11}}$ degrees. The first piece he cuts has size $x$ and he flips it. The second has size $y$ and he flips it. The third has size $z$ and he flips it. He repeats this with pieces of size $x$, $y$ and $z$ in that order until all the icing is back on top, and discovers he needs $60$ flips altogether.\n\nLet $F(a, b, c)$ be the minimum number of piece flips needed to get all the icing back on top for pieces of size $x=\\frac{360}{a}$ degrees, $y=\\frac{360}{b}$ degrees and $z=\\frac{360}{\\sqrt{c}}$ degrees.\n\nLet $G(n) = \\sum_{9 \\le a \\lt b \\lt c \\le n} F(a,b,c)$, for integers $a$, $b$ and $c$.\n\nYou are given that $F(9, 10, 11) = 60$, $F(10, 14, 16) = 506$, $F(15, 16, 17) = 785232$.\n\nYou are also given $G(11) = 60$, $G(14) = 58020$ and $G(17) = 1269260$.\n\nFind $G(53)$.", "raw_html": "

Adam plays the following game with his birthday cake.

\n\n

He cuts a piece forming a circular sector of $60$ degrees and flips the piece upside down, with the icing on the bottom.
\nHe then rotates the cake by $60$ degrees counterclockwise, cuts an adjacent $60$ degree piece and flips it upside down.
\nHe keeps repeating this, until after a total of twelve steps, all the icing is back on top.

\n\n

Amazingly, this works for any piece size, even if the cutting angle is an irrational number: all the icing will be back on top after a finite number of steps.

\n\n

Now, Adam tries something different: he alternates cutting pieces of size $x=\\frac{360}{9}$ degrees, $y=\\frac{360}{10}$ degrees and $z=\\frac{360 }{\\sqrt{11}}$ degrees. The first piece he cuts has size $x$ and he flips it. The second has size $y$ and he flips it. The third has size $z$ and he flips it. He repeats this with pieces of size $x$, $y$ and $z$ in that order until all the icing is back on top, and discovers he needs $60$ flips altogether.

\n\n
\"0566-cakeicingpuzzle.gif\"
\n\n

Let $F(a, b, c)$ be the minimum number of piece flips needed to get all the icing back on top for pieces of size $x=\\frac{360}{a}$ degrees, $y=\\frac{360}{b}$ degrees and $z=\\frac{360}{\\sqrt{c}}$ degrees.
\nLet $G(n) = \\sum_{9 \\le a \\lt b \\lt c \\le n} F(a,b,c)$, for integers $a$, $b$ and $c$.

\n\n

You are given that $F(9, 10, 11) = 60$, $F(10, 14, 16) = 506$, $F(15, 16, 17) = 785232$.
\nYou are also given $G(11) = 60$, $G(14) = 58020$ and $G(17) = 1269260$.

\n\n

Find $G(53)$.

", "url": "https://projecteuler.net/problem=566", "answer": "329569369413585"} {"id": 567, "problem": "Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\\frac 1 2$, independently of its former state or the state of the other light bulbs.\n\nWhile discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:\n\nBoth games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\\frac 1 k$.\n\nIn game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.\n\nFor each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.\n\nLet $\\displaystyle S(m)=\\sum_{n=1}^m (J_A(n)+J_B(n))$. For example $S(6)=7.58932292$, rounded to $8$ decimal places.\n\nFind $S(123456789)$, rounded to $8$ decimal places.", "raw_html": "

Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\\frac 1 2$, independently of its former state or the state of the other light bulbs.

\n\n

While discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:
\nBoth games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\\frac 1 k$.

\n\n

In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.

\n\n

For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.

\n\n

Let $\\displaystyle S(m)=\\sum_{n=1}^m (J_A(n)+J_B(n))$. For example $S(6)=7.58932292$, rounded to $8$ decimal places.

\n\n

Find $S(123456789)$, rounded to $8$ decimal places.

", "url": "https://projecteuler.net/problem=567", "answer": "75.44817535"} {"id": 568, "problem": "Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\\frac 1 2$, independently of its former state or the state of the other light bulbs.\n\nWhile discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:\n\nBoth games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\\frac 1 k$.\n\nIn game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.\n\nFor each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.\n\nLet $D(n)=J_B(n)−J_A(n)$. For example, $D(6) = 0.03828125$.\n\nFind the $7$ most significant digits of $D(123456789)$ after removing all leading zeros.\n\n(If, for example, we had asked for the $7$ most significant digits of $D(6)$, the answer would have been 3828125.)", "raw_html": "

Tom has built a random generator that is connected to a row of $n$ light bulbs. Whenever the random generator is activated each of the $n$ lights is turned on with the probability of $\\frac 1 2$, independently of its former state or the state of the other light bulbs.

\n\n

While discussing with his friend Jerry how to use his generator, they invent two different games, they call the reciprocal games:
\nBoth games consist of $n$ turns. Each turn is started by choosing a number $k$ randomly between (and including) $1$ and $n$, with equal probability of $\\frac 1 n$ for each number, while the possible win for that turn is the reciprocal of $k$, that is $\\frac 1 k$.

\n\n

In game A, Tom activates his random generator once in each turn. If the number of lights turned on is the same as the previously chosen number $k$, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing for that turn. Jerry's expected win after playing the total game A consisting of $n$ turns is called $J_A(n)$. For example $J_A(6)=0.39505208$, rounded to $8$ decimal places.

\n\n

For each turn in game B, after $k$ has been randomly selected, Tom keeps reactivating his random generator until exactly $k$ lights are turned on. After that Jerry takes over and reactivates the random generator until he, too, has generated a pattern with exactly $k$ lights turned on. If this pattern is identical to Tom's last pattern, Jerry wins and gets $\\frac 1 k$, otherwise he will receive nothing. Jerry's expected win after the total game B consisting of $n$ turns is called $J_B(n)$. For example $J_B(6)=0.43333333$, rounded to $8$ decimal places.

\n\n

Let $D(n)=J_B(n)−J_A(n)$. For example, $D(6) = 0.03828125$.

\n\n

Find the $7$ most significant digits of $D(123456789)$ after removing all leading zeros.
\n(If, for example, we had asked for the $7$ most significant digits of $D(6)$, the answer would have been 3828125.)

", "url": "https://projecteuler.net/problem=568", "answer": "4228020"} {"id": 569, "problem": "A mountain range consists of a line of mountains with slopes of exactly $45^\\circ$, and heights governed by the prime numbers, $p_n$. The up-slope of the $k$th mountain is of height $p_{2k - 1}$, and the downslope is $p_{2k}$. The first few foot-hills of this range are illustrated below.\n\nTenzing sets out to climb each one in turn, starting from the lowest. At the top of each peak, he looks back and counts how many of the previous peaks he can see. In the example above, the eye-line from the third mountain is drawn in red, showing that he can only see the peak of the second mountain from this viewpoint. Similarly, from the $9$th mountain, he can see three peaks, those of the $5$th, $7$th and $8$th mountain.\n\nLet $P(k)$ be the number of peaks that are visible looking back from the $k$th mountain. Hence $P(3)=1$ and $P(9)=3$.\n\nAlso $\\displaystyle \\sum_{k=1}^{100} P(k) = 227$.\n\nFind $\\displaystyle \\sum_{k=1}^{2500000} P(k)$.", "raw_html": "

A mountain range consists of a line of mountains with slopes of exactly $45^\\circ$, and heights governed by the prime numbers, $p_n$. The up-slope of the $k$th mountain is of height $p_{2k - 1}$, and the downslope is $p_{2k}$. The first few foot-hills of this range are illustrated below.

\n\n
\n\"0569-prime-mountain-range.gif\"\n
\n\n

Tenzing sets out to climb each one in turn, starting from the lowest. At the top of each peak, he looks back and counts how many of the previous peaks he can see. In the example above, the eye-line from the third mountain is drawn in red, showing that he can only see the peak of the second mountain from this viewpoint. Similarly, from the $9$th mountain, he can see three peaks, those of the $5$th, $7$th and $8$th mountain.

\n\n

Let $P(k)$ be the number of peaks that are visible looking back from the $k$th mountain. Hence $P(3)=1$ and $P(9)=3$.
\nAlso $\\displaystyle \\sum_{k=1}^{100} P(k) = 227$.

\n\n

Find $\\displaystyle \\sum_{k=1}^{2500000} P(k)$.

", "url": "https://projecteuler.net/problem=569", "answer": "21025060"} {"id": 570, "problem": "A snowflake of order $n$ is formed by overlaying an equilateral triangle (rotated by $180$ degrees) onto each equilateral triangle of the same size in a snowflake of order $n-1$. A snowflake of order $1$ is a single equilateral triangle.\n\n\n\nSome areas of the snowflake are overlaid repeatedly. In the above picture, blue represents the areas that are one layer thick, red two layers thick, yellow three layers thick, and so on.\n\nFor an order $n$ snowflake, let $A(n)$ be the number of triangles that are one layer thick, and let $B(n)$ be the number of triangles that are three layers thick. Define $G(n) = \\gcd(A(n), B(n))$.\n\nE.g. $A(3) = 30$, $B(3) = 6$, $G(3)=6$.\n\n$A(11) = 3027630$, $B(11) = 19862070$, $G(11) = 30$.\n\nFurther, $G(500) = 186$ and $\\sum_{n=3}^{500}G(n)=5124$.\n\nFind $\\displaystyle \\sum_{n=3}^{10^7}G(n)$.", "raw_html": "

A snowflake of order $n$ is formed by overlaying an equilateral triangle (rotated by $180$ degrees) onto each equilateral triangle of the same size in a snowflake of order $n-1$. A snowflake of order $1$ is a single equilateral triangle.

\n\n\n\n
\"0570-snowflakes.png\"
\n\n\n

Some areas of the snowflake are overlaid repeatedly. In the above picture, blue represents the areas that are one layer thick, red two layers thick, yellow three layers thick, and so on.

\n\n

For an order $n$ snowflake, let $A(n)$ be the number of triangles that are one layer thick, and let $B(n)$ be the number of triangles that are three layers thick. Define $G(n) = \\gcd(A(n), B(n))$.

\n\n

E.g. $A(3) = 30$, $B(3) = 6$, $G(3)=6$.
\n$A(11) = 3027630$, $B(11) = 19862070$, $G(11) = 30$.

\n\n

Further, $G(500) = 186$ and $\\sum_{n=3}^{500}G(n)=5124$.

\n\n

Find $\\displaystyle \\sum_{n=3}^{10^7}G(n)$.

", "url": "https://projecteuler.net/problem=570", "answer": "271197444"} {"id": 571, "problem": "A positive number is pandigital in base $b$ if it contains all digits from $0$ to $b - 1$ at least once when written in base $b$.\n\nAn $n$-super-pandigital number is a number that is simultaneously pandigital in all bases from $2$ to $n$ inclusively.\n\nFor example $978 = 1111010010_2 = 1100020_3 = 33102_4 = 12403_5$ is the smallest $5$-super-pandigital number.\n\nSimilarly, $1093265784$ is the smallest $10$-super-pandigital number.\n\nThe sum of the $10$ smallest $10$-super-pandigital numbers is $20319792309$.\n\nWhat is the sum of the $10$ smallest $12$-super-pandigital numbers?", "raw_html": "

A positive number is pandigital in base $b$ if it contains all digits from $0$ to $b - 1$ at least once when written in base $b$.

\n\n

An $n$-super-pandigital number is a number that is simultaneously pandigital in all bases from $2$ to $n$ inclusively.
\nFor example $978 = 1111010010_2 = 1100020_3 = 33102_4 = 12403_5$ is the smallest $5$-super-pandigital number.
\nSimilarly, $1093265784$ is the smallest $10$-super-pandigital number.
\nThe sum of the $10$ smallest $10$-super-pandigital numbers is $20319792309$.

\n\n

What is the sum of the $10$ smallest $12$-super-pandigital numbers?

", "url": "https://projecteuler.net/problem=571", "answer": "30510390701978"} {"id": 572, "problem": "A matrix $M$ is called idempotent if $M^2 = M$.\n\nLet $M$ be a three by three matrix :\n$M=\\begin{pmatrix}\na & b & c\\\\\nd & e & f\\\\\ng &h &i\\\\\n\\end{pmatrix}$.\n\nLet $C(n)$ be the number of idempotent three by three matrices $M$ with integer elements such that\n\n$ -n \\le a,b,c,d,e,f,g,h,i \\le n$.\n\n$C(1)=164$ and $C(2)=848$.\n\nFind $C(200)$.", "raw_html": "

\nA matrix $M$ is called idempotent if $M^2 = M$.
\nLet $M$ be a three by three matrix : \n$M=\\begin{pmatrix} \n a & b & c\\\\ \n d & e & f\\\\\n g &h &i\\\\\n\\end{pmatrix}$.
\nLet $C(n)$ be the number of idempotent three by three matrices $M$ with integer elements such that
\n$ -n \\le a,b,c,d,e,f,g,h,i \\le n$.

\n

\n$C(1)=164$ and $C(2)=848$.\n

\n

\nFind $C(200)$.\n

", "url": "https://projecteuler.net/problem=572", "answer": "19737656"} {"id": 573, "problem": "$n$ runners in very different training states want to compete in a race. Each one of them is given a different starting number $k$ $(1\\leq k \\leq n)$ according to the runner's (constant) individual racing speed being $v_k=\\frac{k}{n}$.\n\nIn order to give the slower runners a chance to win the race, $n$ different starting positions are chosen randomly (with uniform distribution) and independently from each other within the racing track of length $1$. After this, the starting position nearest to the goal is assigned to runner $1$, the next nearest starting position to runner $2$ and so on, until finally the starting position furthest away from the goal is assigned to runner $n$. The winner of the race is the runner who reaches the goal first.\n\nInterestingly, the expected running time for the winner is $\\frac{1}{2}$, independently of the number of runners. Moreover, while it can be shown that all runners will have the same expected running time of $\\frac{n}{n+1}$, the race is still unfair, since the winning chances may differ significantly for different starting numbers:\n\nLet $P_{n,k}$ be the probability for runner $k$ to win a race with $n$ runners and $E_n = \\sum_{k=1}^n k P_{n,k}$ be the expected starting number of the winner in that race. It can be shown that, for example,\n$P_{3,1}=\\frac{4}{9}$, $P_{3,2}=\\frac{2}{9}$, $P_{3,3}=\\frac{1}{3}$ and $E_3=\\frac{17}{9}$ for a race with $3$ runners.\n\nYou are given that $E_4=2.21875$, $E_5=2.5104$ and $E_{10}=3.66021568$.\n\nFind $E_{1000000}$ rounded to $4$ digits after the decimal point.", "raw_html": "

$n$ runners in very different training states want to compete in a race. Each one of them is given a different starting number $k$ $(1\\leq k \\leq n)$ according to the runner's (constant) individual racing speed being $v_k=\\frac{k}{n}$.
\nIn order to give the slower runners a chance to win the race, $n$ different starting positions are chosen randomly (with uniform distribution) and independently from each other within the racing track of length $1$. After this, the starting position nearest to the goal is assigned to runner $1$, the next nearest starting position to runner $2$ and so on, until finally the starting position furthest away from the goal is assigned to runner $n$. The winner of the race is the runner who reaches the goal first.

\n\n

Interestingly, the expected running time for the winner is $\\frac{1}{2}$, independently of the number of runners. Moreover, while it can be shown that all runners will have the same expected running time of $\\frac{n}{n+1}$, the race is still unfair, since the winning chances may differ significantly for different starting numbers:

\n\n

Let $P_{n,k}$ be the probability for runner $k$ to win a race with $n$ runners and $E_n = \\sum_{k=1}^n k P_{n,k}$ be the expected starting number of the winner in that race. It can be shown that, for example,\n$P_{3,1}=\\frac{4}{9}$, $P_{3,2}=\\frac{2}{9}$, $P_{3,3}=\\frac{1}{3}$ and $E_3=\\frac{17}{9}$ for a race with $3$ runners.
\nYou are given that $E_4=2.21875$, $E_5=2.5104$ and $E_{10}=3.66021568$.

\n\n

Find $E_{1000000}$ rounded to $4$ digits after the decimal point.

", "url": "https://projecteuler.net/problem=573", "answer": "1252.9809"} {"id": 574, "problem": "Let $q$ be a prime and $A \\ge B >0$ be two integers with the following properties:\n\n- $A$ and $B$ have no prime factor in common, that is $\\gcd(A,B)=1$.\n\n- The product $AB$ is divisible by every prime less than q.\n\nIt can be shown that, given these conditions, any sum $A+BLet $q$ be a prime and $A \\ge B >0$ be two integers with the following properties:\n

  • $A$ and $B$ have no prime factor in common, that is $\\gcd(A,B)=1$.
  • \n
  • The product $AB$ is divisible by every prime less than q.
  • \n\n

It can be shown that, given these conditions, any sum $A+B<q^2$ and any difference $1<A-B<q^2$ has to be a prime number. Thus you can verify that a number $p$ is prime by showing that either $p=A+B<q^2$ or $p=A-B<q^2$ for some $A,B,q$ fulfilling the conditions listed above.

\n\n

Let $V(p)$ be the smallest possible value of $A$ in any sum $p=A+B$ and any difference $p=A-B$, that verifies $p$ being prime. Examples:
\n$V(2)=1$, since $2=1+1< 2^2$.
\n$V(37)=22$, since $37=22+15=2 \\cdot 11+3 \\cdot 5< 7^2$ is the associated sum with the smallest possible $A$.
\n$V(151)=165$ since $151=165-14=3 \\cdot 5 \\cdot 11 - 2 \\cdot 7<13^2$ is the associated difference with the smallest possible $A$.

\n

\nLet $S(n)$ be the sum of $V(p)$ for all primes $p<n$. For example, $S(10)=10$ and $S(200)=7177$.

\n

\nFind $S(3800)$.\n

", "url": "https://projecteuler.net/problem=574", "answer": "5780447552057000454"} {"id": 575, "problem": "It was quite an ordinary day when a mysterious alien vessel appeared as if from nowhere. After waiting several hours and receiving no response it is decided to send a team to investigate, of which you are included. Upon entering the vessel you are met by a friendly holographic figure, Katharina, who explains the purpose of the vessel, Eulertopia.\n\nShe claims that Eulertopia is almost older than time itself. Its mission was to take advantage of a combination of incredible computational power and vast periods of time to discover the answer to life, the universe, and everything. Hence the resident cleaning robot, Leonhard, along with his housekeeping responsibilities, was built with a powerful computational matrix to ponder the meaning of life as he wanders through a massive 1000 by 1000 square grid of rooms. She goes on to explain that the rooms are numbered sequentially from left to right, row by row. So, for example, if Leonhard was wandering around a 5 by 5 grid then the rooms would be numbered in the following way.\n\nMany millenia ago Leonhard reported to Katharina to have found the answer and he is willing to share it with any life form who proves to be worthy of such knowledge.\n\nKatharina further explains that the designers of Leonhard were given instructions to program him with equal probability of remaining in the same room or travelling to an adjacent room. However, it was not clear to them if this meant (i) an equal probability being split equally between remaining in the room and the number of available routes, or, (ii) an equal probability (50%) of remaining in the same room and then the other 50% was to be split equally between the number of available routes.\n\n(i) Probability of remaining related to number of exits\n\n(ii) Fixed 50% probability of remaining\n\nThe records indicate that they decided to flip a coin. Heads would mean that the probability of remaining was dynamically related to the number of exits whereas tails would mean that they program Leonhard with a fixed 50% probability of remaining in a particular room. Unfortunately there is no record of the outcome of the coin, so without further information we would need to assume that there is equal probability of either of the choices being implemented.\n\nKatharina suggests it should not be too challenging to determine that the probability of finding him in a square numbered room in a 5 by 5 grid after unfathomable periods of time would be approximately 0.177976190476 [12 d.p.].\n\nIn order to prove yourself worthy of visiting the great oracle you must calculate the probability of finding him in a square numbered room in the 1000 by 1000 lair in which he has been wandering.\n\n(Give your answer rounded to 12 decimal places)", "raw_html": "

It was quite an ordinary day when a mysterious alien vessel appeared as if from nowhere. After waiting several hours and receiving no response it is decided to send a team to investigate, of which you are included. Upon entering the vessel you are met by a friendly holographic figure, Katharina, who explains the purpose of the vessel, Eulertopia.

\n\n

She claims that Eulertopia is almost older than time itself. Its mission was to take advantage of a combination of incredible computational power and vast periods of time to discover the answer to life, the universe, and everything. Hence the resident cleaning robot, Leonhard, along with his housekeeping responsibilities, was built with a powerful computational matrix to ponder the meaning of life as he wanders through a massive 1000 by 1000 square grid of rooms. She goes on to explain that the rooms are numbered sequentially from left to right, row by row. So, for example, if Leonhard was wandering around a 5 by 5 grid then the rooms would be numbered in the following way.

\n\n
\n\"0575_wandering_robot_1_5x5.png\"\n
\n\n

Many millenia ago Leonhard reported to Katharina to have found the answer and he is willing to share it with any life form who proves to be worthy of such knowledge.

\n\n

Katharina further explains that the designers of Leonhard were given instructions to program him with equal probability of remaining in the same room or travelling to an adjacent room. However, it was not clear to them if this meant (i) an equal probability being split equally between remaining in the room and the number of available routes, or, (ii) an equal probability (50%) of remaining in the same room and then the other 50% was to be split equally between the number of available routes.

\n\n
\n\"0575_wandering_robot_2_fixed.png\"
\n
(i) Probability of remaining related to number of exits
\n
\n\"0575_wandering_robot_3_dynamic.png\"
\n
(ii) Fixed 50% probability of remaining
\n
\n\n

The records indicate that they decided to flip a coin. Heads would mean that the probability of remaining was dynamically related to the number of exits whereas tails would mean that they program Leonhard with a fixed 50% probability of remaining in a particular room. Unfortunately there is no record of the outcome of the coin, so without further information we would need to assume that there is equal probability of either of the choices being implemented.

\n\n

Katharina suggests it should not be too challenging to determine that the probability of finding him in a square numbered room in a 5 by 5 grid after unfathomable periods of time would be approximately 0.177976190476 [12 d.p.].

\n\n

In order to prove yourself worthy of visiting the great oracle you must calculate the probability of finding him in a square numbered room in the 1000 by 1000 lair in which he has been wandering.
\n(Give your answer rounded to 12 decimal places)

", "url": "https://projecteuler.net/problem=575", "answer": "0.000989640561"} {"id": 576, "problem": "A bouncing point moves counterclockwise along a circle with circumference $1$ with jumps of constant length $l \\lt 1$, until it hits a gap of length $g \\lt 1$, that is placed in a distance $d$ counterclockwise from the starting point. The gap does not include the starting point, that is $g+d \\lt 1$.\n\nLet $S(l,g,d)$ be the sum of the length of all jumps, until the point falls into the gap. It can be shown that $S(l,g,d)$ is finite for any irrational jump size $l$, regardless of the values of $g$ and $d$.\n\nExamples:\n\n$S(\\sqrt{\\frac 1 2}, 0.06, 0.7)=0.7071 \\cdots$, $S(\\sqrt{\\frac 1 2}, 0.06, 0.3543)=1.4142 \\cdots$ and\n$S(\\sqrt{\\frac 1 2}, 0.06, 0.2427)=16.2634 \\cdots$.\n\nLet $M(n, g)$ be the maximum of $ \\sum S(\\sqrt{\\frac 1 p}, g, d)$ for all primes $p \\le n$ and any valid value of $d$.\n\nExamples:\n\n$M(3, 0.06) =29.5425 \\cdots$, since $S(\\sqrt{\\frac 1 2}, 0.06, 0.2427)+S(\\sqrt{\\frac 1 3}, 0.06, 0.2427)=29.5425 \\cdots$ is the maximal reachable sum for $g=0.06$.\n\n$M(10, 0.01)=266.9010 \\cdots$\n\nFind $M(100, 0.00002)$, rounded to $4$ decimal places.", "raw_html": "

\nA bouncing point moves counterclockwise along a circle with circumference $1$ with jumps of constant length $l \\lt 1$, until it hits a gap of length $g \\lt 1$, that is placed in a distance $d$ counterclockwise from the starting point. The gap does not include the starting point, that is $g+d \\lt 1$.

\n\n

Let $S(l,g,d)$ be the sum of the length of all jumps, until the point falls into the gap. It can be shown that $S(l,g,d)$ is finite for any irrational jump size $l$, regardless of the values of $g$ and $d$.
\nExamples:
\n$S(\\sqrt{\\frac 1 2}, 0.06, 0.7)=0.7071 \\cdots$, $S(\\sqrt{\\frac 1 2}, 0.06, 0.3543)=1.4142 \\cdots$ and
$S(\\sqrt{\\frac 1 2}, 0.06, 0.2427)=16.2634 \\cdots$.

\n

\nLet $M(n, g)$ be the maximum of $ \\sum S(\\sqrt{\\frac 1 p}, g, d)$ for all primes $p \\le n$ and any valid value of $d$.
\nExamples:
\n$M(3, 0.06) =29.5425 \\cdots$, since $S(\\sqrt{\\frac 1 2}, 0.06, 0.2427)+S(\\sqrt{\\frac 1 3}, 0.06, 0.2427)=29.5425 \\cdots$ is the maximal reachable sum for $g=0.06$.
\n$M(10, 0.01)=266.9010 \\cdots$

\n\n

Find $M(100, 0.00002)$, rounded to $4$ decimal places.

", "url": "https://projecteuler.net/problem=576", "answer": "344457.5871"} {"id": 577, "problem": "An equilateral triangle with integer side length $n \\ge 3$ is divided into $n^2$ equilateral triangles with side length 1 as shown in the diagram below.\n\nThe vertices of these triangles constitute a triangular lattice with $\\frac{(n+1)(n+2)} 2$ lattice points.\n\nLet $H(n)$ be the number of all regular hexagons that can be found by connecting 6 of these points.\n\n\n\nFor example, $H(3)=1$, $H(6)=12$ and $H(20)=966$.\n\nFind $\\displaystyle \\sum_{n=3}^{12345} H(n)$.", "raw_html": "

An equilateral triangle with integer side length $n \\ge 3$ is divided into $n^2$ equilateral triangles with side length 1 as shown in the diagram below.
\nThe vertices of these triangles constitute a triangular lattice with $\\frac{(n+1)(n+2)} 2$ lattice points.

\n

Let $H(n)$ be the number of all regular hexagons that can be found by connecting 6 of these points.

\n
\n\"0577_counting_hexagons.png\"\n
\n\n

\nFor example, $H(3)=1$, $H(6)=12$ and $H(20)=966$.

\n\n

Find $\\displaystyle \\sum_{n=3}^{12345} H(n)$.

", "url": "https://projecteuler.net/problem=577", "answer": "265695031399260211"} {"id": 578, "problem": "Any positive integer can be written as a product of prime powers: $p_1^{a_1} \\times p_2^{a_2} \\times \\cdots \\times p_k^{a_k}$,\n\nwhere $p_i$ are distinct prime integers, $a_i \\gt 0$ and $p_i \\lt p_j$ if $i \\lt j$.\n\nA decreasing prime power positive integer is one for which $a_i \\ge a_j$ if $i \\lt j$.\n\nFor example, $1$, $2$, $15=3 \\times 5$, $360=2^3 \\times 3^2 \\times 5$ and $1000=2^3 \\times 5^3$ are decreasing prime power integers.\n\nLet $C(n)$ be the count of decreasing prime power positive integers not exceeding $n$.\n\n$C(100) = 94$ since all positive integers not exceeding $100$ have decreasing prime powers except $18$, $50$, $54$, $75$, $90$ and $98$.\n\nYou are given $C(10^6) = 922052$.\n\nFind $C(10^{13})$.", "raw_html": "

Any positive integer can be written as a product of prime powers: $p_1^{a_1} \\times p_2^{a_2} \\times \\cdots \\times p_k^{a_k}$,
\nwhere $p_i$ are distinct prime integers, $a_i \\gt 0$ and $p_i \\lt p_j$ if $i \\lt j$.

\n\n

A decreasing prime power positive integer is one for which $a_i \\ge a_j$ if $i \\lt j$.
\nFor example, $1$, $2$, $15=3 \\times 5$, $360=2^3 \\times 3^2 \\times 5$ and $1000=2^3 \\times 5^3$ are decreasing prime power integers.

\n\n

Let $C(n)$ be the count of decreasing prime power positive integers not exceeding $n$.
\n$C(100) = 94$ since all positive integers not exceeding $100$ have decreasing prime powers except $18$, $50$, $54$, $75$, $90$ and $98$.
\nYou are given $C(10^6) = 922052$.

\n\n

Find $C(10^{13})$.

", "url": "https://projecteuler.net/problem=578", "answer": "9219696799346"} {"id": 579, "problem": "A lattice cube is a cube in which all vertices have integer coordinates. Let $C(n)$ be the number of different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$. Two cubes are hereby considered different if any of their vertices have different coordinates.\n\nFor example, $C(1)=1$, $C(2)=9$, $C(4)=100$, $C(5)=229$, $C(10)=4469$ and $C(50)=8154671$.\n\nDifferent cubes may contain different numbers of lattice points.\n\nFor example, the cube with the vertices\n\n$(0, 0, 0)$, $(3, 0, 0)$, $(0, 3, 0)$, $(0, 0, 3)$, $(0, 3, 3)$, $(3, 0, 3)$, $(3, 3, 0)$, $(3, 3, 3)$ contains $64$ lattice points ($56$ lattice points on the surface including the $8$ vertices and $8$ points within the cube).\n\nIn contrast, the cube with the vertices\n\n$(0, 2, 2)$, $(1, 4, 4)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 2, 5)$, $(3, 5, 2)$, $(4, 1, 1)$, $(5, 3, 3)$ contains only $40$ lattice points ($20$ points on the surface and $20$ points within the cube), although both cubes have the same side length $3$.\n\nLet $S(n)$ be the sum of the lattice points contained in the different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$.\n\nFor example, $S(1)=8$, $S(2)=91$, $S(4)=1878$, $S(5)=5832$, $S(10)=387003$ and $S(50)=29948928129$.\n\nFind $S(5000) \\bmod 10^9$.", "raw_html": "

A lattice cube is a cube in which all vertices have integer coordinates. Let $C(n)$ be the number of different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$. Two cubes are hereby considered different if any of their vertices have different coordinates.
\nFor example, $C(1)=1$, $C(2)=9$, $C(4)=100$, $C(5)=229$, $C(10)=4469$ and $C(50)=8154671$.\n

\n

Different cubes may contain different numbers of lattice points.

\n

\nFor example, the cube with the vertices
\n$(0, 0, 0)$, $(3, 0, 0)$, $(0, 3, 0)$, $(0, 0, 3)$, $(0, 3, 3)$, $(3, 0, 3)$, $(3, 3, 0)$, $(3, 3, 3)$ contains $64$ lattice points ($56$ lattice points on the surface including the $8$ vertices and $8$ points within the cube).

\n

In contrast, the cube with the vertices
\n$(0, 2, 2)$, $(1, 4, 4)$, $(2, 0, 3)$, $(2, 3, 0)$, $(3, 2, 5)$, $(3, 5, 2)$, $(4, 1, 1)$, $(5, 3, 3)$ contains only $40$ lattice points ($20$ points on the surface and $20$ points within the cube), although both cubes have the same side length $3$.\n

\n

\nLet $S(n)$ be the sum of the lattice points contained in the different lattice cubes in which the coordinates of all vertices range between (and including) $0$ and $n$.

\n\n

For example, $S(1)=8$, $S(2)=91$, $S(4)=1878$, $S(5)=5832$, $S(10)=387003$ and $S(50)=29948928129$.

\n\n

Find $S(5000) \\bmod 10^9$.

", "url": "https://projecteuler.net/problem=579", "answer": "3805524"} {"id": 580, "problem": "A Hilbert number is any positive integer of the form $4k+1$ for integer $k\\geq 0$. We shall define a squarefree Hilbert number as a Hilbert number which is not divisible by the square of any Hilbert number other than one. For example, $117$ is a squarefree Hilbert number, equaling $9\\times13$. However $6237$ is a Hilbert number that is not squarefree in this sense, as it is divisible by $9^2$. The number $3969$ is also not squarefree, as it is divisible by both $9^2$ and $21^2$.\n\nThere are $2327192$ squarefree Hilbert numbers below $10^7$.\n\nHow many squarefree Hilbert numbers are there below $10^{16}$?", "raw_html": "

\nA Hilbert number is any positive integer of the form $4k+1$ for integer $k\\geq 0$. We shall define a squarefree Hilbert number as a Hilbert number which is not divisible by the square of any Hilbert number other than one. For example, $117$ is a squarefree Hilbert number, equaling $9\\times13$. However $6237$ is a Hilbert number that is not squarefree in this sense, as it is divisible by $9^2$. The number $3969$ is also not squarefree, as it is divisible by both $9^2$ and $21^2$. \n

\n

\nThere are $2327192$ squarefree Hilbert numbers below $10^7$.
\nHow many squarefree Hilbert numbers are there below $10^{16}$?\n

", "url": "https://projecteuler.net/problem=580", "answer": "2327213148095366"} {"id": 581, "problem": "A number is $p$-smooth if it has no prime factors larger than $p$.\n\nLet $T$ be the sequence of triangular numbers, i.e. $T(n)=n(n+1)/2$.\n\nFind the sum of all indices $n$ such that $T(n)$ is $47$-smooth.", "raw_html": "

\nA number is $p$-smooth if it has no prime factors larger than $p$.
\nLet $T$ be the sequence of triangular numbers, i.e. $T(n)=n(n+1)/2$.
\nFind the sum of all indices $n$ such that $T(n)$ is $47$-smooth.\n

", "url": "https://projecteuler.net/problem=581", "answer": "2227616372734"} {"id": 582, "problem": "Let $a, b$ and $c$ be the sides of an integer sided triangle with one angle of $120$ degrees, $a \\le b \\le c$ and $b-a \\le 100$.\n\nLet $T(n)$ be the number of such triangles with $c \\le n$.\n\n$T(1000)=235$ and $T(10^8)=1245$.\n\nFind $T(10^{100})$.", "raw_html": "

\nLet $a, b$ and $c$ be the sides of an integer sided triangle with one angle of $120$ degrees, $a \\le b \\le c$ and $b-a \\le 100$.
\nLet $T(n)$ be the number of such triangles with $c \\le n$.
\n$T(1000)=235$ and $T(10^8)=1245$.
\nFind $T(10^{100})$.\n

", "url": "https://projecteuler.net/problem=582", "answer": "19903"} {"id": 583, "problem": "A standard envelope shape is a convex figure consisting of an isosceles triangle (the flap) placed on top of a rectangle. An example of an envelope with integral sides is shown below. Note that to form a sensible envelope, the perpendicular height of the flap ($BCD$) must be smaller than the height of the rectangle ($ABDE$).\n\nIn the envelope illustrated, not only are all the sides integral, but also all the diagonals ($AC$, $AD$, $BD$, $BE$ and $CE$) are integral too. Let us call an envelope with these properties a Heron envelope.\n\nLet $S(p)$ be the sum of the perimeters of all the Heron envelopes with a perimeter less than or equal to $p$.\n\nYou are given that $S(10^4) = 884680$. Find $S(10^7)$.", "raw_html": "

\nA standard envelope shape is a convex figure consisting of an isosceles triangle (the flap) placed on top of a rectangle. An example of an envelope with integral sides is shown below. Note that to form a sensible envelope, the perpendicular height of the flap ($BCD$) must be smaller than the height of the rectangle ($ABDE$). \n

\n\n
\n\"0583_heron_envelope.gif\"\n
\n\n

\nIn the envelope illustrated, not only are all the sides integral, but also all the diagonals ($AC$, $AD$, $BD$, $BE$ and $CE$) are integral too. Let us call an envelope with these properties a Heron envelope.\n

\n\n

\nLet $S(p)$ be the sum of the perimeters of all the Heron envelopes with a perimeter less than or equal to $p$. \n

\n

\nYou are given that $S(10^4) = 884680$. Find $S(10^7)$.\n

", "url": "https://projecteuler.net/problem=583", "answer": "1174137929000"} {"id": 584, "problem": "A long long time ago in a galaxy far far away, the Wimwians, inhabitants of planet WimWi, discovered an unmanned drone that had landed on their planet. On examining the drone, they uncovered a device that sought the answer for the so called \"Birthday Problem\". The description of the problem was as follows:\n\nIf people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 1 day from each other.\n\nThe description further instructed them to enter the answer into the device and send the drone into space again. Startled by this turn of events, the Wimwians consulted their best mathematicians. Each year on Wimwi has 10 days and the mathematicians assumed equally likely birthdays and ignored leap years (leap years in Wimwi have 11 days), and found 5.78688636 to be the required answer. As such, the Wimwians entered this answer and sent the drone back into space.\n\nAfter traveling light years away, the drone then landed on planet Joka. The same events ensued except this time, the numbers in the device had changed due to some unknown technical issues. The description read:\n\nIf people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 7 days from each other.\n\nWith a 100-day year on the planet, the Jokars (inhabitants of Joka) found the answer to be 8.48967364 (rounded to 8 decimal places because the device allowed only 8 places after the decimal point) assuming equally likely birthdays. They too entered the answer into the device and launched the drone into space again.\n\nThis time the drone landed on planet Earth. As before the numbers in the problem description had changed. It read:\n\nIf people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 4 people with Birthdays within 7 days from each other.\n\nWhat would be the answer (rounded to eight places after the decimal point) the people of Earth have to enter into the device for a year with 365 days? Ignore leap years. Also assume that all birthdays are equally likely and independent of each other.", "raw_html": "

A long long time ago in a galaxy far far away, the Wimwians, inhabitants of planet WimWi, discovered an unmanned drone that had landed on their planet. On examining the drone, they uncovered a device that sought the answer for the so called \"Birthday Problem\". The description of the problem was as follows:

\n\n

If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 1 day from each other.

\n\n

The description further instructed them to enter the answer into the device and send the drone into space again. Startled by this turn of events, the Wimwians consulted their best mathematicians. Each year on Wimwi has 10 days and the mathematicians assumed equally likely birthdays and ignored leap years (leap years in Wimwi have 11 days), and found 5.78688636 to be the required answer. As such, the Wimwians entered this answer and sent the drone back into space.

\n\n\n

After traveling light years away, the drone then landed on planet Joka. The same events ensued except this time, the numbers in the device had changed due to some unknown technical issues. The description read:

\n\n

If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 3 people with Birthdays within 7 days from each other.

\n\n

With a 100-day year on the planet, the Jokars (inhabitants of Joka) found the answer to be 8.48967364 (rounded to 8 decimal places because the device allowed only 8 places after the decimal point) assuming equally likely birthdays. They too entered the answer into the device and launched the drone into space again.

\n\n\n

This time the drone landed on planet Earth. As before the numbers in the problem description had changed. It read:

\n\n

If people on your planet were to enter a very large room one by one, what will be the expected number of people in the room when you first find 4 people with Birthdays within 7 days from each other.

\n\n

What would be the answer (rounded to eight places after the decimal point) the people of Earth have to enter into the device for a year with 365 days? Ignore leap years. Also assume that all birthdays are equally likely and independent of each other.

", "url": "https://projecteuler.net/problem=584", "answer": "32.83822408"} {"id": 585, "problem": "Consider the term $\\small \\sqrt{x+\\sqrt{y}+\\sqrt{z}}$ that is representing a nested square root. $x$, $y$ and $z$ are positive integers and $y$ and $z$ are not allowed to be perfect squares, so the number below the outer square root is irrational. Still it can be shown that for some combinations of $x$, $y$ and $z$ the given term can be simplified into a sum and/or difference of simple square roots of integers, actually denesting the square roots in the initial expression.\n\nHere are some examples of this denesting:\n\n$\\small \\sqrt{3+\\sqrt{2}+\\sqrt{2}}=\\sqrt{2}+\\sqrt{1}=\\sqrt{2}+1$\n\n$\\small \\sqrt{8+\\sqrt{15}+\\sqrt{15}}=\\sqrt{5}+\\sqrt{3}$\n\n$\\small \\sqrt{20+\\sqrt{96}+\\sqrt{12}}=\\sqrt{9}+\\sqrt{6}+\\sqrt{3}-\\sqrt{2}=3+\\sqrt{6}+\\sqrt{3}-\\sqrt{2}$\n\n$\\small \\sqrt{28+\\sqrt{160}+\\sqrt{108}}=\\sqrt{15}+\\sqrt{6}+\\sqrt{5}-\\sqrt{2}$\n\nAs you can see the integers used in the denested expression may also be perfect squares resulting in further simplification.\n\nLet F($n$) be the number of different terms $\\small \\sqrt{x+\\sqrt{y}+\\sqrt{z}}$, that can be denested into the sum and/or difference of a finite number of square roots, given the additional condition that $0Consider the term $\\small \\sqrt{x+\\sqrt{y}+\\sqrt{z}}$ that is representing a nested square root. $x$, $y$ and $z$ are positive integers and $y$ and $z$ are not allowed to be perfect squares, so the number below the outer square root is irrational. Still it can be shown that for some combinations of $x$, $y$ and $z$ the given term can be simplified into a sum and/or difference of simple square roots of integers, actually denesting the square roots in the initial expression.

\n\n

Here are some examples of this denesting:
\n$\\small \\sqrt{3+\\sqrt{2}+\\sqrt{2}}=\\sqrt{2}+\\sqrt{1}=\\sqrt{2}+1$
\n$\\small \\sqrt{8+\\sqrt{15}+\\sqrt{15}}=\\sqrt{5}+\\sqrt{3}$
\n$\\small \\sqrt{20+\\sqrt{96}+\\sqrt{12}}=\\sqrt{9}+\\sqrt{6}+\\sqrt{3}-\\sqrt{2}=3+\\sqrt{6}+\\sqrt{3}-\\sqrt{2}$
\n$\\small \\sqrt{28+\\sqrt{160}+\\sqrt{108}}=\\sqrt{15}+\\sqrt{6}+\\sqrt{5}-\\sqrt{2}$

\n

As you can see the integers used in the denested expression may also be perfect squares resulting in further simplification.

\n\n

Let F($n$) be the number of different terms $\\small \\sqrt{x+\\sqrt{y}+\\sqrt{z}}$, that can be denested into the sum and/or difference of a finite number of square roots, given the additional condition that $0<x \\le n$. That is,
\n$\\small \\displaystyle \\sqrt{x+\\sqrt{y}+\\sqrt{z}}=\\sum_{i=1}^k s_i\\sqrt{a_i}$
\nwith $k$, $x$, $y$, $z$ and all $a_i$ being positive integers, all $s_i =\\pm 1$ and $x\\le n$.
Furthermore $y$ and $z$ are not allowed to be perfect squares.

\n\n

Nested roots with the same value are not considered different, for example $\\small \\sqrt{7+\\sqrt{3}+\\sqrt{27}}$, $\\small \\sqrt{7+\\sqrt{12}+\\sqrt{12}}$ and $\\small \\sqrt{7+\\sqrt{27}+\\sqrt{3}}$, that can all three be denested into $\\small 2+\\sqrt{3}$, would only be counted once.

\n\n

You are given that $F(10)=17$, $F(15)=46$, $F(20)=86$, $F(30)=213$ and $F(100)=2918$ and $F(5000)=11134074$.
\nFind $F(5000000)$.

", "url": "https://projecteuler.net/problem=585", "answer": "17714439395932"} {"id": 586, "problem": "The number $209$ can be expressed as $a^2 + 3ab + b^2$ in two distinct ways:\n\n$ \\qquad 209 = 8^2 + 3\\cdot 8\\cdot 5 + 5^2$\n\n$ \\qquad 209 = 13^2 + 3\\cdot13\\cdot 1 + 1^2$\n\nLet $f(n,r)$ be the number of integers $k$ not exceeding $n$ that can be expressed as $k=a^2 + 3ab + b^2$, with $a \\gt b \\gt 0$ integers, in exactly $r$ different ways.\n\nYou are given that $f(10^5, 4) = 237$ and $f(10^8, 6) = 59517$.\n\nFind $f(10^{15}, 40)$.", "raw_html": "

\nThe number $209$ can be expressed as $a^2 + 3ab + b^2$ in two distinct ways:\n

\n

\n$ \\qquad 209 = 8^2 + 3\\cdot 8\\cdot 5 + 5^2$
\n$ \\qquad 209 = 13^2 + 3\\cdot13\\cdot 1 + 1^2$\n

\n

\nLet $f(n,r)$ be the number of integers $k$ not exceeding $n$ that can be expressed as $k=a^2 + 3ab + b^2$, with $a \\gt b \\gt 0$ integers, in exactly $r$ different ways.\n

\n

\nYou are given that $f(10^5, 4) = 237$ and $f(10^8, 6) = 59517$.\n

\n

\nFind $f(10^{15}, 40)$.\n

", "url": "https://projecteuler.net/problem=586", "answer": "82490213"} {"id": 587, "problem": "A square is drawn around a circle as shown in the diagram below on the left.\n\nWe shall call the blue shaded region the L-section.\n\nA line is drawn from the bottom left of the square to the top right as shown in the diagram on the right.\n\nWe shall call the orange shaded region a concave triangle.\n\nIt should be clear that the concave triangle occupies exactly half of the L-section.\n\nTwo circles are placed next to each other horizontally, a rectangle is drawn around both circles, and a line is drawn from the bottom left to the top right as shown in the diagram below.\n\nThis time the concave triangle occupies approximately 36.46% of the L-section.\n\nIf $n$ circles are placed next to each other horizontally, a rectangle is drawn around the n circles, and a line is drawn from the bottom left to the top right, then it can be shown that the least value of n for which the concave triangle occupies less than 10% of the L-section is $n = 15$.\n\nWhat is the least value of $n$ for which the concave triangle occupies less than 0.1% of the L-section?", "raw_html": "

\nA square is drawn around a circle as shown in the diagram below on the left.
\nWe shall call the blue shaded region the L-section.
\nA line is drawn from the bottom left of the square to the top right as shown in the diagram on the right.
\nWe shall call the orange shaded region a concave triangle.\n

\n
\n\"0587_concave_triangle_1.png\"\n
\n

\nIt should be clear that the concave triangle occupies exactly half of the L-section.\n

\n

\n\nTwo circles are placed next to each other horizontally, a rectangle is drawn around both circles, and a line is drawn from the bottom left to the top right as shown in the diagram below.\n

\n
\n\"0587_concave_triangle_2.png\"\n
\n

\nThis time the concave triangle occupies approximately 36.46% of the L-section.\n

\n

\nIf $n$ circles are placed next to each other horizontally, a rectangle is drawn around the n circles, and a line is drawn from the bottom left to the top right, then it can be shown that the least value of n for which the concave triangle occupies less than 10% of the L-section is $n = 15$.\n

\n

\nWhat is the least value of $n$ for which the concave triangle occupies less than 0.1% of the L-section?\n

", "url": "https://projecteuler.net/problem=587", "answer": "2240"} {"id": 588, "problem": "The coefficients in the expansion of $(x+1)^k$ are called binomial coefficients.\n\nAnaloguously the coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$ are called quintinomial coefficients.\n(quintus= Latin for fifth).\n\nConsider the expansion of $(x^4+x^3+x^2+x+1)^3$:\n\n$x^{12}+3x^{11}+6x^{10}+10x^9+15x^8+18x^7+19x^6+18x^5+15x^4+10x^3+6x^2+3x+1$\n\nAs we can see $7$ out of the $13$ quintinomial coefficients for $k=3$ are odd.\n\nLet $Q(k)$ be the number of odd coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$.\n\nSo $Q(3)=7$.\n\nYou are given $Q(10)=17$ and $Q(100)=35$.\n\nFind $\\sum_{k=1}^{18}Q(10^k)$.", "raw_html": "

\nThe coefficients in the expansion of $(x+1)^k$ are called binomial coefficients.
\nAnaloguously the coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$ are called quintinomial coefficients.
(quintus= Latin for fifth).\n

\n

\nConsider the expansion of $(x^4+x^3+x^2+x+1)^3$:
\n$x^{12}+3x^{11}+6x^{10}+10x^9+15x^8+18x^7+19x^6+18x^5+15x^4+10x^3+6x^2+3x+1$
\nAs we can see $7$ out of the $13$ quintinomial coefficients for $k=3$ are odd.\n

\n

\nLet $Q(k)$ be the number of odd coefficients in the expansion of $(x^4+x^3+x^2+x+1)^k$.
\nSo $Q(3)=7$.\n

\n

\nYou are given $Q(10)=17$ and $Q(100)=35$.\n

\n

Find $\\sum_{k=1}^{18}Q(10^k)$.\n

", "url": "https://projecteuler.net/problem=588", "answer": "11651930052"} {"id": 589, "problem": "Christopher Robin and Pooh Bear love the game of Poohsticks so much that they invented a new version which allows them to play for longer before one of them wins and they have to go home for tea. The game starts as normal with both dropping a stick simultaneously on the upstream side of a bridge. But rather than the game ending when one of the sticks emerges on the downstream side, instead they fish their sticks out of the water, and drop them back in again on the upstream side. The game only ends when one of the sticks emerges from under the bridge ahead of the other one having also 'lapped' the other stick - that is, having made one additional journey under the bridge compared to the other stick.\n\nOn a particular day when playing this game, the time taken for a stick to travel under the bridge varies between a minimum of 30 seconds, and a maximum of 60 seconds. The time taken to fish a stick out of the water and drop it back in again on the other side is 5 seconds. The current under the bridge has the unusual property that the sticks' journey time is always an integral number of seconds, and it is equally likely to emerge at any of the possible times between 30 and 60 seconds (inclusive). It turns out that under these circumstances, the expected time for playing a single game is 1036.15 seconds (rounded to 2 decimal places). This time is measured from the point of dropping the sticks for the first time, to the point where the winning stick emerges from under the bridge having lapped the other.\n\nThe stream flows at different rates each day, but maintains the property that the journey time in seconds is equally distributed amongst the integers from a minimum, $n$, to a maximum, $m$, inclusive. Let the expected time of play in seconds be $E(m,n)$. Hence $E(60,30)=1036.15...$\n\nLet $S(k)=\\sum_{m=2}^k\\sum_{n=1}^{m-1}E(m,n)$.\n\nFor example $S(5)=7722.82$ rounded to 2 decimal places.\n\nFind $S(100)$ and give your answer rounded to 2 decimal places.", "raw_html": "

\nChristopher Robin and Pooh Bear love the game of Poohsticks so much that they invented a new version which allows them to play for longer before one of them wins and they have to go home for tea. The game starts as normal with both dropping a stick simultaneously on the upstream side of a bridge. But rather than the game ending when one of the sticks emerges on the downstream side, instead they fish their sticks out of the water, and drop them back in again on the upstream side. The game only ends when one of the sticks emerges from under the bridge ahead of the other one having also 'lapped' the other stick - that is, having made one additional journey under the bridge compared to the other stick.\n

\n

\nOn a particular day when playing this game, the time taken for a stick to travel under the bridge varies between a minimum of 30 seconds, and a maximum of 60 seconds. The time taken to fish a stick out of the water and drop it back in again on the other side is 5 seconds. The current under the bridge has the unusual property that the sticks' journey time is always an integral number of seconds, and it is equally likely to emerge at any of the possible times between 30 and 60 seconds (inclusive). It turns out that under these circumstances, the expected time for playing a single game is 1036.15 seconds (rounded to 2 decimal places). This time is measured from the point of dropping the sticks for the first time, to the point where the winning stick emerges from under the bridge having lapped the other.\n

\n

\nThe stream flows at different rates each day, but maintains the property that the journey time in seconds is equally distributed amongst the integers from a minimum, $n$, to a maximum, $m$, inclusive. Let the expected time of play in seconds be $E(m,n)$. Hence $E(60,30)=1036.15...$\n

\n

\nLet $S(k)=\\sum_{m=2}^k\\sum_{n=1}^{m-1}E(m,n)$.\n

\n

\nFor example $S(5)=7722.82$ rounded to 2 decimal places.\n

\n

\nFind $S(100)$ and give your answer rounded to 2 decimal places.\n

", "url": "https://projecteuler.net/problem=589", "answer": "131776959.25"} {"id": 590, "problem": "Let $H(n)$ denote the number of sets of positive integers such that the least common multiple of the integers in the set equals $n$.\n\nE.g.:\n\nThe integers in the following ten sets all have a least common multiple of $6$:\n\n$\\{2,3\\}$, $\\{1,2,3\\}$, $\\{6\\}$, $\\{1,6\\}$, $\\{2,6\\}$, $\\{1,2,6\\}$, $\\{3,6\\}$, $\\{1,3,6\\}$, $\\{2,3,6\\}$ and $\\{1,2,3,6\\}$.\n\nThus $H(6)=10$.\n\nLet $L(n)$ denote the least common multiple of the numbers $1$ through $n$.\n\nE.g. $L(6)$ is the least common multiple of the numbers $1,2,3,4,5,6$ and $L(6)$ equals $60$.\n\nLet $HL(n)$ denote $H(L(n))$.\n\nYou are given $HL(4)=H(12)=44$.\n\nFind $HL(50000)$. Give your answer modulo $10^9$.", "raw_html": "

\nLet $H(n)$ denote the number of sets of positive integers such that the least common multiple of the integers in the set equals $n$.
\nE.g.:
\nThe integers in the following ten sets all have a least common multiple of $6$:
\n$\\{2,3\\}$, $\\{1,2,3\\}$, $\\{6\\}$, $\\{1,6\\}$, $\\{2,6\\}$, $\\{1,2,6\\}$, $\\{3,6\\}$, $\\{1,3,6\\}$, $\\{2,3,6\\}$ and $\\{1,2,3,6\\}$.
\nThus $H(6)=10$.\n

\n

\nLet $L(n)$ denote the least common multiple of the numbers $1$ through $n$.
\nE.g. $L(6)$ is the least common multiple of the numbers $1,2,3,4,5,6$ and $L(6)$ equals $60$.\n

\n

\nLet $HL(n)$ denote $H(L(n))$.
\nYou are given $HL(4)=H(12)=44$.\n

\n

\nFind $HL(50000)$. Give your answer modulo $10^9$.\n

", "url": "https://projecteuler.net/problem=590", "answer": "834171904"} {"id": 591, "problem": "Given a non-square integer $d$, any real $x$ can be approximated arbitrarily close by quadratic integers $a+b\\sqrt{d}$, where $a,b$ are integers. For example, the following inequalities approximate $\\pi$ with precision $10^{-13}$:\n\n$$4375636191520\\sqrt{2}-6188084046055 < \\pi < 721133315582\\sqrt{2}-1019836515172 $$\n\nWe call $BQA_d(x,n)$ the quadratic integer closest to $x$ with the absolute values of $a,b$ not exceeding $n$.\nWe also define the integral part of a quadratic integer as $I_d(a+b\\sqrt{d}) = a$.\n\nYou are given that:\n\n- $BQA_2(\\pi,10) = 6 - 2\\sqrt{2}$\n\n- $BQA_5(\\pi,100)=26\\sqrt{5}-55$\n\n- $BQA_7(\\pi,10^6)=560323 - 211781\\sqrt{7}$\n\n- $I_2(BQA_2(\\pi,10^{13}))=-6188084046055$\n\nFind the sum of $|I_d(BQA_d(\\pi,10^{13}))|$ for all non-square positive integers less than 100.", "raw_html": "

Given a non-square integer $d$, any real $x$ can be approximated arbitrarily close by quadratic integers $a+b\\sqrt{d}$, where $a,b$ are integers. For example, the following inequalities approximate $\\pi$ with precision $10^{-13}$:
\n$$4375636191520\\sqrt{2}-6188084046055 < \\pi < 721133315582\\sqrt{2}-1019836515172 $$
\nWe call $BQA_d(x,n)$ the quadratic integer closest to $x$ with the absolute values of $a,b$ not exceeding $n$.
We also define the integral part of a quadratic integer as $I_d(a+b\\sqrt{d}) = a$.

\n\n

You are given that:

\n
  • $BQA_2(\\pi,10) = 6 - 2\\sqrt{2}$
  • \n
  • $BQA_5(\\pi,100)=26\\sqrt{5}-55$
  • \n
  • $BQA_7(\\pi,10^6)=560323 - 211781\\sqrt{7}$
  • \n
  • $I_2(BQA_2(\\pi,10^{13}))=-6188084046055$
\n\n

Find the sum of $|I_d(BQA_d(\\pi,10^{13}))|$ for all non-square positive integers less than 100.

", "url": "https://projecteuler.net/problem=591", "answer": "526007984625966"} {"id": 592, "problem": "For any $N$, let $f(N)$ be the last twelve hexadecimal digits before the trailing zeroes in $N!$.\n\nFor example, the hexadecimal representation of $20!$ is 21C3677C82B40000,\n\nso $f(20)$ is the digit sequence 21C3677C82B4.\n\nFind $f(20!)$. Give your answer as twelve hexadecimal digits, using uppercase for the digits A to F.", "raw_html": "

For any $N$, let $f(N)$ be the last twelve hexadecimal digits before the trailing zeroes in $N!$.

\n\n

For example, the hexadecimal representation of $20!$ is 21C3677C82B40000,
\nso $f(20)$ is the digit sequence 21C3677C82B4.

\n\n

Find $f(20!)$. Give your answer as twelve hexadecimal digits, using uppercase for the digits A to F.

", "url": "https://projecteuler.net/problem=592", "answer": "13415DF2BE9C"} {"id": 593, "problem": "We define two sequences $S = \\{S(1), S(2), ..., S(n)\\}$ and $S_2 = \\{S_2(1), S_2(2), ..., S_2(n)\\}$:\n\n$S(k) = (p_k)^k \\bmod 10007$ where $p_k$ is the $k$th prime number.\n\n$S_2(k) = S(k) + S(\\lfloor\\frac{k}{10000}\\rfloor + 1)$ where $\\lfloor \\cdot \\rfloor$ denotes the floor function.\n\nThen let $M(i, j)$ be the median of elements $S_2(i)$ through $S_2(j)$, inclusive. For example, $M(1, 10) = 2021.5$ and $M(10^2, 10^3) = 4715.0$.\n\nLet $F(n, k) = \\sum_{i=1}^{n-k+1} M(i, i + k - 1)$. For example, $F(100, 10) = 463628.5$ and $F(10^5, 10^4) = 675348207.5$.\n\nFind $F(10^7, 10^5)$. If the sum is not an integer, use $.5$ to denote a half. Otherwise, use $.0$ instead.", "raw_html": "

We define two sequences $S = \\{S(1), S(2), ..., S(n)\\}$ and $S_2 = \\{S_2(1), S_2(2), ..., S_2(n)\\}$:

\n\n

$S(k) = (p_k)^k \\bmod 10007$ where $p_k$ is the $k$th prime number.

\n\n

$S_2(k) = S(k) + S(\\lfloor\\frac{k}{10000}\\rfloor + 1)$ where $\\lfloor \\cdot \\rfloor$ denotes the floor function.

\n\n

Then let $M(i, j)$ be the median of elements $S_2(i)$ through $S_2(j)$, inclusive. For example, $M(1, 10) = 2021.5$ and $M(10^2, 10^3) = 4715.0$.

\n\n

Let $F(n, k) = \\sum_{i=1}^{n-k+1} M(i, i + k - 1)$. For example, $F(100, 10) = 463628.5$ and $F(10^5, 10^4) = 675348207.5$.

\n\n

Find $F(10^7, 10^5)$. If the sum is not an integer, use $.5$ to denote a half. Otherwise, use $.0$ instead.

", "url": "https://projecteuler.net/problem=593", "answer": "96632320042.0"} {"id": 594, "problem": "For a polygon $P$, let $t(P)$ be the number of ways in which $P$ can be tiled using rhombi and squares with edge length 1. Distinct rotations and reflections are counted as separate tilings.\n\nFor example, if $O$ is a regular octagon with edge length 1, then $t(O) = 8$. As it happens, all these 8 tilings are rotations of one another:\n\nLet $O_{a,b}$ be the equal-angled convex octagon whose edges alternate in length between $a$ and $b$.\n\nFor example, here is $O_{2,1}$, with one of its tilings:\n\nYou are given that $t(O_{1,1})=8$, $t(O_{2,1})=76$ and $t(O_{3,2})=456572$.\n\nFind $t(O_{4,2})$.", "raw_html": "

\nFor a polygon $P$, let $t(P)$ be the number of ways in which $P$ can be tiled using rhombi and squares with edge length 1. Distinct rotations and reflections are counted as separate tilings.\n

\n

\nFor example, if $O$ is a regular octagon with edge length 1, then $t(O) = 8$. As it happens, all these 8 tilings are rotations of one another:\n

\n
\n\"0594_octagon_tilings_1.png\"\n
\n

\nLet $O_{a,b}$ be the equal-angled convex octagon whose edges alternate in length between $a$ and $b$.\n
\nFor example, here is $O_{2,1}$, with one of its tilings:\n

\n
\n\"0594_octagon_tilings_2.png\"\n
\n\n

\nYou are given that $t(O_{1,1})=8$, $t(O_{2,1})=76$ and $t(O_{3,2})=456572$.\n

\n

\nFind $t(O_{4,2})$.\n

", "url": "https://projecteuler.net/problem=594", "answer": "47067598"} {"id": 595, "problem": "A deck of cards numbered from $1$ to $n$ is shuffled randomly such that each permutation is equally likely.\n\nThe cards are to be sorted into ascending order using the following technique:\n\n- Look at the initial sequence of cards. If it is already sorted, then there is no need for further action. Otherwise, if any subsequences of cards happen to be in the correct place relative to one another (ascending with no gaps), then those subsequences are fixed by attaching the cards together. For example, with $7$ cards initially in the order 4123756, the cards labelled 1, 2 and 3 would be attached together, as would 5 and 6.\n\n- The cards are 'shuffled' by being thrown into the air, but note that any correctly sequenced cards remain attached, so their orders are maintained. The cards (or bundles of attached cards) are then picked up randomly. You should assume that this randomisation is unbiased, despite the fact that some cards are single, and others are grouped together.\n\n- Repeat steps 1 and 2 until the cards are sorted.\n\nLet $S(n)$ be the expected number of shuffles needed to sort the cards. Since the order is checked before the first shuffle, $S(1) = 0$. You are given that $S(2) = 1$, and $S(5) = 4213/871$.\n\nFind $S(52)$, and give your answer rounded to $8$ decimal places.", "raw_html": "

\nA deck of cards numbered from $1$ to $n$ is shuffled randomly such that each permutation is equally likely.\n

\n

\nThe cards are to be sorted into ascending order using the following technique:\n

    \n
  1. Look at the initial sequence of cards. If it is already sorted, then there is no need for further action. Otherwise, if any subsequences of cards happen to be in the correct place relative to one another (ascending with no gaps), then those subsequences are fixed by attaching the cards together. For example, with $7$ cards initially in the order 4123756, the cards labelled 1, 2 and 3 would be attached together, as would 5 and 6.\n
\n
    \n
  1. The cards are 'shuffled' by being thrown into the air, but note that any correctly sequenced cards remain attached, so their orders are maintained. The cards (or bundles of attached cards) are then picked up randomly. You should assume that this randomisation is unbiased, despite the fact that some cards are single, and others are grouped together. \n
\n
    \n
  1. Repeat steps 1 and 2 until the cards are sorted. \n
\n\n

\n Let $S(n)$ be the expected number of shuffles needed to sort the cards. Since the order is checked before the first shuffle, $S(1) = 0$. You are given that $S(2) = 1$, and $S(5) = 4213/871$.\n

\n

\nFind $S(52)$, and give your answer rounded to $8$ decimal places.\n

", "url": "https://projecteuler.net/problem=595", "answer": "54.17529329"} {"id": 596, "problem": "Let $T(r)$ be the number of integer quadruplets $x, y, z, t$ such that $x^2 + y^2 + z^2 + t^2 \\le r^2$. In other words, $T(r)$ is the number of lattice points in the four-dimensional hyperball of radius $r$.\n\nYou are given that $T(2) = 89$, $T(5) = 3121$, $T(100) = 493490641$ and $T(10^4) = 49348022079085897$.\n\nFind $T(10^8) \\bmod 1000000007$.", "raw_html": "

Let $T(r)$ be the number of integer quadruplets $x, y, z, t$ such that $x^2 + y^2 + z^2 + t^2 \\le r^2$. In other words, $T(r)$ is the number of lattice points in the four-dimensional hyperball of radius $r$.

\n\n

You are given that $T(2) = 89$, $T(5) = 3121$, $T(100) = 493490641$ and $T(10^4) = 49348022079085897$.

\n\n

Find $T(10^8) \\bmod 1000000007$.

", "url": "https://projecteuler.net/problem=596", "answer": "734582049"} {"id": 597, "problem": "The Torpids are rowing races held annually in Oxford, following some curious rules:\n\n-\nA division consists of $n$ boats (typically 13), placed in order based on past performance.\n\n-\nAll boats within a division start at 40 metre intervals along the river, in order with the highest-placed boat starting furthest upstream.\n\n-\nThe boats all start rowing simultaneously, upstream, trying to catch the boat in front while avoiding being caught by boats behind.\n\n-\nEach boat continues rowing until either it reaches the finish line or it catches up with (\"bumps\") a boat in front.\n\n-\nThe finish line is a distance $L$ metres (the course length, in reality about 1800 metres) upstream from the starting position of the lowest-placed boat. (Because of the staggered starting positions, higher-placed boats row a slightly shorter course than lower-placed boats.)\n\n-\nWhen a \"bump\" occurs, the \"bumping\" boat takes no further part in the race. The \"bumped\" boat must continue, however, and may even be \"bumped\" again by boats that started two or more places behind it.\n\n-\nAfter the race, boats are assigned new places within the division, based on the bumps that occurred. Specifically, for any boat $A$ that started in a lower place than $B$, then $A$ will be placed higher than $B$ in the new order if and only if one of the following occurred:\n\n\n- $A$ bumped $B$ directly\n\n- $A$ bumped another boat that went on to bump $B$\n\n- $A$ bumped another boat, that bumped yet another boat, that bumped $B$\n\n- etc\n\nNOTE: For the purposes of this problem you may disregard the boats' lengths, and assume that a bump occurs precisely when the two boats draw level. (In reality, a bump is awarded as soon as physical contact is made, which usually occurs when there is much less than a full boat length's overlap.)\n\nSuppose that, in a particular race, each boat $B_j$ rows at a steady speed $v_j = -$log$X_j$ metres per second, where the $X_j$ are chosen randomly (with uniform distribution) between 0 and 1, independently from one another. These speeds are relative to the riverbank: you may disregard the flow of the river.\n\nLet $p(n,L)$ be the probability that the new order is an even permutation of the starting order, when there are $n$ boats in the division and $L$ is the course length.\n\nFor example, with $n=3$ and $L=160$, labelling the boats as $A$,$B$,$C$ in starting order with $C$ highest, the different possible outcomes of the race are as follows:\n\n| Bumps occurring | New order | Permutation | Probability |\n| --- | --- | --- | --- |\n| none | $A$, $B$, $C$ | even | $4/15$ |\n| $B$ bumps $C$ | $A$, $C$, $B$ | odd | $8/45$ |\n| $A$ bumps $B$ | $B$, $A$, $C$ | odd | $1/3$ |\n| $B$ bumps $C$, then $A$ bumps $C$ | $C$, $A$, $B$ | even | $4/27$ |\n| $A$ bumps $B$, then $B$ bumps $C$ | $C$, $B$, $A$ | odd | $2/27$ |\n\nTherefore, $p(3,160) = 4/15 + 4/27 = 56/135$.\n\nYou are also given that $p(4,400)=0.5107843137$, rounded to 10 digits after the decimal point.\n\nFind $p(13,1800)$ rounded to 10 digits after the decimal point.", "raw_html": "The Torpids are rowing races held annually in Oxford, following some curious rules:\n\n
    \n
  • \nA division consists of $n$ boats (typically 13), placed in order based on past performance.\n
  • \nAll boats within a division start at 40 metre intervals along the river, in order with the highest-placed boat starting furthest upstream.\n
  • \nThe boats all start rowing simultaneously, upstream, trying to catch the boat in front while avoiding being caught by boats behind.\n
  • \nEach boat continues rowing until either it reaches the finish line or it catches up with (\"bumps\") a boat in front.\n
  • \nThe finish line is a distance $L$ metres (the course length, in reality about 1800 metres) upstream from the starting position of the lowest-placed boat. (Because of the staggered starting positions, higher-placed boats row a slightly shorter course than lower-placed boats.)\n
  • \nWhen a \"bump\" occurs, the \"bumping\" boat takes no further part in the race. The \"bumped\" boat must continue, however, and may even be \"bumped\" again by boats that started two or more places behind it.\n
  • \nAfter the race, boats are assigned new places within the division, based on the bumps that occurred. Specifically, for any boat $A$ that started in a lower place than $B$, then $A$ will be placed higher than $B$ in the new order if and only if one of the following occurred:\n
      \n
    1. $A$ bumped $B$ directly
    2. \n
    3. $A$ bumped another boat that went on to bump $B$
    4. \n
    5. $A$ bumped another boat, that bumped yet another boat, that bumped $B$
    6. \n
    7. etc
    \n
\n\nNOTE: For the purposes of this problem you may disregard the boats' lengths, and assume that a bump occurs precisely when the two boats draw level. (In reality, a bump is awarded as soon as physical contact is made, which usually occurs when there is much less than a full boat length's overlap.)\n\n

\nSuppose that, in a particular race, each boat $B_j$ rows at a steady speed $v_j = -$log$X_j$ metres per second, where the $X_j$ are chosen randomly (with uniform distribution) between 0 and 1, independently from one another. These speeds are relative to the riverbank: you may disregard the flow of the river.\n

\n

\nLet $p(n,L)$ be the probability that the new order is an even permutation of the starting order, when there are $n$ boats in the division and $L$ is the course length.\n

\n

\nFor example, with $n=3$ and $L=160$, labelling the boats as $A$,$B$,$C$ in starting order with $C$ highest, the different possible outcomes of the race are as follows:\n

\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
Bumps occurring New order Permutation Probability
none $A$, $B$, $C$ even $4/15$
$B$ bumps $C$ $A$, $C$, $B$ odd $8/45$
$A$ bumps $B$ $B$, $A$, $C$ odd $1/3$
    $B$ bumps $C$, then $A$ bumps $C$     $C$, $A$, $B$ even $4/27$
    $A$ bumps $B$, then $B$ bumps $C$     $C$, $B$, $A$ odd $2/27$
\n

\nTherefore, $p(3,160) = 4/15 + 4/27 = 56/135$.\n

\n

\nYou are also given that $p(4,400)=0.5107843137$, rounded to 10 digits after the decimal point.\n

\n

\nFind $p(13,1800)$ rounded to 10 digits after the decimal point.\n

", "url": "https://projecteuler.net/problem=597", "answer": "0.5001817828"} {"id": 598, "problem": "Consider the number $48$.\n\nThere are five pairs of integers $a$ and $b$ ($a \\leq b$) such that $a \\times b=48$: $(1,48)$, $(2,24)$, $(3,16)$, $(4,12)$ and $(6,8)$.\n\nIt can be seen that both $6$ and $8$ have $4$ divisors.\n\nSo of those five pairs one consists of two integers with the same number of divisors.\n\nIn general:\n\nLet $C(n)$ be the number of pairs of positive integers $a \\times b=n$, ($a \\leq b$) such that $a$ and $b$ have the same number of divisors;\nso $C(48)=1$.\n\nYou are given $C(10!)=3$: $(1680, 2160)$, $(1800, 2016)$ and $(1890,1920)$.\n\n\nFind $C(100!)$.", "raw_html": "

\nConsider the number $48$.
\nThere are five pairs of integers $a$ and $b$ ($a \\leq b$) such that $a \\times b=48$: $(1,48)$, $(2,24)$, $(3,16)$, $(4,12)$ and $(6,8)$.
\nIt can be seen that both $6$ and $8$ have $4$ divisors.
\nSo of those five pairs one consists of two integers with the same number of divisors.

\n

\nIn general:
\nLet $C(n)$ be the number of pairs of positive integers $a \\times b=n$, ($a \\leq b$) such that $a$ and $b$ have the same number of divisors;
so $C(48)=1$.\n

\n

\nYou are given $C(10!)=3$: $(1680, 2160)$, $(1800, 2016)$ and $(1890,1920)$.

\nFind $C(100!)$.

", "url": "https://projecteuler.net/problem=598", "answer": "543194779059"} {"id": 599, "problem": "The well-known Rubik's Cube puzzle has many fascinating mathematical properties. The 2×2×2 variant has 8 cubelets with a total of 24 visible faces, each with a coloured sticker. Successively turning faces will rearrange the cubelets, although not all arrangements of cubelets are reachable without dismantling the puzzle.\n\nSuppose that we wish to apply new stickers to a 2×2×2 Rubik's cube in a non-standard colouring. Specifically, we have $n$ different colours available (with an unlimited supply of stickers of each colour), and we place one sticker on each of the 24 faces in any arrangement that we please. We are not required to use all the colours, and if desired the same colour may appear in more than one face of a single cubelet.\n\nWe say that two such colourings $c_1,c_2$ are essentially distinct if a cube coloured according to $c_1$ cannot be made to match a cube coloured according to $c_2$ by performing mechanically possible Rubik's Cube moves.\n\nFor example, with two colours available, there are 183 essentially distinct colourings.\n\nHow many essentially distinct colourings are there with 10 different colours available?", "raw_html": "

\nThe well-known Rubik's Cube puzzle has many fascinating mathematical properties. The 2×2×2 variant has 8 cubelets with a total of 24 visible faces, each with a coloured sticker. Successively turning faces will rearrange the cubelets, although not all arrangements of cubelets are reachable without dismantling the puzzle.\n

\n

\nSuppose that we wish to apply new stickers to a 2×2×2 Rubik's cube in a non-standard colouring. Specifically, we have $n$ different colours available (with an unlimited supply of stickers of each colour), and we place one sticker on each of the 24 faces in any arrangement that we please. We are not required to use all the colours, and if desired the same colour may appear in more than one face of a single cubelet.\n

\n

\nWe say that two such colourings $c_1,c_2$ are essentially distinct if a cube coloured according to $c_1$ cannot be made to match a cube coloured according to $c_2$ by performing mechanically possible Rubik's Cube moves.\n

\n

\nFor example, with two colours available, there are 183 essentially distinct colourings.\n

\n

\nHow many essentially distinct colourings are there with 10 different colours available?\n

", "url": "https://projecteuler.net/problem=599", "answer": "12395526079546335"} {"id": 600, "problem": "Let $H(n)$ be the number of distinct integer sided equiangular convex hexagons with perimeter not exceeding $n$.\n\nHexagons are distinct if and only if they are not congruent.\n\nYou are given $H(6) = 1$, $H(12) = 10$, $H(100) = 31248$.\n\nFind $H(55106)$.\n\nEquiangular hexagons with perimeter not exceeding $12$", "raw_html": "

Let $H(n)$ be the number of distinct integer sided equiangular convex hexagons with perimeter not exceeding $n$.
\nHexagons are distinct if and only if they are not congruent.

\n\n

You are given $H(6) = 1$, $H(12) = 10$, $H(100) = 31248$.
\nFind $H(55106)$.

\n\n
\n\"p600-equiangular-hexagons.png\"\n

Equiangular hexagons with perimeter not exceeding $12$

\n
", "url": "https://projecteuler.net/problem=600", "answer": "2668608479740672"} {"id": 601, "problem": "For every positive number $n$ we define the function $\\mathop{streak}(n)=k$ as the smallest positive integer $k$ such that $n+k$ is not divisible by $k+1$.\n\nE.g:\n\n$13$ is divisible by $1$\n\n$14$ is divisible by $2$\n\n$15$ is divisible by $3$\n\n$16$ is divisible by $4$\n\n$17$ is NOT divisible by $5$\n\nSo $\\mathop{streak}(13) = 4$.\n\nSimilarly:\n\n$120$ is divisible by $1$\n\n$121$ is NOT divisible by $2$\n\nSo $\\mathop{streak}(120) = 1$.\n\nDefine $P(s, N)$ to be the number of integers $n$, $1 \\lt n \\lt N$, for which $\\mathop{streak}(n) = s$.\n\nSo $P(3, 14) = 1$ and $P(6, 10^6) = 14286$.\n\nFind the sum, as $i$ ranges from $1$ to $31$, of $P(i, 4^i)$.", "raw_html": "

\nFor every positive number $n$ we define the function $\\mathop{streak}(n)=k$ as the smallest positive integer $k$ such that $n+k$ is not divisible by $k+1$.
\nE.g:
\n$13$ is divisible by $1$
\n$14$ is divisible by $2$
\n$15$ is divisible by $3$
\n$16$ is divisible by $4$
\n$17$ is NOT divisible by $5$
\nSo $\\mathop{streak}(13) = 4$.
\nSimilarly:
\n$120$ is divisible by $1$
\n$121$ is NOT divisible by $2$
\nSo $\\mathop{streak}(120) = 1$.

\n

\n\nDefine $P(s, N)$ to be the number of integers $n$, $1 \\lt n \\lt N$, for which $\\mathop{streak}(n) = s$.
\nSo $P(3, 14) = 1$ and $P(6, 10^6) = 14286$.\n

\n

\nFind the sum, as $i$ ranges from $1$ to $31$, of $P(i, 4^i)$.\n

", "url": "https://projecteuler.net/problem=601", "answer": "1617243"} {"id": 602, "problem": "Alice enlists the help of some friends to generate a random number, using a single unfair coin. She and her friends sit around a table and, starting with Alice, they take it in turns to toss the coin. Everyone keeps a count of how many heads they obtain individually. The process ends as soon as Alice obtains a Head. At this point, Alice multiplies all her friends' Head counts together to obtain her random number.\n\nAs an illustration, suppose Alice is assisted by Bob, Charlie, and Dawn, who are seated round the table in that order, and that they obtain the sequence of Head/Tail outcomes THHH—TTTT—THHT—H beginning and ending with Alice. Then Bob and Charlie each obtain 2 heads, and Dawn obtains 1 head. Alice's random number is therefore $2\\times 2\\times 1 = 4$.\n\nDefine $e(n, p)$ to be the expected value of Alice's random number, where $n$ is the number of friends helping (excluding Alice herself), and $p$ is the probability of the coin coming up Tails.\n\nIt turns out that, for any fixed $n$, $e(n, p)$ is always a polynomial in $p$. For example, $e(3, p) = p^3 + 4p^2 + p$.\n\nDefine $c(n, k)$ to be the coefficient of $p^k$ in the polynomial $e(n, p)$. So $c(3, 1) = 1$, $c(3, 2) = 4$, and $c(3, 3) = 1$.\n\nYou are given that $c(100, 40) \\equiv 986699437 \\text{ } (\\text{mod } 10^9+7)$.\n\nFind $c(10000000, 4000000) \\mod 10^9+7$.", "raw_html": "

\nAlice enlists the help of some friends to generate a random number, using a single unfair coin. She and her friends sit around a table and, starting with Alice, they take it in turns to toss the coin. Everyone keeps a count of how many heads they obtain individually. The process ends as soon as Alice obtains a Head. At this point, Alice multiplies all her friends' Head counts together to obtain her random number.\n

\n

\nAs an illustration, suppose Alice is assisted by Bob, Charlie, and Dawn, who are seated round the table in that order, and that they obtain the sequence of Head/Tail outcomes THHH—TTTT—THHT—H beginning and ending with Alice. Then Bob and Charlie each obtain 2 heads, and Dawn obtains 1 head. Alice's random number is therefore $2\\times 2\\times 1 = 4$.\n

\n

\nDefine $e(n, p)$ to be the expected value of Alice's random number, where $n$ is the number of friends helping (excluding Alice herself), and $p$ is the probability of the coin coming up Tails.\n

\n

\nIt turns out that, for any fixed $n$, $e(n, p)$ is always a polynomial in $p$. For example, $e(3, p) = p^3 + 4p^2 + p$.\n

\n

\nDefine $c(n, k)$ to be the coefficient of $p^k$ in the polynomial $e(n, p)$. So $c(3, 1) = 1$, $c(3, 2) = 4$, and $c(3, 3) = 1$.\n

\n

\nYou are given that $c(100, 40) \\equiv 986699437 \\text{ } (\\text{mod } 10^9+7)$.\n

\n

\nFind $c(10000000, 4000000) \\mod 10^9+7$.\n

", "url": "https://projecteuler.net/problem=602", "answer": "269496760"} {"id": 603, "problem": "Let $S(n)$ be the sum of all contiguous integer-substrings that can be formed from the integer $n$. The substrings need not be distinct.\n\nFor example, $S(2024) = 2 + 0 + 2 + 4 + 20 + 02 + 24 + 202 + 024 + 2024 = 2304$.\n\nLet $P(n)$ be the integer formed by concatenating the first $n$ primes together. For example, $P(7) = 2357111317$.\n\nLet $C(n, k)$ be the integer formed by concatenating $k$ copies of $P(n)$ together. For example, $C(7, 3) = 235711131723571113172357111317$.\n\nEvaluate $S(C(10^6, 10^{12})) \\bmod (10^9 + 7)$.", "raw_html": "

Let $S(n)$ be the sum of all contiguous integer-substrings that can be formed from the integer $n$. The substrings need not be distinct.

\n\n

For example, $S(2024) = 2 + 0 + 2 + 4 + 20 + 02 + 24 + 202 + 024 + 2024 = 2304$.

\n\n

Let $P(n)$ be the integer formed by concatenating the first $n$ primes together. For example, $P(7) = 2357111317$.

\n\n

Let $C(n, k)$ be the integer formed by concatenating $k$ copies of $P(n)$ together. For example, $C(7, 3) = 235711131723571113172357111317$.

\n\n

Evaluate $S(C(10^6, 10^{12})) \\bmod (10^9 + 7)$.

", "url": "https://projecteuler.net/problem=603", "answer": "879476477"} {"id": 604, "problem": "Let $F(N)$ be the maximum number of lattice points in an axis-aligned $N\\times N$ square that the graph of a single strictly convex increasing function can pass through.\n\nYou are given that $F(1) = 2$, $F(3) = 3$, $F(9) = 6$, $F(11) = 7$, $F(100) = 30$ and $F(50000) = 1898$.\n\nBelow is the graph of a function reaching the maximum $3$ for $N=3$:\n\nFind $F(10^{18})$.", "raw_html": "

\nLet $F(N)$ be the maximum number of lattice points in an axis-aligned $N\\times N$ square that the graph of a single strictly convex increasing function can pass through.\n

\n

\nYou are given that $F(1) = 2$, $F(3) = 3$, $F(9) = 6$, $F(11) = 7$, $F(100) = 30$ and $F(50000) = 1898$.
\nBelow is the graph of a function reaching the maximum $3$ for $N=3$:\n

\n
\n\"0604_convex3.png\"
\n

\nFind $F(10^{18})$.\n

", "url": "https://projecteuler.net/problem=604", "answer": "1398582231101"} {"id": 605, "problem": "Consider an $n$-player game played in consecutive pairs: Round $1$ takes place between players $1$ and $2$, round $2$ takes place between players $2$ and $3$, and so on and so forth, all the way up to round $n$, which takes place between players $n$ and $1$. Then round $n+1$ takes place between players $1$ and $2$ as the entire cycle starts again.\n\nIn other words, during round $r$, player $((r-1) \\bmod n) + 1$ faces off against player $(r \\bmod n) + 1$.\n\nDuring each round, a fair coin is tossed to decide which of the two players wins that round. If any given player wins both rounds $r$ and $r+1$, then that player wins the entire game.\n\nLet $P_n(k)$ be the probability that player $k$ wins in an $n$-player game, in the form of a reduced fraction. For example, $P_3(1) = 12/49$ and $P_6(2) = 368/1323$.\n\nLet $M_n(k)$ be the product of the reduced numerator and denominator of $P_n(k)$. For example, $M_3(1) = 588$ and $M_6(2) = 486864$.\n\nFind the last $8$ digits of $M_{10^8+7}(10^4+7)$.", "raw_html": "

Consider an $n$-player game played in consecutive pairs: Round $1$ takes place between players $1$ and $2$, round $2$ takes place between players $2$ and $3$, and so on and so forth, all the way up to round $n$, which takes place between players $n$ and $1$. Then round $n+1$ takes place between players $1$ and $2$ as the entire cycle starts again.

\n\n

In other words, during round $r$, player $((r-1) \\bmod n) + 1$ faces off against player $(r \\bmod n) + 1$.

\n\n

During each round, a fair coin is tossed to decide which of the two players wins that round. If any given player wins both rounds $r$ and $r+1$, then that player wins the entire game.

\n\n

Let $P_n(k)$ be the probability that player $k$ wins in an $n$-player game, in the form of a reduced fraction. For example, $P_3(1) = 12/49$ and $P_6(2) = 368/1323$.

\n\n

Let $M_n(k)$ be the product of the reduced numerator and denominator of $P_n(k)$. For example, $M_3(1) = 588$ and $M_6(2) = 486864$.

\n\n

Find the last $8$ digits of $M_{10^8+7}(10^4+7)$.

", "url": "https://projecteuler.net/problem=605", "answer": "59992576"} {"id": 606, "problem": "A gozinta chain for $n$ is a sequence $\\{1,a,b,\\dots,n\\}$ where each element properly divides the next.\n\nFor example, there are eight distinct gozinta chains for $12$:\n\n$\\{1,12\\}$, $\\{1,2,12\\}$, $\\{1,2,4,12\\}$, $\\{1,2,6,12\\}$, $\\{1,3,12\\}$, $\\{1,3,6,12\\}$, $\\{1,4,12\\}$ and $\\{1,6,12\\}$.\n\nLet $S(n)$ be the sum of all numbers, $k$, not exceeding $n$, which have $252$ distinct gozinta chains.\n\nYou are given $S(10^6)=8462952$ and $S(10^{12})=623291998881978$.\n\nFind $S(10^{36})$, giving the last nine digits of your answer.", "raw_html": "

\nA gozinta chain for $n$ is a sequence $\\{1,a,b,\\dots,n\\}$ where each element properly divides the next.
\nFor example, there are eight distinct gozinta chains for $12$:
\n$\\{1,12\\}$, $\\{1,2,12\\}$, $\\{1,2,4,12\\}$, $\\{1,2,6,12\\}$, $\\{1,3,12\\}$, $\\{1,3,6,12\\}$, $\\{1,4,12\\}$ and $\\{1,6,12\\}$.\n

\n

\nLet $S(n)$ be the sum of all numbers, $k$, not exceeding $n$, which have $252$ distinct gozinta chains.
\nYou are given $S(10^6)=8462952$ and $S(10^{12})=623291998881978$.\n

\n

\nFind $S(10^{36})$, giving the last nine digits of your answer.\n

", "url": "https://projecteuler.net/problem=606", "answer": "158452775"} {"id": 607, "problem": "Frodo and Sam need to travel 100 leagues due East from point A to point B. On normal terrain, they can cover 10 leagues per day, and so the journey would take 10 days. However, their path is crossed by a long marsh which runs exactly South-West to North-East, and walking through the marsh will slow them down. The marsh is 50 leagues wide at all points, and the mid-point of AB is located in the middle of the marsh. A map of the region is shown in the diagram below:\n\nThe marsh consists of 5 distinct regions, each 10 leagues across, as shown by the shading in the map. The strip closest to point A is relatively light marsh, and can be crossed at a speed of 9 leagues per day. However, each strip becomes progressively harder to navigate, the speeds going down to 8, 7, 6 and finally 5 leagues per day for the final region of marsh, before it ends and the terrain becomes easier again, with the speed going back to 10 leagues per day.\n\nIf Frodo and Sam were to head directly East for point B, they would travel exactly 100 leagues, and the journey would take approximately 13.4738 days. However, this time can be shortened if they deviate from the direct path.\n\nFind the shortest possible time required to travel from point A to B, and give your answer in days, rounded to 10 decimal places.", "raw_html": "

\nFrodo and Sam need to travel 100 leagues due East from point A to point B. On normal terrain, they can cover 10 leagues per day, and so the journey would take 10 days. However, their path is crossed by a long marsh which runs exactly South-West to North-East, and walking through the marsh will slow them down. The marsh is 50 leagues wide at all points, and the mid-point of AB is located in the middle of the marsh. A map of the region is shown in the diagram below:\n

\n\n
\n\"0607_marsh.png\"
\n\n\n

\nThe marsh consists of 5 distinct regions, each 10 leagues across, as shown by the shading in the map. The strip closest to point A is relatively light marsh, and can be crossed at a speed of 9 leagues per day. However, each strip becomes progressively harder to navigate, the speeds going down to 8, 7, 6 and finally 5 leagues per day for the final region of marsh, before it ends and the terrain becomes easier again, with the speed going back to 10 leagues per day.\n

\n

\nIf Frodo and Sam were to head directly East for point B, they would travel exactly 100 leagues, and the journey would take approximately 13.4738 days. However, this time can be shortened if they deviate from the direct path.\n

\n

\nFind the shortest possible time required to travel from point A to B, and give your answer in days, rounded to 10 decimal places.\n

", "url": "https://projecteuler.net/problem=607", "answer": "13.1265108586"} {"id": 608, "problem": "Let $D(m,n)=\\displaystyle\\sum_{d\\mid m}\\sum_{k=1}^n\\sigma_0(kd)$ where $d$ runs through all divisors of $m$ and $\\sigma_0(n)$ is the number of divisors of $n$.\n\nYou are given $D(3!,10^2)=3398$ and $D(4!,10^6)=268882292$.\n\nFind $D(200!,10^{12}) \\bmod (10^9 + 7)$.", "raw_html": "

Let $D(m,n)=\\displaystyle\\sum_{d\\mid m}\\sum_{k=1}^n\\sigma_0(kd)$ where $d$ runs through all divisors of $m$ and $\\sigma_0(n)$ is the number of divisors of $n$.
\nYou are given $D(3!,10^2)=3398$ and $D(4!,10^6)=268882292$.

\n\n

Find $D(200!,10^{12}) \\bmod (10^9 + 7)$.

", "url": "https://projecteuler.net/problem=608", "answer": "439689828"} {"id": 609, "problem": "For every $n \\ge 1$ the prime-counting function $\\pi(n)$ is equal to the number of primes\nnot exceeding $n$.\n\nE.g. $\\pi(6)=3$ and $\\pi(100)=25$.\n\nWe say that a sequence of integers $u = (u_0,\\cdots,u_m)$ is a $\\pi$ sequence if\n\n- $u_n \\ge 1$ for every $n$\n\n- $u_{n+1}= \\pi(u_n)$\n\n- $u$ has two or more elements\n\nFor $u_0=10$ there are three distinct $\\pi$ sequences: $(10,4)$, $(10,4,2)$ and $(10,4,2,1)$.\n\nLet $c(u)$ be the number of elements of $u$ that are not prime.\n\nLet $p(n,k)$ be the number of $\\pi$ sequences $u$ for which $u_0\\le n$ and $c(u)=k$.\n\nLet $P(n)$ be the product of all $p(n,k)$ that are larger than $0$.\n\nYou are given: $P(10)=3 \\times 8 \\times 9 \\times 3=648$ and $P(100)=31038676032$.\n\nFind $P(10^8)$. Give your answer modulo $1000000007$.", "raw_html": "

\nFor every $n \\ge 1$ the prime-counting function $\\pi(n)$ is equal to the number of primes\nnot exceeding $n$.
\nE.g. $\\pi(6)=3$ and $\\pi(100)=25$.\n

\n

\nWe say that a sequence of integers $u = (u_0,\\cdots,u_m)$ is a $\\pi$ sequence if \n

    \n
  • $u_n \\ge 1$ for every $n$\n
  • $u_{n+1}= \\pi(u_n)$\n
  • $u$ has two or more elements\n
\n

\nFor $u_0=10$ there are three distinct $\\pi$ sequences: $(10,4)$, $(10,4,2)$ and $(10,4,2,1)$.\n

\n

\nLet $c(u)$ be the number of elements of $u$ that are not prime.
\nLet $p(n,k)$ be the number of $\\pi$ sequences $u$ for which $u_0\\le n$ and $c(u)=k$.
\nLet $P(n)$ be the product of all $p(n,k)$ that are larger than $0$.
\nYou are given: $P(10)=3 \\times 8 \\times 9 \\times 3=648$ and $P(100)=31038676032$.\n

\n

\nFind $P(10^8)$. Give your answer modulo $1000000007$. \n

", "url": "https://projecteuler.net/problem=609", "answer": "172023848"} {"id": 610, "problem": "A random generator produces a sequence of symbols drawn from the set {I, V, X, L, C, D, M, #}. Each item in the sequence is determined by selecting one of these symbols at random, independently of the other items in the sequence. At each step, the seven letters are equally likely to be selected, with probability 14% each, but the # symbol only has a 2% chance of selection.\n\nWe write down the sequence of letters from left to right as they are generated, and we stop at the first occurrence of the # symbol (without writing it). However, we stipulate that what we have written down must always (when non-empty) be a valid Roman numeral representation in minimal form. If appending the next letter would contravene this then we simply skip it and try again with the next symbol generated.\n\nPlease take careful note of About... Roman Numerals for the definitive rules for this problem on what constitutes a \"valid Roman numeral representation\" and \"minimal form\". For example, the (only) sequence that represents 49 is XLIX. The subtractive combination IL is invalid because of rule (ii), while XXXXIX is valid but not minimal. The rules do not place any restriction on the number of occurrences of M, so all positive integers have a valid representation. These are the same rules as were used in Problem 89, and members are invited to solve that problem first.\n\nFind the expected value of the number represented by what we have written down when we stop. (If nothing is written down then count that as zero.) Give your answer rounded to 8 places after the decimal point.", "raw_html": "

A random generator produces a sequence of symbols drawn from the set {I, V, X, L, C, D, M, #}. Each item in the sequence is determined by selecting one of these symbols at random, independently of the other items in the sequence. At each step, the seven letters are equally likely to be selected, with probability 14% each, but the # symbol only has a 2% chance of selection.

\n\n

We write down the sequence of letters from left to right as they are generated, and we stop at the first occurrence of the # symbol (without writing it). However, we stipulate that what we have written down must always (when non-empty) be a valid Roman numeral representation in minimal form. If appending the next letter would contravene this then we simply skip it and try again with the next symbol generated.

\n\n

Please take careful note of About... Roman Numerals for the definitive rules for this problem on what constitutes a \"valid Roman numeral representation\" and \"minimal form\". For example, the (only) sequence that represents 49 is XLIX. The subtractive combination IL is invalid because of rule (ii), while XXXXIX is valid but not minimal. The rules do not place any restriction on the number of occurrences of M, so all positive integers have a valid representation. These are the same rules as were used in Problem 89, and members are invited to solve that problem first.

\n\n

Find the expected value of the number represented by what we have written down when we stop. (If nothing is written down then count that as zero.) Give your answer rounded to 8 places after the decimal point.

", "url": "https://projecteuler.net/problem=610", "answer": "319.30207833"} {"id": 611, "problem": "Peter moves in a hallway with $N + 1$ doors consecutively numbered from $0$ through $N$. All doors are initially closed. Peter starts in front of door $0$, and repeatedly performs the following steps:\n\n- First, he walks a positive square number of doors away from his position.\n\n- Then he walks another, larger square number of doors away from his new position.\n\n- He toggles the door he faces (opens it if closed, closes it if open).\n\n- And finally returns to door $0$.\n\nWe call an action any sequence of those steps. Peter never performs the exact same action twice, and makes sure to perform all possible actions that don't bring him past the last door.\n\nLet $F(N)$ be the number of doors that are open after Peter has performed all possible actions. You are given that $F(5) = 1$, $F(100) = 27$, $F(1000) = 233$ and $F(10^6) = 112168$.\n\nFind $F(10^{12})$.", "raw_html": "

Peter moves in a hallway with $N + 1$ doors consecutively numbered from $0$ through $N$. All doors are initially closed. Peter starts in front of door $0$, and repeatedly performs the following steps:

\n
  • First, he walks a positive square number of doors away from his position.
  • \n
  • Then he walks another, larger square number of doors away from his new position.
  • \n
  • He toggles the door he faces (opens it if closed, closes it if open).
  • \n
  • And finally returns to door $0$.
  • \n

We call an action any sequence of those steps. Peter never performs the exact same action twice, and makes sure to perform all possible actions that don't bring him past the last door.

\n

Let $F(N)$ be the number of doors that are open after Peter has performed all possible actions. You are given that $F(5) = 1$, $F(100) = 27$, $F(1000) = 233$ and $F(10^6) = 112168$.

\n

Find $F(10^{12})$.

", "url": "https://projecteuler.net/problem=611", "answer": "49283233900"} {"id": 612, "problem": "Let's call two numbers friend numbers if their representation in base $10$ has at least one common digit.\nE.g. $1123$ and $3981$ are friend numbers.\n\nLet $f(n)$ be the number of pairs $(p,q)$ with $1\\le p \\lt q \\lt n$ such that $p$ and $q$ are friend numbers.\n\n$f(100)=1539$.\n\nFind $f(10^{18}) \\bmod 1000267129$.", "raw_html": "

\nLet's call two numbers friend numbers if their representation in base $10$ has at least one common digit.
E.g. $1123$ and $3981$ are friend numbers. \n

\n

\nLet $f(n)$ be the number of pairs $(p,q)$ with $1\\le p \\lt q \\lt n$ such that $p$ and $q$ are friend numbers.
\n$f(100)=1539$.\n

\n

\nFind $f(10^{18}) \\bmod 1000267129$.\n

", "url": "https://projecteuler.net/problem=612", "answer": "819963842"} {"id": 613, "problem": "Dave is doing his homework on the balcony and, preparing a presentation about Pythagorean triangles, has just cut out a triangle with side lengths 30cm, 40cm and 50cm from some cardboard, when a gust of wind blows the triangle down into the garden.\n\nAnother gust blows a small ant straight onto this triangle. The poor ant is completely disoriented and starts to crawl straight ahead in random direction in order to get back into the grass.\n\nAssuming that all possible positions of the ant within the triangle and all possible directions of moving on are equiprobable, what is the probability that the ant leaves the triangle along its longest side?\n\nGive your answer rounded to 10 digits after the decimal point.", "raw_html": "

Dave is doing his homework on the balcony and, preparing a presentation about Pythagorean triangles, has just cut out a triangle with side lengths 30cm, 40cm and 50cm from some cardboard, when a gust of wind blows the triangle down into the garden.
\nAnother gust blows a small ant straight onto this triangle. The poor ant is completely disoriented and starts to crawl straight ahead in random direction in order to get back into the grass.

\n\n

Assuming that all possible positions of the ant within the triangle and all possible directions of moving on are equiprobable, what is the probability that the ant leaves the triangle along its longest side?
\nGive your answer rounded to 10 digits after the decimal point.

", "url": "https://projecteuler.net/problem=613", "answer": "0.3916721504"} {"id": 614, "problem": "An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers. Partitions that differ only by the order of their summands are considered the same.\n\nWe call an integer partition special if 1) all its summands are distinct, and 2) all its even summands are also divisible by $4$.\nFor example, the special partitions of $10$ are: $$10 = 1+4+5=3+7=1+9$$\nThe number $10$ admits many more integer partitions (a total of $42$), but only those three are special.\n\nLet be $P(n)$ the number of special integer partitions of $n$. You are given that $P(1) = 1$, $P(2) = 0$, $P(3) = 1$, $P(6) = 1$, $P(10)=3$, $P(100) = 37076$ and $P(1000)=3699177285485660336$.\n\nFind $\\displaystyle \\sum_{i=1}^{10^7} P(i)$. Give the result modulo $10^9+7$.", "raw_html": "

An integer partition of a number $n$ is a way of writing $n$ as a sum of positive integers. Partitions that differ only by the order of their summands are considered the same.

\n\n

We call an integer partition special if 1) all its summands are distinct, and 2) all its even summands are also divisible by $4$.
For example, the special partitions of $10$ are: $$10 = 1+4+5=3+7=1+9$$\nThe number $10$ admits many more integer partitions (a total of $42$), but only those three are special.

\n\n

Let be $P(n)$ the number of special integer partitions of $n$. You are given that $P(1) = 1$, $P(2) = 0$, $P(3) = 1$, $P(6) = 1$, $P(10)=3$, $P(100) = 37076$ and $P(1000)=3699177285485660336$.

\n\n

Find $\\displaystyle \\sum_{i=1}^{10^7} P(i)$. Give the result modulo $10^9+7$.

", "url": "https://projecteuler.net/problem=614", "answer": "130694090"} {"id": 615, "problem": "Consider the natural numbers having at least $5$ prime factors, which don't have to be distinct.\nSorting these numbers by size gives a list which starts with:\n\n- $32=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2$\n\n- $48=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 3$\n\n- $64=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2$\n\n- $72=2 \\cdot 2 \\cdot 2 \\cdot 3 \\cdot 3$\n\n- $80=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 5$\n\n- $96=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 3$\n\n- $\\cdots$\n\nSo, for example, the fifth number with at least $5$ prime factors is $80$.\n\nFind the millionth number with at least one million prime factors.\nGive your answer modulo $123454321$.", "raw_html": "

\nConsider the natural numbers having at least $5$ prime factors, which don't have to be distinct.
Sorting these numbers by size gives a list which starts with:\n

\n
  • $32=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2$
  • \n
  • $48=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 3$
  • \n
  • $64=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2$
  • \n
  • $72=2 \\cdot 2 \\cdot 2 \\cdot 3 \\cdot 3$
  • \n
  • $80=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 5$
  • \n
  • $96=2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 2 \\cdot 3$
  • \n
  • $\\cdots$
\n

\nSo, for example, the fifth number with at least $5$ prime factors is $80$.\n

\n

\nFind the millionth number with at least one million prime factors.
Give your answer modulo $123454321$.\n

", "url": "https://projecteuler.net/problem=615", "answer": "108424772"} {"id": 616, "problem": "Alice plays the following game, she starts with a list of integers $L$ and on each step she can either:\n\n- remove two elements $a$ and $b$ from $L$ and add $a^b$ to $L$\n\n- or conversely remove an element $c$ from $L$ that can be written as $a^b$, with $a$ and $b$ being two integers such that $a, b > 1$, and add both $a$ and $b$ to $L$\n\n\nFor example starting from the list $L=\\{8\\}$, Alice can remove $8$ and add $2$ and $3$ resulting in $L=\\{2,3\\}$ in a first step. Then she can obtain $L=\\{9\\}$ in a second step.\n\nNote that the same integer is allowed to appear multiple times in the list.\n\nAn integer $n>1$ is said to be creative if for any integer $m \\gt 1$ Alice can obtain a list that contains $m$ starting from $L=\\{n\\}$.\n\nFind the sum of all creative integers less than or equal to $10^{12}$.", "raw_html": "

Alice plays the following game, she starts with a list of integers $L$ and on each step she can either:\n

  • remove two elements $a$ and $b$ from $L$ and add $a^b$ to $L$
  • \n
  • or conversely remove an element $c$ from $L$ that can be written as $a^b$, with $a$ and $b$ being two integers such that $a, b > 1$, and add both $a$ and $b$ to $L$
\n

For example starting from the list $L=\\{8\\}$, Alice can remove $8$ and add $2$ and $3$ resulting in $L=\\{2,3\\}$ in a first step. Then she can obtain $L=\\{9\\}$ in a second step.

\n\n

Note that the same integer is allowed to appear multiple times in the list.

\n\n

An integer $n>1$ is said to be creative if for any integer $m \\gt 1$ Alice can obtain a list that contains $m$ starting from $L=\\{n\\}$.\n\n

Find the sum of all creative integers less than or equal to $10^{12}$.

", "url": "https://projecteuler.net/problem=616", "answer": "310884668312456458"} {"id": 617, "problem": "For two integers $n,e \\gt 1$, we define an $(n,e)$-MPS (Mirror Power Sequence) to be an infinite sequence of integers $(a_i)_{i\\ge 0}$ such that for all $i\\ge 0$, $a_{i+1} = \\min(a_i^e,n-a_i^e)$ and $a_i \\gt 1$.\nExamples of such sequences are the two $(18,2)$-MPS sequences made of alternating $2$ and $4$.\n\nNote that even though such a sequence is uniquely determined by $n,e$ and $a_0$, for most values such a sequence does not exist. For example, no $(n,e)$-MPS exists for $n \\lt 6$.\n\nDefine $C(n)$ to be the number of $(n,e)$-MPS for some $e$, and $\\displaystyle D(N) = \\sum_{n=2}^N C(n)$.\n\nYou are given that $D(10) = 2$, $D(100) = 21$, $D(1000) = 69$, $D(10^6) = 1303$ and $D(10^{12}) = 1014800$.\n\n\nFind $D(10^{18})$.", "raw_html": "

For two integers $n,e \\gt 1$, we define an $(n,e)$-MPS (Mirror Power Sequence) to be an infinite sequence of integers $(a_i)_{i\\ge 0}$ such that for all $i\\ge 0$, $a_{i+1} = \\min(a_i^e,n-a_i^e)$ and $a_i \\gt 1$.
Examples of such sequences are the two $(18,2)$-MPS sequences made of alternating $2$ and $4$.

\n\n

Note that even though such a sequence is uniquely determined by $n,e$ and $a_0$, for most values such a sequence does not exist. For example, no $(n,e)$-MPS exists for $n \\lt 6$.

\n\n

Define $C(n)$ to be the number of $(n,e)$-MPS for some $e$, and $\\displaystyle D(N) = \\sum_{n=2}^N C(n)$.\n
You are given that $D(10) = 2$, $D(100) = 21$, $D(1000) = 69$, $D(10^6) = 1303$ and $D(10^{12}) = 1014800$.

\n \n

Find $D(10^{18})$.

", "url": "https://projecteuler.net/problem=617", "answer": "1001133757"} {"id": 618, "problem": "Consider the numbers $15$, $16$ and $18$:\n\n$15=3\\times 5$ and $3+5=8$.\n\n$16 = 2\\times 2\\times 2\\times 2$ and $2+2+2+2=8$.\n\n$18 = 2\\times 3\\times 3$ and $2+3+3=8$.\n\n\n$15$, $16$ and $18$ are the only numbers that have $8$ as sum of the prime factors (counted with multiplicity).\n\nWe define $S(k)$ to be the sum of all numbers $n$ where the sum of the prime factors (with multiplicity) of $n$ is $k$.\n\nHence $S(8) = 15+16+18 = 49$.\n\nOther examples: $S(1) = 0$, $S(2) = 2$, $S(3) = 3$, $S(5) = 5 + 6 = 11$.\n\nThe Fibonacci sequence is $F_1 = 1$, $F_2 = 1$, $F_3 = 2$, $F_4 = 3$, $F_5 = 5$, ....\n\nFind the last nine digits of $\\displaystyle\\sum_{k=2}^{24}S(F_k)$.", "raw_html": "

Consider the numbers $15$, $16$ and $18$:
\n$15=3\\times 5$ and $3+5=8$.
\n$16 = 2\\times 2\\times 2\\times 2$ and $2+2+2+2=8$.
\n$18 = 2\\times 3\\times 3$ and $2+3+3=8$.
\n\n$15$, $16$ and $18$ are the only numbers that have $8$ as sum of the prime factors (counted with multiplicity).

\n

\nWe define $S(k)$ to be the sum of all numbers $n$ where the sum of the prime factors (with multiplicity) of $n$ is $k$.
\nHence $S(8) = 15+16+18 = 49$.
\nOther examples: $S(1) = 0$, $S(2) = 2$, $S(3) = 3$, $S(5) = 5 + 6 = 11$.

\n

\nThe Fibonacci sequence is $F_1 = 1$, $F_2 = 1$, $F_3 = 2$, $F_4 = 3$, $F_5 = 5$, ....
\nFind the last nine digits of $\\displaystyle\\sum_{k=2}^{24}S(F_k)$.

", "url": "https://projecteuler.net/problem=618", "answer": "634212216"} {"id": 619, "problem": "For a set of positive integers $\\{a, a+1, a+2, \\dots , b\\}$, let $C(a,b)$ be the number of non-empty subsets in which the product of all elements is a perfect square.\n\nFor example $C(5,10)=3$, since the products of all elements of $\\{5, 8, 10\\}$, $\\{5, 8, 9, 10\\}$ and $\\{9\\}$ are perfect squares, and no other subsets of $\\{5, 6, 7, 8, 9, 10\\}$ have this property.\n\nYou are given that $C(40,55) =15$, and $C(1000,1234) \\bmod 1000000007=975523611$.\n\nFind $C(1000000,1234567) \\bmod 1000000007$.", "raw_html": "

For a set of positive integers $\\{a, a+1, a+2, \\dots , b\\}$, let $C(a,b)$ be the number of non-empty subsets in which the product of all elements is a perfect square.

\n

For example $C(5,10)=3$, since the products of all elements of $\\{5, 8, 10\\}$, $\\{5, 8, 9, 10\\}$ and $\\{9\\}$ are perfect squares, and no other subsets of $\\{5, 6, 7, 8, 9, 10\\}$ have this property.

\n

You are given that $C(40,55) =15$, and $C(1000,1234) \\bmod 1000000007=975523611$.

\n\n

Find $C(1000000,1234567) \\bmod 1000000007$.

", "url": "https://projecteuler.net/problem=619", "answer": "857810883"} {"id": 620, "problem": "A circle $C$ of circumference $c$ centimetres has a smaller circle $S$ of circumference $s$ centimetres lying off-centre within it. Four other distinct circles, which we call \"planets\", with circumferences $p$, $p$, $q$, $q$ centimetres respectively ($pA circle $C$ of circumference $c$ centimetres has a smaller circle $S$ of circumference $s$ centimetres lying off-centre within it. Four other distinct circles, which we call \"planets\", with circumferences $p$, $p$, $q$, $q$ centimetres respectively ($p<q$), are inscribed within $C$ but outside $S$, with each planet touching both $C$ and $S$ tangentially. The planets are permitted to overlap one another, but the boundaries of $S$ and $C$ must be at least 1cm apart at their closest point.

\n\n

Now suppose that these circles are actually gears with perfectly meshing teeth at a pitch of 1cm. $C$ is an internal gear with teeth on the inside. We require that $c$, $s$, $p$, $q$ are all integers (as they are the numbers of teeth), and we further stipulate that any gear must have at least 5 teeth.

\n\n

Note that \"perfectly meshing\" means that as the gears rotate, the ratio between their angular velocities remains constant, and the teeth of one gear perfectly align with the groves of the other gear and vice versa. Only for certain gear sizes and positions will it be possible for $S$ and $C$ each to mesh perfectly with all the planets. Arrangements where not all gears mesh perfectly are not valid.

\n\n

Define $g(c,s,p,q)$ to be the number of such gear arrangements for given values of $c$, $s$, $p$, $q$: it turns out that this is finite as only certain discrete arrangements are possible satisfying the above conditions. For example, $g(16,5,5,6)=9$.

\n\n

Here is one such arrangement:

\n
\"Example
\n\n

Let $G(n) = \\sum_{s+p+q\\le n} g(s+p+q,s,p,q)$ where the sum only includes cases with $p<q$, $p\\ge 5$, and $s\\ge 5$, all integers. You are given that $G(16)=9$ and $G(20)=205$.

\n\n

Find $G(500)$.

", "url": "https://projecteuler.net/problem=620", "answer": "1470337306"} {"id": 621, "problem": "Gauss famously proved that every positive integer can be expressed as the sum of three triangular numbers (including $0$ as the lowest triangular number). In fact most numbers can be expressed as a sum of three triangular numbers in several ways.\n\nLet $G(n)$ be the number of ways of expressing $n$ as the sum of three triangular numbers, regarding different arrangements of the terms of the sum as distinct.\n\nFor example, $G(9) = 7$, as $9$ can be expressed as: $3+3+3$, $0+3+6$, $0+6+3$, $3+0+6$, $3+6+0$, $6+0+3$, $6+3+0$.\n\nYou are given $G(1000) = 78$ and $G(10^6) = 2106$.\n\nFind $G(17526 \\times 10^9)$.", "raw_html": "

Gauss famously proved that every positive integer can be expressed as the sum of three triangular numbers (including $0$ as the lowest triangular number). In fact most numbers can be expressed as a sum of three triangular numbers in several ways.

\n

\nLet $G(n)$ be the number of ways of expressing $n$ as the sum of three triangular numbers, regarding different arrangements of the terms of the sum as distinct.

\n

\nFor example, $G(9) = 7$, as $9$ can be expressed as: $3+3+3$, $0+3+6$, $0+6+3$, $3+0+6$, $3+6+0$, $6+0+3$, $6+3+0$.
\nYou are given $G(1000) = 78$ and $G(10^6) = 2106$.

\n

\nFind $G(17526 \\times 10^9)$.

", "url": "https://projecteuler.net/problem=621", "answer": "11429712"} {"id": 622, "problem": "A riffle shuffle is executed as follows: a deck of cards is split into two equal halves, with the top half taken in the left hand and the bottom half taken in the right hand. Next, the cards are interleaved exactly, with the top card in the right half inserted just after the top card in the left half, the 2nd card in the right half just after the 2nd card in the left half, etc. (Note that this process preserves the location of the top and bottom card of the deck)\n\nLet $s(n)$ be the minimum number of consecutive riffle shuffles needed to restore a deck of size $n$ to its original configuration, where $n$ is a positive even number.\n\nAmazingly, a standard deck of $52$ cards will first return to its original configuration after only $8$ perfect shuffles, so $s(52) = 8$. It can be verified that a deck of $86$ cards will also return to its original configuration after exactly $8$ shuffles, and the sum of all values of $n$ that satisfy $s(n) = 8$ is $412$.\n\nFind the sum of all values of n that satisfy $s(n) = 60$.", "raw_html": "

\nA riffle shuffle is executed as follows: a deck of cards is split into two equal halves, with the top half taken in the left hand and the bottom half taken in the right hand. Next, the cards are interleaved exactly, with the top card in the right half inserted just after the top card in the left half, the 2nd card in the right half just after the 2nd card in the left half, etc. (Note that this process preserves the location of the top and bottom card of the deck)\n

\n

\nLet $s(n)$ be the minimum number of consecutive riffle shuffles needed to restore a deck of size $n$ to its original configuration, where $n$ is a positive even number.

\n

\nAmazingly, a standard deck of $52$ cards will first return to its original configuration after only $8$ perfect shuffles, so $s(52) = 8$. It can be verified that a deck of $86$ cards will also return to its original configuration after exactly $8$ shuffles, and the sum of all values of $n$ that satisfy $s(n) = 8$ is $412$.\n

\n

\nFind the sum of all values of n that satisfy $s(n) = 60$.\n

", "url": "https://projecteuler.net/problem=622", "answer": "3010983666182123972"} {"id": 623, "problem": "The lambda-calculus is a universal model of computation at the core of functional programming languages. It is based on lambda-terms, a minimal programming language featuring only function definitions, function calls and variables. Lambda-terms are built according to the following rules:\n\n- Any variable $x$ (single letter, from some infinite alphabet) is a lambda-term.\n\n- If $M$ and $N$ are lambda-terms, then $(M N)$ is a lambda-term, called the application of $M$ to $N$.\n\n- If $x$ is a variable and $M$ is a term, then $(\\lambda x. M)$ is a lambda-term, called an abstraction. An abstraction defines an anonymous function, taking $x$ as parameter and sending back $M$.\n\nA lambda-term $T$ is said to be closed if for all variables $x$, all occurrences of $x$ within $T$ are contained within some abstraction $(\\lambda x. M)$ in $T$. The smallest such abstraction is said to bind the occurrence of the variable $x$. In other words, a lambda-term is closed if all its variables are bound to parameters of enclosing functions definitions. For example, the term $(\\lambda x. x)$ is closed, while the term $(\\lambda x. (x y))$ is not because $y$ is not bound.\n\nAlso, we can rename variables as long as no binding abstraction changes. This means that $(\\lambda x. x)$ and $(\\lambda y. y)$ should be considered equivalent since we merely renamed a parameter. Two terms equivalent modulo such renaming are called $\\alpha$-equivalent. Note that $(\\lambda x. (\\lambda y. (x y)))$ and $(\\lambda x. (\\lambda x. (x x)))$ are not $\\alpha$-equivalent, since the abstraction binding the first variable was the outer one and becomes the inner one. However, $(\\lambda x. (\\lambda y. (x y)))$ and $(\\lambda y. (\\lambda x. (y x)))$ are $\\alpha$-equivalent.\n\nThe following table regroups the lambda-terms that can be written with at most $15$ symbols, symbols being parenthesis, $\\lambda$, dot and variables.\n\n$$\\begin{array}{|c|c|c|c|}\n\\hline\n(\\lambda x.x) & (\\lambda x.(x x)) & (\\lambda x.(\\lambda y.x)) & (\\lambda x.(\\lambda y.y)) \\\\\n\\hline\n(\\lambda x.(x (x x))) & (\\lambda x.((x x) x)) & (\\lambda x.(\\lambda y.(x x))) & (\\lambda x.(\\lambda y.(x y))) \\\\\n\\hline\n(\\lambda x.(\\lambda y.(y x))) & (\\lambda x.(\\lambda y.(y y))) & (\\lambda x.(x (\\lambda y.x))) & (\\lambda x.(x (\\lambda y.y))) \\\\\n\\hline\n(\\lambda x.((\\lambda y.x) x)) & (\\lambda x.((\\lambda y.y) x)) & ((\\lambda x.x) (\\lambda x.x)) & (\\lambda x.(x (x (x x)))) \\\\\n\\hline\n(\\lambda x.(x ((x x) x))) & (\\lambda x.((x x) (x x))) & (\\lambda x.((x (x x)) x)) & (\\lambda x.(((x x) x) x)) \\\\\n\\hline\n\\end{array}$$\n\nLet be $\\Lambda(n)$ the number of distinct closed lambda-terms that can be written using at most $n$ symbols, where terms that are $\\alpha$-equivalent to one another should be counted only once. You are given that $\\Lambda(6) = 1$, $\\Lambda(9) = 2$, $\\Lambda(15) = 20$ and $\\Lambda(35) = 3166438$.\n\nFind $\\Lambda(2000)$. Give the answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

The lambda-calculus is a universal model of computation at the core of functional programming languages. It is based on lambda-terms, a minimal programming language featuring only function definitions, function calls and variables. Lambda-terms are built according to the following rules:

\n
    \n
  • Any variable $x$ (single letter, from some infinite alphabet) is a lambda-term.
  • \n
  • If $M$ and $N$ are lambda-terms, then $(M N)$ is a lambda-term, called the application of $M$ to $N$.
  • \n
  • If $x$ is a variable and $M$ is a term, then $(\\lambda x. M)$ is a lambda-term, called an abstraction. An abstraction defines an anonymous function, taking $x$ as parameter and sending back $M$.
  • \n
\n\n

A lambda-term $T$ is said to be closed if for all variables $x$, all occurrences of $x$ within $T$ are contained within some abstraction $(\\lambda x. M)$ in $T$. The smallest such abstraction is said to bind the occurrence of the variable $x$. In other words, a lambda-term is closed if all its variables are bound to parameters of enclosing functions definitions. For example, the term $(\\lambda x. x)$ is closed, while the term $(\\lambda x. (x y))$ is not because $y$ is not bound.

\n\n

Also, we can rename variables as long as no binding abstraction changes. This means that $(\\lambda x. x)$ and $(\\lambda y. y)$ should be considered equivalent since we merely renamed a parameter. Two terms equivalent modulo such renaming are called $\\alpha$-equivalent. Note that $(\\lambda x. (\\lambda y. (x y)))$ and $(\\lambda x. (\\lambda x. (x x)))$ are not $\\alpha$-equivalent, since the abstraction binding the first variable was the outer one and becomes the inner one. However, $(\\lambda x. (\\lambda y. (x y)))$ and $(\\lambda y. (\\lambda x. (y x)))$ are $\\alpha$-equivalent.

\n\n

The following table regroups the lambda-terms that can be written with at most $15$ symbols, symbols being parenthesis, $\\lambda$, dot and variables.

\n\n$$\\begin{array}{|c|c|c|c|}\n\\hline\n(\\lambda x.x) & (\\lambda x.(x x)) & (\\lambda x.(\\lambda y.x)) & (\\lambda x.(\\lambda y.y)) \\\\\n\\hline\n(\\lambda x.(x (x x))) & (\\lambda x.((x x) x)) & (\\lambda x.(\\lambda y.(x x))) & (\\lambda x.(\\lambda y.(x y))) \\\\\n\\hline\n(\\lambda x.(\\lambda y.(y x))) & (\\lambda x.(\\lambda y.(y y))) & (\\lambda x.(x (\\lambda y.x))) & (\\lambda x.(x (\\lambda y.y))) \\\\\n\\hline\n(\\lambda x.((\\lambda y.x) x)) & (\\lambda x.((\\lambda y.y) x)) & ((\\lambda x.x) (\\lambda x.x)) & (\\lambda x.(x (x (x x)))) \\\\\n\\hline\n(\\lambda x.(x ((x x) x))) & (\\lambda x.((x x) (x x))) & (\\lambda x.((x (x x)) x)) & (\\lambda x.(((x x) x) x)) \\\\\n\\hline\n\\end{array}$$\n\n

Let be $\\Lambda(n)$ the number of distinct closed lambda-terms that can be written using at most $n$ symbols, where terms that are $\\alpha$-equivalent to one another should be counted only once. You are given that $\\Lambda(6) = 1$, $\\Lambda(9) = 2$, $\\Lambda(15) = 20$ and $\\Lambda(35) = 3166438$.

\n

Find $\\Lambda(2000)$. Give the answer modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=623", "answer": "3679796"} {"id": 624, "problem": "An unbiased coin is tossed repeatedly until two consecutive heads are obtained. Suppose these occur on the $(M-1)$th and $M$th toss.\n\nLet $P(n)$ be the probability that $M$ is divisible by $n$. For example, the outcomes HH, HTHH, and THTTHH all count towards $P(2)$, but THH and HTTHH do not.\n\nYou are given that $P(2) =\\frac 3 5$ and $P(3)=\\frac 9 {31}$. Indeed, it can be shown that $P(n)$ is always a rational number.\n\nFor a prime $p$ and a fully reduced fraction $\\frac a b$, define $Q(\\frac a b,p)$ to be the smallest positive $q$ for which $a \\equiv b q \\pmod{p}$.\n\nFor example $Q(P(2), 109) = Q(\\frac 3 5, 109) = 66$, because $5 \\cdot 66 = 330 \\equiv 3 \\pmod{109}$ and $66$ is the smallest positive such number.\n\nSimilarly $Q(P(3),109) = 46$.\n\nFind $Q(P(10^{18}),1\\,000\\,000\\,009)$.", "raw_html": "

\nAn unbiased coin is tossed repeatedly until two consecutive heads are obtained. Suppose these occur on the $(M-1)$th and $M$th toss.
\nLet $P(n)$ be the probability that $M$ is divisible by $n$. For example, the outcomes HH, HTHH, and THTTHH all count towards $P(2)$, but THH and HTTHH do not.

\n

\nYou are given that $P(2) =\\frac 3 5$ and $P(3)=\\frac 9 {31}$. Indeed, it can be shown that $P(n)$ is always a rational number.

\n

\nFor a prime $p$ and a fully reduced fraction $\\frac a b$, define $Q(\\frac a b,p)$ to be the smallest positive $q$ for which $a \\equiv b q \\pmod{p}$.
\nFor example $Q(P(2), 109) = Q(\\frac 3 5, 109) = 66$, because $5 \\cdot 66 = 330 \\equiv 3 \\pmod{109}$ and $66$ is the smallest positive such number.
\nSimilarly $Q(P(3),109) = 46$.

\n

\nFind $Q(P(10^{18}),1\\,000\\,000\\,009)$.

", "url": "https://projecteuler.net/problem=624", "answer": "984524441"} {"id": 625, "problem": "$G(N)=\\sum_{j=1}^N\\sum_{i=1}^j \\gcd(i,j)$.\n\nYou are given: $G(10)=122$.\n\nFind $G(10^{11})$. Give your answer modulo $998244353$.", "raw_html": "

\n$G(N)=\\sum_{j=1}^N\\sum_{i=1}^j \\gcd(i,j)$.
\nYou are given: $G(10)=122$.

\n

\nFind $G(10^{11})$. Give your answer modulo $998244353$.\n

", "url": "https://projecteuler.net/problem=625", "answer": "551614306"} {"id": 626, "problem": "A binary matrix is a matrix consisting entirely of $0$s and $1$s. Consider the following transformations that can be performed on a binary matrix:\n\n- Swap any two rows\n\n- Swap any two columns\n\n- Flip all elements in a single row ($1$s become $0$s, $0$s become $1$s)\n\n- Flip all elements in a single column\n\nTwo binary matrices $A$ and $B$ will be considered equivalent if there is a sequence of such transformations that when applied to $A$ yields $B$. For example, the following two matrices are equivalent:\n\n$A=\\begin{pmatrix}\n1 & 0 & 1 \\\\\n0 & 0 & 1 \\\\\n0 & 0 & 0 \\\\\n\\end{pmatrix} \\quad B=\\begin{pmatrix}\n0 & 0 & 0 \\\\\n1 & 0 & 0 \\\\\n0 & 0 & 1 \\\\\n\\end{pmatrix}$\nvia the sequence of two transformations \"Flip all elements in column 3\" followed by \"Swap rows 1 and 2\".\n\nDefine $c(n)$ to be the maximum number of $n\\times n$ binary matrices that can be found such that no two are equivalent. For example, $c(3)=3$. You are also given that $c(5)=39$ and $c(8)=656108$.\n\nFind $c(20)$, and give your answer modulo $1\\,001\\,001\\,011$.", "raw_html": "

A binary matrix is a matrix consisting entirely of $0$s and $1$s. Consider the following transformations that can be performed on a binary matrix:

\n\n
    \n
  • Swap any two rows
  • \n
  • Swap any two columns
  • \n
  • Flip all elements in a single row ($1$s become $0$s, $0$s become $1$s)
  • \n
  • Flip all elements in a single column
  • \n
\n\n

Two binary matrices $A$ and $B$ will be considered equivalent if there is a sequence of such transformations that when applied to $A$ yields $B$. For example, the following two matrices are equivalent:

\n$A=\\begin{pmatrix} \n 1 & 0 & 1 \\\\ \n 0 & 0 & 1 \\\\\n 0 & 0 & 0 \\\\\n\\end{pmatrix} \\quad B=\\begin{pmatrix} \n 0 & 0 & 0 \\\\ \n 1 & 0 & 0 \\\\\n 0 & 0 & 1 \\\\\n\\end{pmatrix}$\n

via the sequence of two transformations \"Flip all elements in column 3\" followed by \"Swap rows 1 and 2\".

\n\n

Define $c(n)$ to be the maximum number of $n\\times n$ binary matrices that can be found such that no two are equivalent. For example, $c(3)=3$. You are also given that $c(5)=39$ and $c(8)=656108$.

\n\n

Find $c(20)$, and give your answer modulo $1\\,001\\,001\\,011$.

", "url": "https://projecteuler.net/problem=626", "answer": "695577663"} {"id": 627, "problem": "Consider the set $S$ of all possible products of $n$ positive integers not exceeding $m$, that is\n\n$S=\\{ x_1x_2\\cdots x_n \\mid 1 \\le x_1, x_2, \\dots, x_n \\le m \\}$.\n\nLet $F(m,n)$ be the number of the distinct elements of the set $S$.\n\nFor example, $F(9, 2) = 36$ and $F(30,2)=308$.\n\nFind $F(30, 10001) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Consider the set $S$ of all possible products of $n$ positive integers not exceeding $m$, that is
\n$S=\\{ x_1x_2\\cdots x_n \\mid 1 \\le x_1, x_2, \\dots, x_n \\le m \\}$.
\n\nLet $F(m,n)$ be the number of the distinct elements of the set $S$.
\nFor example, $F(9, 2) = 36$ and $F(30,2)=308$.

\n\n

Find $F(30, 10001) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=627", "answer": "220196142"} {"id": 628, "problem": "A position in chess is an (orientated) arrangement of chess pieces placed on a chessboard of given size. In the following, we consider all positions in which $n$ pawns are placed on a $n \\times n$\nboard in such a way, that there is a single pawn in every row and every column.\n\nWe call such a position an open position, if a rook, starting at the (empty) lower left corner and using only moves towards the right or upwards, can reach the upper right corner without moving onto any field occupied by a pawn.\n\nLet $f(n)$ be the number of open positions for a $n \\times n$ chessboard.\n\nFor example, $f(3)=2$, illustrated by the two open positions for a $3 \\times 3$ chessboard below.\n\n| | | |\n\nYou are also given $f(5)=70$.\n\nFind $f(10^8)$ modulo $1\\,008\\,691\\,207$.", "raw_html": "

\nA position in chess is an (orientated) arrangement of chess pieces placed on a chessboard of given size. In the following, we consider all positions in which $n$ pawns are placed on a $n \\times n$ \nboard in such a way, that there is a single pawn in every row and every column.\n\n

\n

\nWe call such a position an open position, if a rook, starting at the (empty) lower left corner and using only moves towards the right or upwards, can reach the upper right corner without moving onto any field occupied by a pawn. \n

\n

Let $f(n)$ be the number of open positions for a $n \\times n$ chessboard.
\nFor example, $f(3)=2$, illustrated by the two open positions for a $3 \\times 3$ chessboard below.\n\n

\n\n\n\n
\"Open\"Open
\n

\nYou are also given $f(5)=70$.

\n

Find $f(10^8)$ modulo $1\\,008\\,691\\,207$.

", "url": "https://projecteuler.net/problem=628", "answer": "210286684"} {"id": 629, "problem": "Alice and Bob are playing a modified game of Nim called Scatterstone Nim, with Alice going first, alternating turns with Bob. The game begins with an arbitrary set of stone piles with a total number of stones equal to $n$.\n\nDuring a player's turn, he/she must pick a pile having at least $2$ stones and perform a split operation, dividing the pile into an arbitrary set of $p$ non-empty, arbitrarily-sized piles where $2 \\leq p \\leq k$ for some fixed constant $k$. For example, a pile of size $4$ can be split into $\\{1, 3\\}$ or $\\{2, 2\\}$, or $\\{1, 1, 2\\}$ if $k = 3$ and in addition $\\{1, 1, 1, 1\\}$ if $k = 4$.\n\nIf no valid move is possible on a given turn, then the other player wins the game.\n\nA winning position is defined as a set of stone piles where a player can ultimately ensure victory no matter what the other player does.\n\nLet $f(n,k)$ be the number of winning positions for Alice on her first turn, given parameters $n$ and $k$. For example, $f(5, 2) = 3$ with winning positions $\\{1, 1, 1, 2\\}, \\{1, 4\\}, \\{2, 3\\}$. In contrast, $f(5, 3) = 5$ with winning positions $\\{1, 1, 1, 2\\}, \\{1, 1, 3\\}, \\{1, 4\\}, \\{2, 3\\}, \\{5\\}$.\n\nLet $g(n)$ be the sum of $f(n,k)$ over all $2 \\leq k \\leq n$. For example, $g(7)=66$ and $g(10)=291$.\n\nFind $g(200) \\bmod (10^9 + 7)$.", "raw_html": "

Alice and Bob are playing a modified game of Nim called Scatterstone Nim, with Alice going first, alternating turns with Bob. The game begins with an arbitrary set of stone piles with a total number of stones equal to $n$.

\n\n

During a player's turn, he/she must pick a pile having at least $2$ stones and perform a split operation, dividing the pile into an arbitrary set of $p$ non-empty, arbitrarily-sized piles where $2 \\leq p \\leq k$ for some fixed constant $k$. For example, a pile of size $4$ can be split into $\\{1, 3\\}$ or $\\{2, 2\\}$, or $\\{1, 1, 2\\}$ if $k = 3$ and in addition $\\{1, 1, 1, 1\\}$ if $k = 4$.

\n\n

If no valid move is possible on a given turn, then the other player wins the game.

\n\n

A winning position is defined as a set of stone piles where a player can ultimately ensure victory no matter what the other player does.

\n\n

Let $f(n,k)$ be the number of winning positions for Alice on her first turn, given parameters $n$ and $k$. For example, $f(5, 2) = 3$ with winning positions $\\{1, 1, 1, 2\\}, \\{1, 4\\}, \\{2, 3\\}$. In contrast, $f(5, 3) = 5$ with winning positions $\\{1, 1, 1, 2\\}, \\{1, 1, 3\\}, \\{1, 4\\}, \\{2, 3\\}, \\{5\\}$.

\n\n

Let $g(n)$ be the sum of $f(n,k)$ over all $2 \\leq k \\leq n$. For example, $g(7)=66$ and $g(10)=291$.

\n\n

Find $g(200) \\bmod (10^9 + 7)$.

", "url": "https://projecteuler.net/problem=629", "answer": "626616617"} {"id": 630, "problem": "Given a set, $L$, of unique lines, let $M(L)$ be the number of lines in the set and let $S(L)$ be the sum over every line of the number of times that line is crossed by another line in the set. For example, two sets of three lines are shown below:\n\nIn both cases $M(L)$ is $3$ and $S(L)$ is $6$: each of the three lines is crossed by two other lines. Note that even if the lines cross at a single point, all of the separate crossings of lines are counted.\n\nConsider points $(T_{2k-1}, T_{2k})$, for integer $k \\ge 1$, generated in the following way:\n\n$S_0 \t= \t290797$\n\n$S_{n+1} \t= \tS_n^2 \\bmod 50515093$\n\n$T_n \t= \t(S_n \\bmod 2000) - 1000$\n\nFor example, the first three points are: $(527, 144)$, $(-488, 732)$, $(-454, -947)$. Given the first $n$ points generated in this manner, let $L_n$ be the set of unique lines that can be formed by joining each point with every other point, the lines being extended indefinitely in both directions. We can then define $M(L_n)$ and $S(L_n)$ as described above.\n\nFor example, $M(L_3) = 3$ and $S(L_3) = 6$. Also $M(L_{100}) = 4948$ and $S(L_{100}) = 24477690$.\n\nFind $S(L_{2500})$.", "raw_html": "

\nGiven a set, $L$, of unique lines, let $M(L)$ be the number of lines in the set and let $S(L)$ be the sum over every line of the number of times that line is crossed by another line in the set. For example, two sets of three lines are shown below:\n

\n
\"crossed
\n

\nIn both cases $M(L)$ is $3$ and $S(L)$ is $6$: each of the three lines is crossed by two other lines. Note that even if the lines cross at a single point, all of the separate crossings of lines are counted.\n

\n

\nConsider points $(T_{2k-1}, T_{2k})$, for integer $k \\ge 1$, generated in the following way:\n

\n

\n$S_0 \t= \t290797$
\n$S_{n+1} \t= \tS_n^2 \\bmod 50515093$
\n$T_n \t= \t(S_n \\bmod 2000) - 1000$\n

\n

\nFor example, the first three points are: $(527, 144)$, $(-488, 732)$, $(-454, -947)$. Given the first $n$ points generated in this manner, let $L_n$ be the set of unique lines that can be formed by joining each point with every other point, the lines being extended indefinitely in both directions. We can then define $M(L_n)$ and $S(L_n)$ as described above.\n

\n

\nFor example, $M(L_3) = 3$ and $S(L_3) = 6$. Also $M(L_{100}) = 4948$ and $S(L_{100}) = 24477690$.\n

\nFind $S(L_{2500})$.\n

", "url": "https://projecteuler.net/problem=630", "answer": "9669182880384"} {"id": 631, "problem": "Let $(p_1 p_2 \\ldots p_k)$ denote the permutation of the set ${1, ..., k}$ that maps $p_i\\mapsto i$. Define the length of the permutation to be $k$; note that the empty permutation $()$ has length zero.\n\nDefine an occurrence of a permutation $p=(p_1 p_2 \\cdots p_k)$ in a permutation $P=(P_1 P_2 \\cdots P_n)$ to be a sequence $1\\leq t_1 \\lt t_2 \\lt \\cdots \\lt t_k \\leq n$ such that $p_i \\lt p_j$ if and only if $P_{t_i} \\lt P_{t_j}$ for all $i,j \\in \\{1, \\dots, k\\}$.\n\nFor example, $(1243)$ occurs twice in the permutation $(314625)$: once as the 1st, 3rd, 4th and 6th elements $(3\\,\\,46\\,\\,5)$, and once as the 2nd, 3rd, 4th and 6th elements $(\\,\\,146\\,\\,5)$.\n\nLet $f(n, m)$ be the number of permutations $P$ of length at most $n$ such that there is no occurrence of the permutation $1243$ in $P$ and there are at most $m$ occurrences of the permutation $21$ in $P$.\n\nFor example, $f(2,0) = 3$, with the permutations $()$, $(1)$, $(1,2)$ but not $(2,1)$.\n\nYou are also given that $f(4, 5) = 32$ and $f(10, 25) = 294\\,400$.\n\nFind $f(10^{18}, 40)$ modulo $1\\,000\\,000\\,007$.", "raw_html": "

Let $(p_1 p_2 \\ldots p_k)$ denote the permutation of the set ${1, ..., k}$ that maps $p_i\\mapsto i$. Define the length of the permutation to be $k$; note that the empty permutation $()$ has length zero.

\n\n

Define an occurrence of a permutation $p=(p_1 p_2 \\cdots p_k)$ in a permutation $P=(P_1 P_2 \\cdots P_n)$ to be a sequence $1\\leq t_1 \\lt t_2 \\lt \\cdots \\lt t_k \\leq n$ such that $p_i \\lt p_j$ if and only if $P_{t_i} \\lt P_{t_j}$ for all $i,j \\in \\{1, \\dots, k\\}$.

\n\n

For example, $(1243)$ occurs twice in the permutation $(314625)$: once as the 1st, 3rd, 4th and 6th elements $(3\\,\\,46\\,\\,5)$, and once as the 2nd, 3rd, 4th and 6th elements $(\\,\\,146\\,\\,5)$.

\n\n

Let $f(n, m)$ be the number of permutations $P$ of length at most $n$ such that there is no occurrence of the permutation $1243$ in $P$ and there are at most $m$ occurrences of the permutation $21$ in $P$.

\n\n

For example, $f(2,0) = 3$, with the permutations $()$, $(1)$, $(1,2)$ but not $(2,1)$.

\n\n

You are also given that $f(4, 5) = 32$ and $f(10, 25) = 294\\,400$.

\n\n

Find $f(10^{18}, 40)$ modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=631", "answer": "869588692"} {"id": 632, "problem": "For an integer $n$, we define the square prime factors of $n$ to be the primes whose square divides $n$. For example, the square prime factors of $1500=2^2 \\times 3 \\times 5^3$ are $2$ and $5$.\n\nLet $C_k(N)$ be the number of integers between $1$ and $N$ inclusive with exactly $k$ square prime factors. You are given some values of $C_k(N)$ in the table below.\n\n$$\\begin{array}{|c|c|c|c|c|c|c|}\n\\hline\n\n& k = 0 & k = 1 & k = 2 & k = 3 & k = 4 & k = 5 \\\\\n\\hline\nN=10 & 7 & 3 & 0 & 0 & 0 & 0 \\\\\n\\hline\nN=10^2 & 61 & 36 & 3 & 0 & 0 & 0 \\\\\n\\hline\nN=10^3 & 608 & 343 & 48 & 1 & 0 & 0 \\\\\n\\hline\nN=10^4 & 6083 & 3363 & 533 & 21 & 0 & 0 \\\\\n\\hline\nN=10^5 & 60794 & 33562 & 5345 & 297 & 2 & 0 \\\\\n\\hline\nN=10^6 & 607926 & 335438 & 53358 & 3218 & 60 & 0 \\\\\n\\hline\nN=10^7 & 6079291 & 3353956 & 533140 & 32777 & 834 & 2 \\\\\n\\hline\nN=10^8 & 60792694 & 33539196 & 5329747 & 329028 & 9257 & 78 \\\\\n\\hline\n\\end{array}$$\n\nFind the product of all non-zero $C_k(10^{16})$. Give the result reduced modulo $1\\,000\\,000\\,007$.", "raw_html": "

For an integer $n$, we define the square prime factors of $n$ to be the primes whose square divides $n$. For example, the square prime factors of $1500=2^2 \\times 3 \\times 5^3$ are $2$ and $5$.

\n\n

Let $C_k(N)$ be the number of integers between $1$ and $N$ inclusive with exactly $k$ square prime factors. You are given some values of $C_k(N)$ in the table below.

\n\n\n$$\\begin{array}{|c|c|c|c|c|c|c|}\n\\hline\n\n& k = 0 & k = 1 & k = 2 & k = 3 & k = 4 & k = 5 \\\\\n\\hline\nN=10 & 7 & 3 & 0 & 0 & 0 & 0 \\\\\n\\hline\nN=10^2 & 61 & 36 & 3 & 0 & 0 & 0 \\\\\n\\hline\nN=10^3 & 608 & 343 & 48 & 1 & 0 & 0 \\\\\n\\hline\nN=10^4 & 6083 & 3363 & 533 & 21 & 0 & 0 \\\\\n\\hline\nN=10^5 & 60794 & 33562 & 5345 & 297 & 2 & 0 \\\\\n\\hline\nN=10^6 & 607926 & 335438 & 53358 & 3218 & 60 & 0 \\\\\n\\hline\nN=10^7 & 6079291 & 3353956 & 533140 & 32777 & 834 & 2 \\\\\n\\hline\nN=10^8 & 60792694 & 33539196 & 5329747 & 329028 & 9257 & 78 \\\\\n\\hline\n\\end{array}$$\n\n\n

Find the product of all non-zero $C_k(10^{16})$. Give the result reduced modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=632", "answer": "728378714"} {"id": 633, "problem": "For an integer $n$, we define the square prime factors of $n$ to be the primes whose square divides $n$. For example, the square prime factors of $1500=2^2 \\times 3 \\times 5^3$ are $2$ and $5$.\n\nLet $C_k(N)$ be the number of integers between $1$ and $N$ inclusive with exactly $k$ square prime factors. It can be shown that with growing $N$ the ratio $\\frac{C_k(N)}{N}$ gets arbitrarily close to a constant $c_{k}^{\\infty}$, as suggested by the table below.\n\n$$\\begin{array}{|c|c|c|c|c|c|}\n\\hline\n& k = 0 & k = 1 & k = 2 & k = 3 & k = 4 \\\\\n\\hline\nC_k(10) & 7 & 3 & 0 & 0 & 0 \\\\\n\\hline\nC_k(10^2) & 61 & 36 & 3 & 0 & 0 \\\\\n\\hline\nC_k(10^3) & 608 & 343 & 48 & 1 & 0 \\\\\n\\hline\nC_k(10^4) & 6083 & 3363 & 533 & 21 & 0 \\\\\n\\hline\nC_k(10^5) & 60794 & 33562 & 5345 & 297 & 2 \\\\\n\\hline\nC_k(10^6) & 607926 & 335438 & 53358 & 3218 & 60 \\\\\n\\hline\nC_k(10^7) & 6079291 & 3353956 & 533140 & 32777 & 834 \\\\\n\\hline\nC_k(10^8) & 60792694 & 33539196 & 5329747 & 329028 & 9257 \\\\\n\\hline\nC_k(10^9) & 607927124 & 335389706 & 53294365 & 3291791 & 95821 \\\\\n\\hline\nc_k^{\\infty} & \\frac{6}{\\pi^2} & 3.3539\\times 10^{-1} & 5.3293\\times 10^{-2} & 3.2921\\times 10^{-3} & 9.7046\\times 10^{-5}\\\\\n\\hline\n\\end{array}$$\nFind $c_{7}^{\\infty}$. Give the result in scientific notation rounded to $5$ significant digits, using a $e$ to separate mantissa and exponent. E.g. if the answer were $0.000123456789$, then the answer format would be $1.2346\\mathrm e{-4}$.", "raw_html": "

For an integer $n$, we define the square prime factors of $n$ to be the primes whose square divides $n$. For example, the square prime factors of $1500=2^2 \\times 3 \\times 5^3$ are $2$ and $5$.

\n\n

Let $C_k(N)$ be the number of integers between $1$ and $N$ inclusive with exactly $k$ square prime factors. It can be shown that with growing $N$ the ratio $\\frac{C_k(N)}{N}$ gets arbitrarily close to a constant $c_{k}^{\\infty}$, as suggested by the table below.

\n\n$$\\begin{array}{|c|c|c|c|c|c|}\n\\hline\n& k = 0 & k = 1 & k = 2 & k = 3 & k = 4 \\\\\n\\hline\nC_k(10) & 7 & 3 & 0 & 0 & 0 \\\\\n\\hline\nC_k(10^2) & 61 & 36 & 3 & 0 & 0 \\\\\n\\hline\nC_k(10^3) & 608 & 343 & 48 & 1 & 0 \\\\\n\\hline\nC_k(10^4) & 6083 & 3363 & 533 & 21 & 0 \\\\\n\\hline\nC_k(10^5) & 60794 & 33562 & 5345 & 297 & 2 \\\\\n\\hline\nC_k(10^6) & 607926 & 335438 & 53358 & 3218 & 60 \\\\\n\\hline\nC_k(10^7) & 6079291 & 3353956 & 533140 & 32777 & 834 \\\\\n\\hline\nC_k(10^8) & 60792694 & 33539196 & 5329747 & 329028 & 9257 \\\\\n\\hline\nC_k(10^9) & 607927124 & 335389706 & 53294365 & 3291791 & 95821 \\\\\n\\hline\nc_k^{\\infty} & \\frac{6}{\\pi^2} & 3.3539\\times 10^{-1} & 5.3293\\times 10^{-2} & 3.2921\\times 10^{-3} & 9.7046\\times 10^{-5}\\\\\n\\hline\n\\end{array}$$\nFind $c_{7}^{\\infty}$. Give the result in scientific notation rounded to $5$ significant digits, using a $e$ to separate mantissa and exponent. E.g. if the answer were $0.000123456789$, then the answer format would be $1.2346\\mathrm e{-4}$.", "url": "https://projecteuler.net/problem=633", "answer": "1.0012e-10"} {"id": 634, "problem": "Define $F(n)$ to be the number of integers $x≤n$ that can be written in the form $x=a^2b^3$, where $a$ and $b$ are integers not necessarily different and both greater than 1.\n\nFor example, $32=2^2\\times 2^3$ and $72=3^2\\times 2^3$ are the only two integers less than $100$ that can be written in this form. Hence, $F(100)=2$.\n\nFurther you are given $F(2\\times 10^4)=130$ and $F(3\\times 10^6)=2014$.\n\nFind $F(9\\times 10^{18})$.", "raw_html": "

\nDefine $F(n)$ to be the number of integers $x≤n$ that can be written in the form $x=a^2b^3$, where $a$ and $b$ are integers not necessarily different and both greater than 1.

\n

\nFor example, $32=2^2\\times 2^3$ and $72=3^2\\times 2^3$ are the only two integers less than $100$ that can be written in this form. Hence, $F(100)=2$.\n

\n

\nFurther you are given $F(2\\times 10^4)=130$ and $F(3\\times 10^6)=2014$.\n

\n

\nFind $F(9\\times 10^{18})$.\n

", "url": "https://projecteuler.net/problem=634", "answer": "4019680944"} {"id": 635, "problem": "Let $A_q(n)$ be the number of subsets, $B$, of the set $\\{1, 2, ..., q \\cdot n\\}$ that satisfy two conditions:\n\n1) $B$ has exactly $n$ elements;\n\n2) the sum of the elements of $B$ is divisible by $n$.\n\nE.g. $A_2(5)=52$ and $A_3(5)=603$.\n\nLet $S_q(L)$ be $\\sum A_q(p)$ where the sum is taken over all primes $p \\le L$.\n\nE.g. $S_2(10)=554$, $S_2(100)$ mod $1\\,000\\,000\\,009=100433628$ and\n$S_3(100)$ mod $1\\,000\\,000\\,009=855618282$.\n\nFind $S_2(10^8)+S_3(10^8)$. Give your answer modulo $1\\,000\\,000\\,009$.", "raw_html": "

\nLet $A_q(n)$ be the number of subsets, $B$, of the set $\\{1, 2, ..., q \\cdot n\\}$ that satisfy two conditions:
\n1) $B$ has exactly $n$ elements;
\n2) the sum of the elements of $B$ is divisible by $n$.\n

\n

\nE.g. $A_2(5)=52$ and $A_3(5)=603$.\n

\nLet $S_q(L)$ be $\\sum A_q(p)$ where the sum is taken over all primes $p \\le L$.
\nE.g. $S_2(10)=554$, $S_2(100)$ mod $1\\,000\\,000\\,009=100433628$ and
$S_3(100)$ mod $1\\,000\\,000\\,009=855618282$.\n\n

\nFind $S_2(10^8)+S_3(10^8)$. Give your answer modulo $1\\,000\\,000\\,009$.\n

", "url": "https://projecteuler.net/problem=635", "answer": "689294705"} {"id": 636, "problem": "Consider writing a natural number as product of powers of natural numbers with given exponents, additionally requiring different base numbers for each power.\n\nFor example, $256$ can be written as a product of a square and a fourth power in three ways such that the base numbers are different.\n\nThat is, $256=1^2\\times 4^4=4^2\\times 2^4=16^2\\times 1^4$\n\nThough $4^2$ and $2^4$ are both equal, we are concerned only about the base numbers in this problem. Note that permutations are not considered distinct, for example $16^2\\times 1^4$ and $1^4 \\times 16^2$ are considered to be the same.\n\nSimilarly, $10!$ can be written as a product of one natural number, two squares and three cubes in two ways ($10!=42\\times5^2\\times4^2\\times3^3\\times2^3\\times1^3=21\\times5^2\\times2^2\\times4^3\\times3^3\\times1^3$) whereas $20!$ can be given the same representation in $41680$ ways.\n\nLet $F(n)$ denote the number of ways in which $n$ can be written as a product of one natural number, two squares, three cubes and four fourth powers.\n\nYou are given that $F(25!)=4933$, $F(100!) \\bmod 1\\,000\\,000\\,007=693\\,952\\,493$,\n\nand $F(1\\,000!) \\bmod 1\\,000\\,000\\,007=6\\,364\\,496$.\n\nFind $F(1\\,000\\,000!) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

Consider writing a natural number as product of powers of natural numbers with given exponents, additionally requiring different base numbers for each power.

\n\n

For example, $256$ can be written as a product of a square and a fourth power in three ways such that the base numbers are different.
\nThat is, $256=1^2\\times 4^4=4^2\\times 2^4=16^2\\times 1^4$

\n\n

Though $4^2$ and $2^4$ are both equal, we are concerned only about the base numbers in this problem. Note that permutations are not considered distinct, for example $16^2\\times 1^4$ and $1^4 \\times 16^2$ are considered to be the same.

\n\n

Similarly, $10!$ can be written as a product of one natural number, two squares and three cubes in two ways ($10!=42\\times5^2\\times4^2\\times3^3\\times2^3\\times1^3=21\\times5^2\\times2^2\\times4^3\\times3^3\\times1^3$) whereas $20!$ can be given the same representation in $41680$ ways.

\n\n

Let $F(n)$ denote the number of ways in which $n$ can be written as a product of one natural number, two squares, three cubes and four fourth powers.

\n\n

You are given that $F(25!)=4933$, $F(100!) \\bmod 1\\,000\\,000\\,007=693\\,952\\,493$,
\nand $F(1\\,000!) \\bmod 1\\,000\\,000\\,007=6\\,364\\,496$.

\n\n

Find $F(1\\,000\\,000!) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=636", "answer": "888316"} {"id": 637, "problem": "Given any positive integer $n$, we can construct a new integer by inserting plus signs between some of the digits of the base $B$ representation of $n$, and then carrying out the additions.\n\nFor example, from $n=123_{10}$ ($n$ in base $10$) we can construct the four base $10$ integers $123_{10}$, $1+23=24_{10}$, $12+3=15_{10}$ and $1+2+3=6_{10}$.\n\nLet $f(n,B)$ be the smallest number of steps needed to arrive at a single-digit number in base $B$. For example, $f(7,10)=0$ and $f(123,10)=1$.\n\nLet $g(n,B_1,B_2)$ be the sum of the positive integers $i$ not exceeding $n$ such that $f(i,B_1)=f(i,B_2)$.\n\nYou are given $g(100,10,3)=3302$.\n\nFind $g(10^7,10,3)$.", "raw_html": "

\nGiven any positive integer $n$, we can construct a new integer by inserting plus signs between some of the digits of the base $B$ representation of $n$, and then carrying out the additions.\n

\n

\nFor example, from $n=123_{10}$ ($n$ in base $10$) we can construct the four base $10$ integers $123_{10}$, $1+23=24_{10}$, $12+3=15_{10}$ and $1+2+3=6_{10}$.\n

\n

\nLet $f(n,B)$ be the smallest number of steps needed to arrive at a single-digit number in base $B$. For example, $f(7,10)=0$ and $f(123,10)=1$.\n

\n

\nLet $g(n,B_1,B_2)$ be the sum of the positive integers $i$ not exceeding $n$ such that $f(i,B_1)=f(i,B_2)$.\n

\n

\nYou are given $g(100,10,3)=3302$. \n

\n

\nFind $g(10^7,10,3)$.\n

", "url": "https://projecteuler.net/problem=637", "answer": "49000634845039"} {"id": 638, "problem": "Let $P_{a,b}$ denote a path in a $a\\times b$ lattice grid with following properties:\n\n- The path begins at $(0,0)$ and ends at $(a,b)$.\n\n- The path consists only of unit moves upwards or to the right; that is the coordinates are increasing with every move.\n\nDenote $A(P_{a,b})$ to be the area under the path. For the example of a $P_{4,3}$ path given below, the area equals $6$.\n\nDefine $G(P_{a,b},k)=k^{A(P_{a,b})}$. Let $C(a,b,k)$ equal the sum of $G(P_{a,b},k)$ over all valid paths in a $a\\times b$ lattice grid.\n\nYou are given that\n\n- $C(2,2,1)=6$\n\n- $C(2,2,2)=35$\n\n- $C(10,10,1)=184\\,756$\n\n- $C(15,10,3) \\equiv 880\\,419\\,838 \\mod 1\\,000\\,000\\,007$\n\n- $C(10\\,000,10\\,000,4) \\equiv 395\\,913\\,804 \\mod 1\\,000\\,000\\,007$\n\nCalculate $\\displaystyle\\sum_{k=1}^7 C(10^k+k, 10^k+k,k)$. Give your answer modulo $1\\,000\\,000\\,007$", "raw_html": "Let $P_{a,b}$ denote a path in a $a\\times b$ lattice grid with following properties:\n
    \n
  • The path begins at $(0,0)$ and ends at $(a,b)$.
  • \n
  • The path consists only of unit moves upwards or to the right; that is the coordinates are increasing with every move.
  • \n
\n\nDenote $A(P_{a,b})$ to be the area under the path. For the example of a $P_{4,3}$ path given below, the area equals $6$.\n\n
\n\"crossed\n
\n

\nDefine $G(P_{a,b},k)=k^{A(P_{a,b})}$. Let $C(a,b,k)$ equal the sum of $G(P_{a,b},k)$ over all valid paths in a $a\\times b$ lattice grid. \n

\n

\nYou are given that\n

\n
    \n
  • $C(2,2,1)=6$
  • \n
  • $C(2,2,2)=35$
  • \n
  • $C(10,10,1)=184\\,756$
  • \n
  • $C(15,10,3) \\equiv 880\\,419\\,838 \\mod 1\\,000\\,000\\,007$
  • \n
  • $C(10\\,000,10\\,000,4) \\equiv 395\\,913\\,804 \\mod 1\\,000\\,000\\,007$
  • \n
\n\nCalculate $\\displaystyle\\sum_{k=1}^7 C(10^k+k, 10^k+k,k)$. Give your answer modulo $1\\,000\\,000\\,007$", "url": "https://projecteuler.net/problem=638", "answer": "18423394"} {"id": 639, "problem": "A multiplicative function $f(x)$ is a function over positive integers satisfying $f(1)=1$ and $f(a b)=f(a) f(b)$ for any two coprime positive integers $a$ and $b$.\n\nFor integer $k$ let $f_k(n)$ be a multiplicative function additionally satisfying $f_k(p^e)=p^k$ for any prime $p$ and any integer $e>0$.\n\nFor example, $f_1(2)=2$, $f_1(4)=2$, $f_1(18)=6$ and $f_2(18)=36$.\n\nLet $\\displaystyle S_k(n)=\\sum_{i=1}^{n} f_k(i)$.\nFor example, $S_1(10)=41$, $S_1(100)=3512$, $S_2(100)=208090$, $S_1(10000)=35252550$ and $\\displaystyle \\sum_{k=1}^{3} S_k(10^{8}) \\equiv 338787512 \\pmod{ 1\\,000\\,000\\,007}$.\n\nFind $\\displaystyle \\sum_{k=1}^{50} S_k(10^{12}) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

A multiplicative function $f(x)$ is a function over positive integers satisfying $f(1)=1$ and $f(a b)=f(a) f(b)$ for any two coprime positive integers $a$ and $b$.

\n\n

For integer $k$ let $f_k(n)$ be a multiplicative function additionally satisfying $f_k(p^e)=p^k$ for any prime $p$ and any integer $e>0$.
\nFor example, $f_1(2)=2$, $f_1(4)=2$, $f_1(18)=6$ and $f_2(18)=36$.

\n\n

Let $\\displaystyle S_k(n)=\\sum_{i=1}^{n} f_k(i)$.\nFor example, $S_1(10)=41$, $S_1(100)=3512$, $S_2(100)=208090$, $S_1(10000)=35252550$ and $\\displaystyle \\sum_{k=1}^{3} S_k(10^{8}) \\equiv 338787512 \\pmod{ 1\\,000\\,000\\,007}$.

\n\n

Find $\\displaystyle \\sum_{k=1}^{50} S_k(10^{12}) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=639", "answer": "797866893"} {"id": 640, "problem": "Bob plays a single-player game of chance using two standard 6-sided dice and twelve cards numbered 1 to 12. When the game starts, all cards are placed face up on a table.\n\nEach turn, Bob rolls both dice, getting numbers $x$ and $y$ respectively, each in the range 1,...,6. He must choose amongst three options: turn over card $x$, card $y$, or card $x+y$. (If the chosen card is already face down, it is turned to face up, and vice versa.)\n\nIf Bob manages to have all twelve cards face down at the same time, he wins.\n\nAlice plays a similar game, except that instead of dice she uses two fair coins, counting heads as 2 and tails as 1, and that she uses four cards instead of twelve. Alice finds that, with the optimal strategy for her game, the expected number of turns taken until she wins is approximately 5.673651.\n\nAssuming that Bob plays with an optimal strategy, what is the expected number of turns taken until he wins? Give your answer rounded to 6 places after the decimal point.", "raw_html": "

Bob plays a single-player game of chance using two standard 6-sided dice and twelve cards numbered 1 to 12. When the game starts, all cards are placed face up on a table.

\n\n

Each turn, Bob rolls both dice, getting numbers $x$ and $y$ respectively, each in the range 1,...,6. He must choose amongst three options: turn over card $x$, card $y$, or card $x+y$. (If the chosen card is already face down, it is turned to face up, and vice versa.)

\n\n

If Bob manages to have all twelve cards face down at the same time, he wins.

\n\n

Alice plays a similar game, except that instead of dice she uses two fair coins, counting heads as 2 and tails as 1, and that she uses four cards instead of twelve. Alice finds that, with the optimal strategy for her game, the expected number of turns taken until she wins is approximately 5.673651.

\n\n

Assuming that Bob plays with an optimal strategy, what is the expected number of turns taken until he wins? Give your answer rounded to 6 places after the decimal point.

", "url": "https://projecteuler.net/problem=640", "answer": "50.317928"} {"id": 641, "problem": "Consider a row of $n$ dice all showing 1.\n\nFirst turn every second die,$ (2,4,6,\\ldots)$, so that the number showing is increased by 1. Then turn every third die. The sixth die will now show a 3. Then turn every fourth die and so on until every $n$th die (only the last die) is turned. If the die to be turned is showing a 6 then it is changed to show a 1.\n\nLet $f(n)$ be the number of dice that are showing a 1 when the process finishes. You are given $f(100)=2$ and $f(10^8) = 69$.\n\nFind $f(10^{36})$.", "raw_html": "

Consider a row of $n$ dice all showing 1.

\n\n

First turn every second die,$ (2,4,6,\\ldots)$, so that the number showing is increased by 1. Then turn every third die. The sixth die will now show a 3. Then turn every fourth die and so on until every $n$th die (only the last die) is turned. If the die to be turned is showing a 6 then it is changed to show a 1.

\n\n

Let $f(n)$ be the number of dice that are showing a 1 when the process finishes. You are given $f(100)=2$ and $f(10^8) = 69$.

\n\n

Find $f(10^{36})$.

", "url": "https://projecteuler.net/problem=641", "answer": "793525366"} {"id": 642, "problem": "Let $f(n)$ be the largest prime factor of $n$ and $\\displaystyle F(n) = \\sum_{i=2}^n f(i)$.\n\nFor example $F(10)=32$, $F(100)=1915$ and $F(10000)=10118280$.\n\nFind $F(201820182018)$. Give your answer modulus $10^9$.", "raw_html": "

Let $f(n)$ be the largest prime factor of $n$ and $\\displaystyle F(n) = \\sum_{i=2}^n f(i)$.
\nFor example $F(10)=32$, $F(100)=1915$ and $F(10000)=10118280$.

\n

\nFind $F(201820182018)$. Give your answer modulus $10^9$.

", "url": "https://projecteuler.net/problem=642", "answer": "631499044"} {"id": 643, "problem": "Two positive integers $a$ and $b$ are $2$-friendly when $\\gcd(a,b) = 2^t, t \\gt 0$. For example, $24$ and $40$ are $2$-friendly because $\\gcd(24,40) = 8 = 2^3$ while $24$ and $36$ are not because $\\gcd(24,36) = 12 = 2^2\\cdot 3$ is not a power of $2$.\n\nLet $f(n)$ be the number of pairs, $(p,q)$, of positive integers with $1\\le p\\lt q\\le n$ such that $p$ and $q$ are $2$-friendly. You are given $f(10^2) = 1031$ and $f(10^6) = 321418433$ modulo $1\\,000\\,000\\,007$.\n\nFind $f(10^{11})$ modulo $1\\,000\\,000\\,007$.", "raw_html": "

Two positive integers $a$ and $b$ are $2$-friendly when $\\gcd(a,b) = 2^t, t \\gt 0$. For example, $24$ and $40$ are $2$-friendly because $\\gcd(24,40) = 8 = 2^3$ while $24$ and $36$ are not because $\\gcd(24,36) = 12 = 2^2\\cdot 3$ is not a power of $2$.

\n\n

Let $f(n)$ be the number of pairs, $(p,q)$, of positive integers with $1\\le p\\lt q\\le n$ such that $p$ and $q$ are $2$-friendly. You are given $f(10^2) = 1031$ and $f(10^6) = 321418433$ modulo $1\\,000\\,000\\,007$.

\n\n

Find $f(10^{11})$ modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=643", "answer": "968274154"} {"id": 644, "problem": "Sam and Tom are trying a game of (partially) covering a given line segment of length $L$ by taking turns in placing unit squares onto the line segment.\n\nAs illustrated below, the squares may be positioned in two different ways, either \"straight\" by placing the midpoints of two opposite sides on the line segment, or \"diagonal\" by placing two opposite corners on the line segment. Newly placed squares may touch other squares, but are not allowed to overlap any other square laid down before.\n\nThe player who is able to place the last unit square onto the line segment wins.\n\nWith Sam starting each game by placing the first square, they quickly realise that Sam can easily win every time by placing the first square in the middle of the line segment, making the game boring.\n\nTherefore they decide to randomise Sam's first move, by first tossing a fair coin to determine whether the square will be placed straight or diagonal onto the line segment and then choosing the actual position on the line segment randomly with all possible positions being equally likely. Sam's gain of the game is defined to be 0 if he loses the game and $L$ if he wins. Assuming optimal play of both players after Sam's initial move, you can see that Sam's expected gain, called $e(L)$, is only dependent on the length of the line segment.\n\nFor example, if $L=2$, Sam will win with a probability of $1$, so $e(2)= 2$.\n\nChoosing $L=4$, the winning probability will be $0.33333333$ for the straight case and $0.22654092$ for the diagonal case, leading to $e(4)=1.11974851$ (rounded to $8$ digits after the decimal point each).\n\nBeing interested in the optimal value of $L$ for Sam, let's define $f(a,b)$ to be the maximum of $e(L)$ for some $L \\in [a,b]$.\n\nYou are given $f(2,10)=2.61969775$, being reached for $L= 7.82842712$, and $f(10,20)=\n5.99374121$ (rounded to $8$ digits each).\n\nFind $f(200,500)$, rounded to $8$ digits after the decimal point.", "raw_html": "

Sam and Tom are trying a game of (partially) covering a given line segment of length $L$ by taking turns in placing unit squares onto the line segment.

\n\n

As illustrated below, the squares may be positioned in two different ways, either \"straight\" by placing the midpoints of two opposite sides on the line segment, or \"diagonal\" by placing two opposite corners on the line segment. Newly placed squares may touch other squares, but are not allowed to overlap any other square laid down before.
\nThe player who is able to place the last unit square onto the line segment wins.

\n
\n\"0644_squareline.png\"\n
\n

\nWith Sam starting each game by placing the first square, they quickly realise that Sam can easily win every time by placing the first square in the middle of the line segment, making the game boring.

\n

\nTherefore they decide to randomise Sam's first move, by first tossing a fair coin to determine whether the square will be placed straight or diagonal onto the line segment and then choosing the actual position on the line segment randomly with all possible positions being equally likely. Sam's gain of the game is defined to be 0 if he loses the game and $L$ if he wins. Assuming optimal play of both players after Sam's initial move, you can see that Sam's expected gain, called $e(L)$, is only dependent on the length of the line segment.

\n

\nFor example, if $L=2$, Sam will win with a probability of $1$, so $e(2)= 2$.
\nChoosing $L=4$, the winning probability will be $0.33333333$ for the straight case and $0.22654092$ for the diagonal case, leading to $e(4)=1.11974851$ (rounded to $8$ digits after the decimal point each).

\n

\nBeing interested in the optimal value of $L$ for Sam, let's define $f(a,b)$ to be the maximum of $e(L)$ for some $L \\in [a,b]$.
\nYou are given $f(2,10)=2.61969775$, being reached for $L= 7.82842712$, and $f(10,20)=\n5.99374121$ (rounded to $8$ digits each).

\n

\nFind $f(200,500)$, rounded to $8$ digits after the decimal point.

", "url": "https://projecteuler.net/problem=644", "answer": "20.11208767"} {"id": 645, "problem": "On planet J, a year lasts for $D$ days. Holidays are defined by the two following rules.\n\n- At the beginning of the reign of the current Emperor, his birthday is declared a holiday from that year onwards.\n\n- If both the day before and after a day $d$ are holidays, then $d$ also becomes a holiday.\n\nInitially there are no holidays. Let $E(D)$ be the expected number of Emperors to reign before all the days of the year are holidays, assuming that their birthdays are independent and uniformly distributed throughout the $D$ days of the year.\n\nYou are given $E(2)=1$, $E(5)=31/6$, $E(365)\\approx 1174.3501$.\n\nFind $E(10000)$. Give your answer rounded to 4 digits after the decimal point.", "raw_html": "

On planet J, a year lasts for $D$ days. Holidays are defined by the two following rules.

\n
    \n
  1. At the beginning of the reign of the current Emperor, his birthday is declared a holiday from that year onwards.
  2. \n
  3. If both the day before and after a day $d$ are holidays, then $d$ also becomes a holiday.
  4. \n
\n

Initially there are no holidays. Let $E(D)$ be the expected number of Emperors to reign before all the days of the year are holidays, assuming that their birthdays are independent and uniformly distributed throughout the $D$ days of the year.

\n

You are given $E(2)=1$, $E(5)=31/6$, $E(365)\\approx 1174.3501$.

\n

Find $E(10000)$. Give your answer rounded to 4 digits after the decimal point.

", "url": "https://projecteuler.net/problem=645", "answer": "48894.2174"} {"id": 646, "problem": "Let $n$ be a natural number and $p_1^{\\alpha_1}\\cdot p_2^{\\alpha_2}\\cdots p_k^{\\alpha_k}$ its prime factorisation.\n\nDefine the Liouville function $\\lambda(n)$ as $\\lambda(n) = (-1)^{\\sum\\limits_{i=1}^{k}\\alpha_i}$.\n\n(i.e. $-1$ if the sum of the exponents $\\alpha_i$ is odd and $1$ if the sum of the exponents is even. )\n\nLet $S(n,L,H)$ be the sum $\\lambda(d) \\cdot d$ over all divisors $d$ of $n$ for which $L \\leq d \\leq H$.\n\nYou are given:\n\n- $S(10! , 100, 1000) = 1457$\n\n- $S(15!, 10^3, 10^5) = -107974$\n\n- $S(30!,10^8, 10^{12}) = 9766732243224$.\n\nFind $S(70!,10^{20}, 10^{60})$ and give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

\nLet $n$ be a natural number and $p_1^{\\alpha_1}\\cdot p_2^{\\alpha_2}\\cdots p_k^{\\alpha_k}$ its prime factorisation.
\nDefine the Liouville function $\\lambda(n)$ as $\\lambda(n) = (-1)^{\\sum\\limits_{i=1}^{k}\\alpha_i}$.
\n(i.e. $-1$ if the sum of the exponents $\\alpha_i$ is odd and $1$ if the sum of the exponents is even. )
\nLet $S(n,L,H)$ be the sum $\\lambda(d) \\cdot d$ over all divisors $d$ of $n$ for which $L \\leq d \\leq H$.\n

\n

\nYou are given:

\n
    \n
  • $S(10! , 100, 1000) = 1457$
  • \n
  • $S(15!, 10^3, 10^5) = -107974$
  • \n
  • $S(30!,10^8, 10^{12}) = 9766732243224$.
\n

\nFind $S(70!,10^{20}, 10^{60})$ and give your answer modulo $1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=646", "answer": "845218467"} {"id": 647, "problem": "It is possible to find positive integers $A$ and $B$ such that given any triangular number, $T_n$, then $AT_n +B$ is always a triangular number. We define $F_3(N)$ to be the sum of $(A+B)$ over all such possible pairs $(A,B)$ with $\\max(A,B)\\le N$. For example $F_3(100) = 184$.\n\nPolygonal numbers are generalisations of triangular numbers. Polygonal numbers with parameter $k$ we call $k$-gonal numbers. The formula for the $n$th $k$-gonal number is $\\frac 12n\\big(n(k-2)+4-k\\big)$ where $n \\ge 1$. For example when $k = 3$ we get $\\frac 12n(n+1)$ the formula for triangular numbers.\n\nThe statement above is true for pentagonal, heptagonal and in fact any $k$-gonal number with $k$ odd. For example when $k=5$ we get the pentagonal numbers and we can find positive integers $A$ and $B$ such that given any pentagonal number, $P_n$, then $AP_n+B$ is always a pentagonal number. We define $F_5(N)$ to be the sum of $(A+B)$ over all such possible pairs $(A,B)$ with $\\max(A,B)\\le N$.\n\nSimilarly we define $F_k(N)$ for odd $k$. You are given $\\sum_{k} F_k(10^3) = 14993$ where the sum is over all odd $k = 3,5,7,\\ldots$.\n\nFind $\\sum_{k} F_k(10^{12})$ where the sum is over all odd $k = 3,5,7,\\ldots$", "raw_html": "

\nIt is possible to find positive integers $A$ and $B$ such that given any triangular number, $T_n$, then $AT_n +B$ is always a triangular number. We define $F_3(N)$ to be the sum of $(A+B)$ over all such possible pairs $(A,B)$ with $\\max(A,B)\\le N$. For example $F_3(100) = 184$.\n

\n

\nPolygonal numbers are generalisations of triangular numbers. Polygonal numbers with parameter $k$ we call $k$-gonal numbers. The formula for the $n$th $k$-gonal number is $\\frac 12n\\big(n(k-2)+4-k\\big)$ where $n \\ge 1$. For example when $k = 3$ we get $\\frac 12n(n+1)$ the formula for triangular numbers.\n

\n

\nThe statement above is true for pentagonal, heptagonal and in fact any $k$-gonal number with $k$ odd. For example when $k=5$ we get the pentagonal numbers and we can find positive integers $A$ and $B$ such that given any pentagonal number, $P_n$, then $AP_n+B$ is always a pentagonal number. We define $F_5(N)$ to be the sum of $(A+B)$ over all such possible pairs $(A,B)$ with $\\max(A,B)\\le N$.\n

\n

\nSimilarly we define $F_k(N)$ for odd $k$. You are given $\\sum_{k} F_k(10^3) = 14993$ where the sum is over all odd $k = 3,5,7,\\ldots$.\n

\n

\nFind $\\sum_{k} F_k(10^{12})$ where the sum is over all odd $k = 3,5,7,\\ldots$\n

", "url": "https://projecteuler.net/problem=647", "answer": "563132994232918611"} {"id": 648, "problem": "For some fixed $\\rho \\in [0, 1]$, we begin a sum $s$ at $0$ and repeatedly apply a process: With probability $\\rho$, we add $1$ to $s$, otherwise we add $2$ to $s$.\n\nThe process ends when either $s$ is a perfect square or $s$ exceeds $10^{18}$, whichever occurs first. For example, if $s$ goes through $0, 2, 3, 5, 7, 9$, the process ends at $s=9$, and two squares $1$ and $4$ were skipped over.\n\nLet $f(\\rho)$ be the expected number of perfect squares skipped over when the process finishes.\n\nIt can be shown that the power series for $f(\\rho)$ is $\\sum_{k=0}^\\infty a_k \\rho^k$ for a suitable (unique) choice of coefficients $a_k$. Some of the first few coefficients are $a_0=1$, $a_1=0$, $a_5=-18$, $a_{10}=45176$.\n\nLet $F(n) = \\sum_{k=0}^n a_k$. You are given that $F(10) = 53964$ and $F(50) \\equiv 842418857 \\pmod{10^9}$.\n\nFind $F(1000)$, and give your answer modulo $10^9$.", "raw_html": "

For some fixed $\\rho \\in [0, 1]$, we begin a sum $s$ at $0$ and repeatedly apply a process: With probability $\\rho$, we add $1$ to $s$, otherwise we add $2$ to $s$.

\n\n

The process ends when either $s$ is a perfect square or $s$ exceeds $10^{18}$, whichever occurs first. For example, if $s$ goes through $0, 2, 3, 5, 7, 9$, the process ends at $s=9$, and two squares $1$ and $4$ were skipped over.

\n\n

Let $f(\\rho)$ be the expected number of perfect squares skipped over when the process finishes.

\n\n

It can be shown that the power series for $f(\\rho)$ is $\\sum_{k=0}^\\infty a_k \\rho^k$ for a suitable (unique) choice of coefficients $a_k$. Some of the first few coefficients are $a_0=1$, $a_1=0$, $a_5=-18$, $a_{10}=45176$.

\n\n

Let $F(n) = \\sum_{k=0}^n a_k$. You are given that $F(10) = 53964$ and $F(50) \\equiv 842418857 \\pmod{10^9}$.

\n\n

Find $F(1000)$, and give your answer modulo $10^9$.

", "url": "https://projecteuler.net/problem=648", "answer": "301483197"} {"id": 649, "problem": "Alice and Bob are taking turns playing a game consisting of $c$ different coins on a chessboard of size $n$ by $n$.\n\nThe game may start with any arrangement of $c$ coins in squares on the board. It is possible at any time for more than one coin to occupy the same square on the board at the same time. The coins are distinguishable, so swapping two coins gives a different arrangement if (and only if) they are on different squares.\n\nOn a given turn, the player must choose a coin and move it either left or up $2$, $3$, $5$, or $7$ spaces in a single direction. The only restriction is that the coin cannot move off the edge of the board.\n\nThe game ends when a player is unable to make a valid move, thereby granting the other player the victory.\n\nAssuming that Alice goes first and that both players are playing optimally, let $M(n, c)$ be the number of possible starting arrangements for which Alice can ensure her victory, given a board of size $n$ by $n$ with $c$ distinct coins.\n\nFor example, $M(3, 1) = 4$, $M(3, 2) = 40$, and $M(9, 3) = 450304$.\n\nWhat are the last $9$ digits of $M(10\\,000\\,019, 100)$?", "raw_html": "Alice and Bob are taking turns playing a game consisting of $c$ different coins on a chessboard of size $n$ by $n$.\n\n

The game may start with any arrangement of $c$ coins in squares on the board. It is possible at any time for more than one coin to occupy the same square on the board at the same time. The coins are distinguishable, so swapping two coins gives a different arrangement if (and only if) they are on different squares.

\n\n

On a given turn, the player must choose a coin and move it either left or up $2$, $3$, $5$, or $7$ spaces in a single direction. The only restriction is that the coin cannot move off the edge of the board.

\n\n

The game ends when a player is unable to make a valid move, thereby granting the other player the victory.

\n\n

Assuming that Alice goes first and that both players are playing optimally, let $M(n, c)$ be the number of possible starting arrangements for which Alice can ensure her victory, given a board of size $n$ by $n$ with $c$ distinct coins.

\n\n

For example, $M(3, 1) = 4$, $M(3, 2) = 40$, and $M(9, 3) = 450304$.

\n\n

What are the last $9$ digits of $M(10\\,000\\,019, 100)$?

", "url": "https://projecteuler.net/problem=649", "answer": "924668016"} {"id": 650, "problem": "Let $B(n) = \\displaystyle \\prod_{k=0}^n {n \\choose k}$, a product of binomial coefficients.\n\nFor example, $B(5) = {5 \\choose 0} \\times {5 \\choose 1} \\times {5 \\choose 2} \\times {5 \\choose 3} \\times {5 \\choose 4} \\times {5 \\choose 5} = 1 \\times 5 \\times 10 \\times 10 \\times 5 \\times 1 = 2500$.\n\nLet $D(n) = \\displaystyle \\sum_{d|B(n)} d$, the sum of the divisors of $B(n)$.\n\nFor example, the divisors of B(5) are 1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500, 625, 1250 and 2500,\n\nso D(5) = 1 + 2 + 4 + 5 + 10 + 20 + 25 + 50 + 100 + 125 + 250 + 500 + 625 + 1250 + 2500 = 5467.\n\nLet $S(n) = \\displaystyle \\sum_{k=1}^n D(k)$.\n\nYou are given $S(5) = 5736$, $S(10) = 141740594713218418$ and $S(100)$ mod $1\\,000\\,000\\,007 = 332792866$.\n\nFind $S(20\\,000)$ mod $1\\,000\\,000\\,007$.", "raw_html": "

\nLet $B(n) = \\displaystyle \\prod_{k=0}^n {n \\choose k}$, a product of binomial coefficients.
\nFor example, $B(5) = {5 \\choose 0} \\times {5 \\choose 1} \\times {5 \\choose 2} \\times {5 \\choose 3} \\times {5 \\choose 4} \\times {5 \\choose 5} = 1 \\times 5 \\times 10 \\times 10 \\times 5 \\times 1 = 2500$.\n

\n

\nLet $D(n) = \\displaystyle \\sum_{d|B(n)} d$, the sum of the divisors of $B(n)$.
\nFor example, the divisors of B(5) are 1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500, 625, 1250 and 2500,
\nso D(5) = 1 + 2 + 4 + 5 + 10 + 20 + 25 + 50 + 100 + 125 + 250 + 500 + 625 + 1250 + 2500 = 5467.\n

\n

\nLet $S(n) = \\displaystyle \\sum_{k=1}^n D(k)$.
\nYou are given $S(5) = 5736$, $S(10) = 141740594713218418$ and $S(100)$ mod $1\\,000\\,000\\,007 = 332792866$.\n

\n

\nFind $S(20\\,000)$ mod $1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=650", "answer": "538319652"} {"id": 651, "problem": "An infinitely long cylinder has its curved surface fully covered with different coloured but otherwise identical rectangular stickers, without overlapping. The stickers are aligned with the cylinder, so two of their edges are parallel with the cylinder's axis, with four stickers meeting at each corner.\n\nLet $a>0$ and suppose that the colouring is periodic along the cylinder, with the pattern repeating every $a$ stickers. (The period is allowed to be any divisor of $a$.) Let $b$ be the number of stickers that fit round the circumference of the cylinder.\n\nLet $f(m, a, b)$ be the number of different such periodic patterns that use exactly $m$ distinct colours of stickers. Translations along the axis, reflections in any plane, rotations in any axis, (or combinations of such operations) applied to a pattern are to be counted as the same as the original pattern.\n\nYou are given that $f(2, 2, 3) = 11$, $f(3, 2, 3) = 56$, and $f(2, 3, 4) = 156$.\nFurthermore, $f(8, 13, 21) \\equiv 49718354 \\pmod{1\\,000\\,000\\,007}$,\nand $f(13, 144, 233) \\equiv 907081451 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $\\sum_{i=4}^{40} f(i, F_{i-1}, F_i) \\bmod 1\\,000\\,000\\,007$, where $F_i$ are the Fibonacci numbers starting at $F_0=0$, $F_1=1$.", "raw_html": "

An infinitely long cylinder has its curved surface fully covered with different coloured but otherwise identical rectangular stickers, without overlapping. The stickers are aligned with the cylinder, so two of their edges are parallel with the cylinder's axis, with four stickers meeting at each corner.

\n\n

Let $a>0$ and suppose that the colouring is periodic along the cylinder, with the pattern repeating every $a$ stickers. (The period is allowed to be any divisor of $a$.) Let $b$ be the number of stickers that fit round the circumference of the cylinder.

\n\n

Let $f(m, a, b)$ be the number of different such periodic patterns that use exactly $m$ distinct colours of stickers. Translations along the axis, reflections in any plane, rotations in any axis, (or combinations of such operations) applied to a pattern are to be counted as the same as the original pattern.

\n\n

You are given that $f(2, 2, 3) = 11$, $f(3, 2, 3) = 56$, and $f(2, 3, 4) = 156$.\nFurthermore, $f(8, 13, 21) \\equiv 49718354 \\pmod{1\\,000\\,000\\,007}$,\nand $f(13, 144, 233) \\equiv 907081451 \\pmod{1\\,000\\,000\\,007}$.

\n\n

Find $\\sum_{i=4}^{40} f(i, F_{i-1}, F_i) \\bmod 1\\,000\\,000\\,007$, where $F_i$ are the Fibonacci numbers starting at $F_0=0$, $F_1=1$.

", "url": "https://projecteuler.net/problem=651", "answer": "448233151"} {"id": 652, "problem": "Consider the values of $\\log_2(8)$, $\\log_4(64)$ and $\\log_3(27)$. All three are equal to $3$.\n\nGenerally, the function $f(m,n)=\\log_m(n)$ over integers $m,n \\ge 2$ has the property that\n\n$f(m_1,n_1)=f(m_2,n_2)$ if\n\n- $\\, m_1=a^e, n_1=a^f, m_2=b^e,n_2=b^f \\,$ for some integers $a,b,e,f \\, \\,$ or\n\n- $ \\, m_1=a^e, n_1=b^e, m_2=a^f,n_2=b^f \\,$ for some integers $a,b,e,f \\,$\n\nWe call a function $g(m,n)$ over integers $m,n \\ge 2$ proto-logarithmic if\n\n- $\\quad \\, \\, \\, \\, g(m_1,n_1)=g(m_2,n_2)$ if any integers $a,b,e,f$ fulfilling 1. or 2. can be found\n\n- and $\\, g(m_1,n_1) \\ne g(m_2,n_2)$ if no integers $a,b,e,f$ fulfilling 1. or 2. can be found.\n\nLet $D(N)$ be the number of distinct values that any proto-logarithmic function $g(m,n)$ attains over $2\\le m, n\\le N$.\n\nFor example, $D(5)=13$, $D(10)=69$, $D(100)=9607$ and $D(10000)=99959605$.\n\nFind $D(10^{18})$, and give the last $9$ digits as answer.\n\nNote: According to the four exponentials conjecture the function $\\log_m(n)$ is proto-logarithmic.\nWhile this conjecture is yet unproven in general, $\\log_m(n)$ can be used to calculate $D(N)$ for small values of $N$.", "raw_html": "

Consider the values of $\\log_2(8)$, $\\log_4(64)$ and $\\log_3(27)$. All three are equal to $3$.

\n\n

Generally, the function $f(m,n)=\\log_m(n)$ over integers $m,n \\ge 2$ has the property that
\n$f(m_1,n_1)=f(m_2,n_2)$ if\n

    \n
  1. $\\, m_1=a^e, n_1=a^f, m_2=b^e,n_2=b^f \\,$ for some integers $a,b,e,f \\, \\,$ or
  2. \n
  3. $ \\, m_1=a^e, n_1=b^e, m_2=a^f,n_2=b^f \\,$ for some integers $a,b,e,f \\,$
\n\n\n

We call a function $g(m,n)$ over integers $m,n \\ge 2$ proto-logarithmic if \n

  • $\\quad \\, \\, \\, \\, g(m_1,n_1)=g(m_2,n_2)$ if any integers $a,b,e,f$ fulfilling 1. or 2. can be found
  • \n
  • and $\\, g(m_1,n_1) \\ne g(m_2,n_2)$ if no integers $a,b,e,f$ fulfilling 1. or 2. can be found.
  • \n
\n

Let $D(N)$ be the number of distinct values that any proto-logarithmic function $g(m,n)$ attains over $2\\le m, n\\le N$.
\nFor example, $D(5)=13$, $D(10)=69$, $D(100)=9607$ and $D(10000)=99959605$.

\n\n

Find $D(10^{18})$, and give the last $9$ digits as answer.

\n\n\n


\nNote: According to the four exponentials conjecture the function $\\log_m(n)$ is proto-logarithmic.
While this conjecture is yet unproven in general, $\\log_m(n)$ can be used to calculate $D(N)$ for small values of $N$.

", "url": "https://projecteuler.net/problem=652", "answer": "983924497"} {"id": 653, "problem": "Consider a horizontal frictionless tube with length $L$ millimetres, and a diameter of 20 millimetres. The east end of the tube is open, while the west end is sealed. The tube contains $N$ marbles of diameter 20 millimetres at designated starting locations, each one initially moving either westward or eastward with common speed $v$.\n\nSince there are marbles moving in opposite directions, there are bound to be some collisions. We assume that the collisions are perfectly elastic, so both marbles involved instantly change direction and continue with speed $v$ away from the collision site. Similarly, if the west-most marble collides with the sealed end of the tube, it instantly changes direction and continues eastward at speed $v$. On the other hand, once a marble reaches the unsealed east end, it exits the tube and has no further interaction with the remaining marbles.\n\nTo obtain the starting positions and initial directions, we use the pseudo-random sequence $r_j$ defined by:\n\n$r_1 = 6\\,563\\,116$\n\n$r_{j+1} = r_j^2 \\bmod 32\\,745\\,673$\n\nThe west-most marble is initially positioned with a gap of $(r_1 \\bmod 1000) + 1$ millimetres between it and the sealed end of the tube, measured from the west-most point of the surface of the marble. Then, for $2\\le j\\le N$, counting from the west, the gap between the $(j-1)$th and $j$th marbles, as measured from their closest points, is given by $(r_j \\bmod 1000) + 1$ millimetres.\nFurthermore, the $j$th marble is initially moving eastward if $r_j \\le 10\\,000\\,000$, and westward if $r_j > 10\\,000\\,000$.\n\nFor example, with $N=3$, the sequence specifies gaps of 117, 432, and 173 millimetres. The marbles' centres are therefore 127, 579, and 772 millimetres from the sealed west end of the tube. The west-most marble initially moves eastward, while the other two initially move westward.\n\nUnder this setup, and with a five metre tube ($L=5000$), it turns out that the middle (second) marble travels 5519 millimetres before its centre reaches the east-most end of the tube.\n\nLet $d(L, N, j)$ be the distance in millimetres that the $j$th marble travels before its centre reaches the eastern end of the tube. So $d(5000, 3, 2) = 5519$. You are also given that $d(10\\,000, 11, 6) = 11\\,780$ and $d(100\\,000, 101, 51) = 114\\,101$.\n\nFind $d(1\\,000\\,000\\,000, 1\\,000\\,001, 500\\,001)$.", "raw_html": "

Consider a horizontal frictionless tube with length $L$ millimetres, and a diameter of 20 millimetres. The east end of the tube is open, while the west end is sealed. The tube contains $N$ marbles of diameter 20 millimetres at designated starting locations, each one initially moving either westward or eastward with common speed $v$.

\n\n

Since there are marbles moving in opposite directions, there are bound to be some collisions. We assume that the collisions are perfectly elastic, so both marbles involved instantly change direction and continue with speed $v$ away from the collision site. Similarly, if the west-most marble collides with the sealed end of the tube, it instantly changes direction and continues eastward at speed $v$. On the other hand, once a marble reaches the unsealed east end, it exits the tube and has no further interaction with the remaining marbles.

\n\n

To obtain the starting positions and initial directions, we use the pseudo-random sequence $r_j$ defined by:
\n$r_1 = 6\\,563\\,116$
\n$r_{j+1} = r_j^2 \\bmod 32\\,745\\,673$
\nThe west-most marble is initially positioned with a gap of $(r_1 \\bmod 1000) + 1$ millimetres between it and the sealed end of the tube, measured from the west-most point of the surface of the marble. Then, for $2\\le j\\le N$, counting from the west, the gap between the $(j-1)$th and $j$th marbles, as measured from their closest points, is given by $(r_j \\bmod 1000) + 1$ millimetres.\nFurthermore, the $j$th marble is initially moving eastward if $r_j \\le 10\\,000\\,000$, and westward if $r_j > 10\\,000\\,000$.

\n\n

For example, with $N=3$, the sequence specifies gaps of 117, 432, and 173 millimetres. The marbles' centres are therefore 127, 579, and 772 millimetres from the sealed west end of the tube. The west-most marble initially moves eastward, while the other two initially move westward.

\n\n

Under this setup, and with a five metre tube ($L=5000$), it turns out that the middle (second) marble travels 5519 millimetres before its centre reaches the east-most end of the tube.

\n\n

Let $d(L, N, j)$ be the distance in millimetres that the $j$th marble travels before its centre reaches the eastern end of the tube. So $d(5000, 3, 2) = 5519$. You are also given that $d(10\\,000, 11, 6) = 11\\,780$ and $d(100\\,000, 101, 51) = 114\\,101$.

\n\n

Find $d(1\\,000\\,000\\,000, 1\\,000\\,001, 500\\,001)$.

", "url": "https://projecteuler.net/problem=653", "answer": "1130658687"} {"id": 654, "problem": "Let $T(n, m)$ be the number of $m$-tuples of positive integers such that the sum of any two neighbouring elements of the tuple is $\\le n$.\n\nFor example, $T(3, 4)=8$, via the following eight $4$-tuples:\n\n$(1, 1, 1, 1)$\n\n$(1, 1, 1, 2)$\n\n$(1, 1, 2, 1)$\n\n$(1, 2, 1, 1)$\n\n$(1, 2, 1, 2)$\n\n$(2, 1, 1, 1)$\n\n$(2, 1, 1, 2)$\n\n$(2, 1, 2, 1)$\n\nYou are also given that $T(5, 5)=246$, $T(10, 10^{2}) \\equiv 862820094 \\pmod{1\\,000\\,000\\,007}$ and $T(10^2, 10) \\equiv 782136797 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $T(5000, 10^{12}) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

\nLet $T(n, m)$ be the number of $m$-tuples of positive integers such that the sum of any two neighbouring elements of the tuple is $\\le n$.\n

\n

\nFor example, $T(3, 4)=8$, via the following eight $4$-tuples:
\n$(1, 1, 1, 1)$
\n$(1, 1, 1, 2)$
\n$(1, 1, 2, 1)$
\n$(1, 2, 1, 1)$
\n$(1, 2, 1, 2)$
\n$(2, 1, 1, 1)$
\n$(2, 1, 1, 2)$
\n$(2, 1, 2, 1)$
\n

\n

\nYou are also given that $T(5, 5)=246$, $T(10, 10^{2}) \\equiv 862820094 \\pmod{1\\,000\\,000\\,007}$ and $T(10^2, 10) \\equiv 782136797 \\pmod{1\\,000\\,000\\,007}$.\n

\n

\nFind $T(5000, 10^{12}) \\bmod 1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=654", "answer": "815868280"} {"id": 655, "problem": "The numbers $545$, $5\\,995$ and $15\\,151$ are the three smallest palindromes divisible by $109$. There are nine palindromes less than $100\\,000$ which are divisible by $109$.\n\nHow many palindromes less than $10^{32}$ are divisible by $10\\,000\\,019\\,$ ?", "raw_html": "

The numbers $545$, $5\\,995$ and $15\\,151$ are the three smallest palindromes divisible by $109$. There are nine palindromes less than $100\\,000$ which are divisible by $109$.

\n\n

How many palindromes less than $10^{32}$ are divisible by $10\\,000\\,019\\,$ ?

", "url": "https://projecteuler.net/problem=655", "answer": "2000008332"} {"id": 656, "problem": "Given an irrational number $\\alpha$, let $S_\\alpha(n)$ be the sequence $S_\\alpha(n)=\\lfloor {\\alpha \\cdot n} \\rfloor - \\lfloor {\\alpha \\cdot (n-1)} \\rfloor$ for $n \\ge 1$.\n\n($\\lfloor \\cdots \\rfloor$ is the floor-function.)\n\nIt can be proven that for any irrational $\\alpha$ there exist infinitely many values of $n$ such that the subsequence $ \\{S_\\alpha(1),S_\\alpha(2)...S_\\alpha(n) \\} $ is palindromic.\n\nThe first $20$ values of $n$ that give a palindromic subsequence for $\\alpha = \\sqrt{31}$ are:\n$1$, $3$, $5$, $7$, $44$, $81$, $118$, $273$, $3158$, $9201$, $15244$, $21287$, $133765$, $246243$, $358721$, $829920$, $9600319$, $27971037$, $46341755$, $64712473$.\n\nLet $H_g(\\alpha)$ be the sum of the first $g$ values of $n$ for which the corresponding subsequence is palindromic.\n\nSo $H_{20}(\\sqrt{31})=150243655$.\n\nLet $T=\\{2,3,5,6,7,8,10,\\dots,1000\\}$ be the set of positive integers, not exceeding $1000$, excluding perfect squares.\n\nCalculate the sum of $H_{100}(\\sqrt \\beta)$ for $\\beta \\in T$. Give the last $15$ digits of your answer.", "raw_html": "

\nGiven an irrational number $\\alpha$, let $S_\\alpha(n)$ be the sequence $S_\\alpha(n)=\\lfloor {\\alpha \\cdot n} \\rfloor - \\lfloor {\\alpha \\cdot (n-1)} \\rfloor$ for $n \\ge 1$.
\n($\\lfloor \\cdots \\rfloor$ is the floor-function.)\n

\n

\nIt can be proven that for any irrational $\\alpha$ there exist infinitely many values of $n$ such that the subsequence $ \\{S_\\alpha(1),S_\\alpha(2)...S_\\alpha(n) \\} $ is palindromic.

\n

\nThe first $20$ values of $n$ that give a palindromic subsequence for $\\alpha = \\sqrt{31}$ are:\n$1$, $3$, $5$, $7$, $44$, $81$, $118$, $273$, $3158$, $9201$, $15244$, $21287$, $133765$, $246243$, $358721$, $829920$, $9600319$, $27971037$, $46341755$, $64712473$.

\n

\nLet $H_g(\\alpha)$ be the sum of the first $g$ values of $n$ for which the corresponding subsequence is palindromic.
\nSo $H_{20}(\\sqrt{31})=150243655$.\n

\nLet $T=\\{2,3,5,6,7,8,10,\\dots,1000\\}$ be the set of positive integers, not exceeding $1000$, excluding perfect squares.
\nCalculate the sum of $H_{100}(\\sqrt \\beta)$ for $\\beta \\in T$. Give the last $15$ digits of your answer.\n

", "url": "https://projecteuler.net/problem=656", "answer": "888873503555187"} {"id": 657, "problem": "In the context of formal languages, any finite sequence of letters of a given alphabet $\\Sigma$ is called a word over $\\Sigma$. We call a word incomplete if it does not contain every letter of $\\Sigma$.\n\nFor example, using the alphabet $\\Sigma=\\{ a, b, c\\}$, '$ab$', '$abab$' and '$\\,$' (the empty word) are incomplete words over $\\Sigma$, while '$abac$' is a complete word over $\\Sigma$.\n\nGiven an alphabet $\\Sigma$ of $\\alpha$ letters, we define $I(\\alpha,n)$ to be the number of incomplete words over $\\Sigma$ with a length not exceeding $n$.\n\nFor example, $I(3,0)=1$, $I(3,2)=13$ and $I(3,4)=79$.\n\nFind $I(10^7,10^{12})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

In the context of formal languages, any finite sequence of letters of a given alphabet $\\Sigma$ is called a word over $\\Sigma$. We call a word incomplete if it does not contain every letter of $\\Sigma$.

\n

\nFor example, using the alphabet $\\Sigma=\\{ a, b, c\\}$, '$ab$', '$abab$' and '$\\,$' (the empty word) are incomplete words over $\\Sigma$, while '$abac$' is a complete word over $\\Sigma$.

\n

\nGiven an alphabet $\\Sigma$ of $\\alpha$ letters, we define $I(\\alpha,n)$ to be the number of incomplete words over $\\Sigma$ with a length not exceeding $n$.
\nFor example, $I(3,0)=1$, $I(3,2)=13$ and $I(3,4)=79$.

\n

\nFind $I(10^7,10^{12})$. Give your answer modulo $1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=657", "answer": "219493139"} {"id": 658, "problem": "In the context of formal languages, any finite sequence of letters of a given alphabet $\\Sigma$ is called a word over $\\Sigma$. We call a word incomplete if it does not contain every letter of $\\Sigma$.\n\nFor example, using the alphabet $\\Sigma=\\{ a, b, c\\}$, '$ab$', '$abab$' and '$\\,$' (the empty word) are incomplete words over $\\Sigma$, while '$abac$' is a complete word over $\\Sigma$.\n\nGiven an alphabet $\\Sigma$ of $\\alpha$ letters, we define $I(\\alpha,n)$ to be the number of incomplete words over $\\Sigma$ with a length not exceeding $n$.\n\nFor example, $I(3,0)=1$, $I(3,2)=13$ and $I(3,4)=79$.\n\nLet $\\displaystyle S(k,n)=\\sum_{\\alpha=1}^k I(\\alpha,n)$.\n\nFor example, $S(4,4)=406$, $S(8,8)=27902680$ and $S (10,100) \\equiv 983602076 \\bmod 1\\,000\\,000\\,007$.\n\nFind $S(10^7,10^{12})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

In the context of formal languages, any finite sequence of letters of a given alphabet $\\Sigma$ is called a word over $\\Sigma$. We call a word incomplete if it does not contain every letter of $\\Sigma$.

\n

\nFor example, using the alphabet $\\Sigma=\\{ a, b, c\\}$, '$ab$', '$abab$' and '$\\,$' (the empty word) are incomplete words over $\\Sigma$, while '$abac$' is a complete word over $\\Sigma$.

\n

\nGiven an alphabet $\\Sigma$ of $\\alpha$ letters, we define $I(\\alpha,n)$ to be the number of incomplete words over $\\Sigma$ with a length not exceeding $n$.
\nFor example, $I(3,0)=1$, $I(3,2)=13$ and $I(3,4)=79$.

\n

\nLet $\\displaystyle S(k,n)=\\sum_{\\alpha=1}^k I(\\alpha,n)$.
\nFor example, $S(4,4)=406$, $S(8,8)=27902680$ and $S (10,100) \\equiv 983602076 \\bmod 1\\,000\\,000\\,007$.

\n

\nFind $S(10^7,10^{12})$. Give your answer modulo $1\\,000\\,000\\,007$.\n

", "url": "https://projecteuler.net/problem=658", "answer": "958280177"} {"id": 659, "problem": "Consider the sequence $n^2+3$ with $n \\ge 1$.\n\nIf we write down the first terms of this sequence we get:\n\n$4, 7, 12, 19, 28, 39, 52, 67, 84, 103, 124, 147, 172, 199, 228, 259, 292, 327, 364, \\dots$ .\n\nWe see that the terms for $n=6$ and $n=7$ ($39$ and $52$) are both divisible by $13$.\n\nIn fact $13$ is the largest prime dividing any two successive terms of this sequence.\n\nLet $P(k)$ be the largest prime that divides any two successive terms of the sequence $n^2+k^2$.\n\nFind the last $18$ digits of $\\displaystyle \\sum_{k=1}^{10\\,000\\,000} P(k)$.", "raw_html": "

\nConsider the sequence $n^2+3$ with $n \\ge 1$.
\nIf we write down the first terms of this sequence we get:
\n$4, 7, 12, 19, 28, 39, 52, 67, 84, 103, 124, 147, 172, 199, 228, 259, 292, 327, 364, \\dots$ .
\nWe see that the terms for $n=6$ and $n=7$ ($39$ and $52$) are both divisible by $13$.
\nIn fact $13$ is the largest prime dividing any two successive terms of this sequence.\n

\n

\nLet $P(k)$ be the largest prime that divides any two successive terms of the sequence $n^2+k^2$.\n

\n

\nFind the last $18$ digits of $\\displaystyle \\sum_{k=1}^{10\\,000\\,000} P(k)$.\n

", "url": "https://projecteuler.net/problem=659", "answer": "238518915714422000"} {"id": 660, "problem": "We call an integer sided triangle $n$-pandigital if it contains one angle of $120$ degrees and, when the sides of the triangle are written in base $n$, together they use all $n$ digits of that base exactly once.\n\nFor example, the triangle $(217, 248, 403)$ is $9$-pandigital because it contains one angle of $120$ degrees and the sides written in base $9$ are $261_9, 305_9, 487_9$ using each of the $9$ digits of that base once.\n\nFind the sum of the largest sides of all $n$-pandigital triangles with $9 \\le n \\le 18$.", "raw_html": "

We call an integer sided triangle $n$-pandigital if it contains one angle of $120$ degrees and, when the sides of the triangle are written in base $n$, together they use all $n$ digits of that base exactly once.

\n\n

\nFor example, the triangle $(217, 248, 403)$ is $9$-pandigital because it contains one angle of $120$ degrees and the sides written in base $9$ are $261_9, 305_9, 487_9$ using each of the $9$ digits of that base once.

\n\n

Find the sum of the largest sides of all $n$-pandigital triangles with $9 \\le n \\le 18$.

", "url": "https://projecteuler.net/problem=660", "answer": "474766783"} {"id": 661, "problem": "Two friends $A$ and $B$ are great fans of Chess. They both enjoy playing the game, but after each game the player who lost the game would like to continue (to get back at the other player) and the player who won would prefer to stop (to finish on a high).\n\nSo they come up with a plan. After every game, they would toss a (biased) coin with probability $p$ of Heads (and hence probability $1-p$ of Tails). If they get Tails, they will continue with the next game. Otherwise they end the match. Also, after every game the players make a note of who is leading in the match.\n\nLet $p_A$ denote the probability of $A$ winning a game and $p_B$ the probability of $B$ winning a game. Accordingly $1-p_A-p_B$ is the probability that a game ends in a draw. Let $\\mathbb{E}_A(p_A,p_B,p)$ denote the expected number of times $A$ was leading in the match.\n\nFor example, $\\mathbb{E}_A(0.25,0.25,0.5)\\approx 0.585786$ and $\\mathbb{E}_A(0.47,0.48,0.001)\\approx 377.471736$, both rounded to six places after the decimal point.\n\nLet $\\displaystyle H(n)=\\sum_{k=3}^n \\mathbb{E}_A\\left(\\frac 1 {\\sqrt{k+3}},\\frac 1 {\\sqrt{k+3}}+\\frac 1 {k^2},\\frac 1 {k^3}\\right)$\n\nFor example $H(3) \\approx 6.8345$, rounded to 4 digits after the decimal point.\n\nFind $H(50)$, rounded to 4 digits after the decimal point.", "raw_html": "

Two friends $A$ and $B$ are great fans of Chess. They both enjoy playing the game, but after each game the player who lost the game would like to continue (to get back at the other player) and the player who won would prefer to stop (to finish on a high).

\n\n

So they come up with a plan. After every game, they would toss a (biased) coin with probability $p$ of Heads (and hence probability $1-p$ of Tails). If they get Tails, they will continue with the next game. Otherwise they end the match. Also, after every game the players make a note of who is leading in the match.

\n\n

Let $p_A$ denote the probability of $A$ winning a game and $p_B$ the probability of $B$ winning a game. Accordingly $1-p_A-p_B$ is the probability that a game ends in a draw. Let $\\mathbb{E}_A(p_A,p_B,p)$ denote the expected number of times $A$ was leading in the match.
\n\nFor example, $\\mathbb{E}_A(0.25,0.25,0.5)\\approx 0.585786$ and $\\mathbb{E}_A(0.47,0.48,0.001)\\approx 377.471736$, both rounded to six places after the decimal point.

\n\n

Let $\\displaystyle H(n)=\\sum_{k=3}^n \\mathbb{E}_A\\left(\\frac 1 {\\sqrt{k+3}},\\frac 1 {\\sqrt{k+3}}+\\frac 1 {k^2},\\frac 1 {k^3}\\right)$
\nFor example $H(3) \\approx 6.8345$, rounded to 4 digits after the decimal point.

\n\n

Find $H(50)$, rounded to 4 digits after the decimal point.

", "url": "https://projecteuler.net/problem=661", "answer": "646231.2177"} {"id": 662, "problem": "Alice walks on a lattice grid. She can step from one lattice point $A (a,b)$ to another $B (a+x,b+y)$ providing distance $AB = \\sqrt{x^2+y^2}$ is a Fibonacci number $\\{1,2,3,5,8,13,\\ldots\\}$ and $x\\ge 0,$ $y\\ge 0$.\n\nIn the lattice grid below Alice can step from the blue point to any of the red points.\n\nLet $F(W,H)$ be the number of paths Alice can take from $(0,0)$ to $(W,H)$.\n\nYou are given $F(3,4) = 278$ and $F(10,10) = 215846462$.\n\nFind $F(10\\,000,10\\,000) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

\nAlice walks on a lattice grid. She can step from one lattice point $A (a,b)$ to another $B (a+x,b+y)$ providing distance $AB = \\sqrt{x^2+y^2}$ is a Fibonacci number $\\{1,2,3,5,8,13,\\ldots\\}$ and $x\\ge 0,$ $y\\ge 0$.\n

\n

\n\nIn the lattice grid below Alice can step from the blue point to any of the red points.
\n\n

\n

\"0662_fibonacciwalks.png\"

\n

\nLet $F(W,H)$ be the number of paths Alice can take from $(0,0)$ to $(W,H)$.
\nYou are given $F(3,4) = 278$ and $F(10,10) = 215846462$.\n

\n

\nFind $F(10\\,000,10\\,000) \\bmod 1\\,000\\,000\\,007$.

", "url": "https://projecteuler.net/problem=662", "answer": "860873428"} {"id": 663, "problem": "Let $t_k$ be the tribonacci numbers defined as:\n\n$\\quad t_0 = t_1 = 0$;\n\n$\\quad t_2 = 1$;\n\n$\\quad t_k = t_{k-1} + t_{k-2} + t_{k-3} \\quad \\text{ for } k \\ge 3$.\n\nFor a given integer $n$, let $A_n$ be an array of length $n$ (indexed from $0$ to $n-1$), that is initially filled with zeros.\n\nThe array is changed iteratively by replacing $A_n[(t_{2 i-2} \\bmod n)]$ with $A_n[(t_{2 i-2} \\bmod n)]+2 (t_{2 i-1} \\bmod n)-n+1$ in each step $i$.\n\nAfter each step $i$, define $M_n(i)$ to be $\\displaystyle \\max\\{\\sum_{j=p}^q A_n[j]: 0\\le p\\le q \\lt n\\}$, the maximal sum of any contiguous subarray of $A_n$.\n\nThe first 6 steps for $n=5$ are illustrated below:\n\nInitial state: $\\, A_5=\\{0,0,0,0,0\\}$\n\nStep 1: $\\quad \\Rightarrow A_5=\\{-4,0,0,0,0\\}$, $M_5(1)=0$\n\nStep 2: $\\quad \\Rightarrow A_5=\\{-4, -2, 0, 0, 0\\}$, $M_5(2)=0$\n\nStep 3: $\\quad \\Rightarrow A_5=\\{-4, -2, 4, 0, 0\\}$, $M_5(3)=4$\n\nStep 4: $\\quad \\Rightarrow A_5=\\{-4, -2, 6, 0, 0\\}$, $M_5(4)=6$\n\nStep 5: $\\quad \\Rightarrow A_5=\\{-4, -2, 6, 0, 4\\}$, $M_5(5)=10$\n\nStep 6: $\\quad \\Rightarrow A_5=\\{-4, 2, 6, 0, 4\\}$, $M_5(6)=12$\n\nLet $\\displaystyle S(n,l)=\\sum_{i=1}^l M_n(i)$. Thus $S(5,6)=32$.\n\nYou are given $S(5,100)=2416$, $S(14,100)=3881$ and $S(107,1000)=1618572$.\n\nFind $S(10\\,000\\,003,10\\,200\\,000)-S(10\\,000\\,003,10\\,000\\,000)$.", "raw_html": "

Let $t_k$ be the tribonacci numbers defined as:
\n$\\quad t_0 = t_1 = 0$;
\n$\\quad t_2 = 1$;
\n$\\quad t_k = t_{k-1} + t_{k-2} + t_{k-3} \\quad \\text{ for } k \\ge 3$.

\n\n

For a given integer $n$, let $A_n$ be an array of length $n$ (indexed from $0$ to $n-1$), that is initially filled with zeros.
\nThe array is changed iteratively by replacing $A_n[(t_{2 i-2} \\bmod n)]$ with $A_n[(t_{2 i-2} \\bmod n)]+2 (t_{2 i-1} \\bmod n)-n+1$ in each step $i$.
\nAfter each step $i$, define $M_n(i)$ to be $\\displaystyle \\max\\{\\sum_{j=p}^q A_n[j]: 0\\le p\\le q \\lt n\\}$, the maximal sum of any contiguous subarray of $A_n$.

\n\n

The first 6 steps for $n=5$ are illustrated below:
\nInitial state: $\\, A_5=\\{0,0,0,0,0\\}$
\nStep 1: $\\quad \\Rightarrow A_5=\\{-4,0,0,0,0\\}$, $M_5(1)=0$
\nStep 2: $\\quad \\Rightarrow A_5=\\{-4, -2, 0, 0, 0\\}$, $M_5(2)=0$
\nStep 3: $\\quad \\Rightarrow A_5=\\{-4, -2, 4, 0, 0\\}$, $M_5(3)=4$
\nStep 4: $\\quad \\Rightarrow A_5=\\{-4, -2, 6, 0, 0\\}$, $M_5(4)=6$
\nStep 5: $\\quad \\Rightarrow A_5=\\{-4, -2, 6, 0, 4\\}$, $M_5(5)=10$
\nStep 6: $\\quad \\Rightarrow A_5=\\{-4, 2, 6, 0, 4\\}$, $M_5(6)=12$
\n

\n\n

Let $\\displaystyle S(n,l)=\\sum_{i=1}^l M_n(i)$. Thus $S(5,6)=32$.
\nYou are given $S(5,100)=2416$, $S(14,100)=3881$ and $S(107,1000)=1618572$.

\n\n

Find $S(10\\,000\\,003,10\\,200\\,000)-S(10\\,000\\,003,10\\,000\\,000)$.

", "url": "https://projecteuler.net/problem=663", "answer": "1884138010064752"} {"id": 664, "problem": "Peter is playing a solitaire game on an infinite checkerboard, each square of which can hold an unlimited number of tokens.\n\nEach move of the game consists of the following steps:\n\n- Choose one token $T$ to move. This may be any token on the board, as long as not all of its four adjacent squares are empty.\n\n- Select and discard one token $D$ from a square adjacent to that of $T$.\n\n- Move $T$ to any one of its four adjacent squares (even if that square is already occupied).\n\nThe board is marked with a line called the dividing line. Initially, every square to the left of the dividing line contains a token, and every square to the right of the dividing line is empty:\n\nPeter's goal is to get a token as far as possible to the right in a finite number of moves. However, he quickly finds out that, even with his infinite supply of tokens, he cannot move a token more than four squares beyond the dividing line.\n\nPeter then considers starting configurations with larger supplies of tokens: each square in the $d$th column to the left of the dividing line starts with $d^n$ tokens instead of $1$. This is illustrated below for $n=1$:\n\nLet $F(n)$ be the maximum number of squares Peter can move a token beyond the dividing line. For example, $F(0)=4$.\nYou are also given that $F(1)=6$, $F(2)=9$, $F(3)=13$, $F(11)=58$ and $F(123)=1173$.\n\nFind $F(1234567)$.", "raw_html": "

Peter is playing a solitaire game on an infinite checkerboard, each square of which can hold an unlimited number of tokens.

\n\n

Each move of the game consists of the following steps:

\n
    \n
  1. Choose one token $T$ to move. This may be any token on the board, as long as not all of its four adjacent squares are empty.
  2. \n
  3. Select and discard one token $D$ from a square adjacent to that of $T$.
  4. \n
  5. Move $T$ to any one of its four adjacent squares (even if that square is already occupied).
  6. \n
\n\n
\n\"Allowed\n
\n\n

The board is marked with a line called the dividing line. Initially, every square to the left of the dividing line contains a token, and every square to the right of the dividing line is empty:

\n\n
\n\"Initial\n
\n\n

Peter's goal is to get a token as far as possible to the right in a finite number of moves. However, he quickly finds out that, even with his infinite supply of tokens, he cannot move a token more than four squares beyond the dividing line.

\n\n

Peter then considers starting configurations with larger supplies of tokens: each square in the $d$th column to the left of the dividing line starts with $d^n$ tokens instead of $1$. This is illustrated below for $n=1$:

\n\n
\n\"Initial\n
\n\n

Let $F(n)$ be the maximum number of squares Peter can move a token beyond the dividing line. For example, $F(0)=4$.\nYou are also given that $F(1)=6$, $F(2)=9$, $F(3)=13$, $F(11)=58$ and $F(123)=1173$.

\n

Find $F(1234567)$.

", "url": "https://projecteuler.net/problem=664", "answer": "35295862"} {"id": 665, "problem": "Two players play a game with two piles of stones, alternating turns.\n\nOn each turn, the corresponding player chooses a positive integer $n$ and does one of the following:\n\n- removes $n$ stones from one pile;\n\n- removes $n$ stones from both piles; or\n\n- removes $n$ stones from one pile and $2n$ stones from the other pile.\n\nThe player who removes the last stone wins.\n\nWe denote by $(n,m)$ the position in which the piles have $n$ and $m$ stones remaining. Note that $(n,m)$ is considered to be the same position as $(m,n)$.\n\nThen, for example, if the position is $(2,6)$, the next player may reach the following positions:\n\n$(0,2)$, $(0,4)$, $(0,5)$, $(0,6)$, $(1,2)$, $(1,4)$, $(1,5)$, $(1,6)$, $(2,2)$, $(2,3)$, $(2,4)$, $(2,5)$\n\nA position is a losing position if the player to move next cannot force a win. For example, $(1,3)$, $(2,6)$, $(4,5)$ are the first few losing positions.\n\nLet $f(M)$ be the sum of $n+m$ for all losing positions $(n,m)$ with $n\\le m$ and $n+m \\le M$. For example, $f(10) = 21$, by considering the losing positions $(1,3)$, $(2,6)$, $(4,5)$.\n\nYou are given that $f(100) = 1164$ and $f(1000) = 117002$.\n\nFind $f(10^7)$.", "raw_html": "

Two players play a game with two piles of stones, alternating turns.

\n

On each turn, the corresponding player chooses a positive integer $n$ and does one of the following:

\n
    \n
  • removes $n$ stones from one pile;
  • \n
  • removes $n$ stones from both piles; or
  • \n
  • removes $n$ stones from one pile and $2n$ stones from the other pile.
  • \n
\n

The player who removes the last stone wins.

\n\n

We denote by $(n,m)$ the position in which the piles have $n$ and $m$ stones remaining. Note that $(n,m)$ is considered to be the same position as $(m,n)$.

\n\n

Then, for example, if the position is $(2,6)$, the next player may reach the following positions:
\n$(0,2)$, $(0,4)$, $(0,5)$, $(0,6)$, $(1,2)$, $(1,4)$, $(1,5)$, $(1,6)$, $(2,2)$, $(2,3)$, $(2,4)$, $(2,5)$

\n\n

A position is a losing position if the player to move next cannot force a win. For example, $(1,3)$, $(2,6)$, $(4,5)$ are the first few losing positions.

\n\n

Let $f(M)$ be the sum of $n+m$ for all losing positions $(n,m)$ with $n\\le m$ and $n+m \\le M$. For example, $f(10) = 21$, by considering the losing positions $(1,3)$, $(2,6)$, $(4,5)$.

\n

You are given that $f(100) = 1164$ and $f(1000) = 117002$.

\n\n

Find $f(10^7)$.

", "url": "https://projecteuler.net/problem=665", "answer": "11541685709674"} {"id": 666, "problem": "Members of a species of bacteria occur in two different types: $\\alpha$ and $\\beta$. Individual bacteria are capable of multiplying and mutating between the types according to the following rules:\n\n- Every minute, each individual will simultaneously undergo some kind of transformation.\n\n- Each individual $A$ of type $\\alpha$ will, independently, do one of the following (at random with equal probability):\n\n- clone itself, resulting in a new bacterium of type $\\alpha$ (alongside $A$ who remains)\n\n- split into 3 new bacteria of type $\\beta$ (replacing $A$)\n\n- Each individual $B$ of type $\\beta$ will, independently, do one of the following (at random with equal probability):\n\n- spawn a new bacterium of type $\\alpha$ (alongside $B$ who remains)\n\n- die\n\nIf a population starts with a single bacterium of type $\\alpha$, then it can be shown that there is a 0.07243802 probability that the population will eventually die out, and a 0.92756198 probability that the population will last forever. These probabilities are given rounded to 8 decimal places.\n\nNow consider another species of bacteria, $S_{k,m}$ (where $k$ and $m$ are positive integers), which occurs in $k$ different types $\\alpha_i$ for $0\\le i< k$. The rules governing this species' lifecycle involve the sequence $r_n$ defined by:\n\n- $r_0 = 306$\n\n- $r_{n+1} = r_n^2 \\bmod 10\\,007$\n\nEvery minute, for each $i$, each bacterium $A$ of type $\\alpha_i$ will independently choose an integer $j$ uniformly at random in the range $0\\le j\n
  • Every minute, each individual will simultaneously undergo some kind of transformation.
  • \n
  • Each individual $A$ of type $\\alpha$ will, independently, do one of the following (at random with equal probability):\n
      \n
    • clone itself, resulting in a new bacterium of type $\\alpha$ (alongside $A$ who remains)
    • \n
    • split into 3 new bacteria of type $\\beta$ (replacing $A$)
    • \n
  • \n\n
  • Each individual $B$ of type $\\beta$ will, independently, do one of the following (at random with equal probability):\n
      \n
    • spawn a new bacterium of type $\\alpha$ (alongside $B$ who remains)
    • \n
    • die
    • \n
  • \n\n

    \nIf a population starts with a single bacterium of type $\\alpha$, then it can be shown that there is a 0.07243802 probability that the population will eventually die out, and a 0.92756198 probability that the population will last forever. These probabilities are given rounded to 8 decimal places.\n

    \n

    \nNow consider another species of bacteria, $S_{k,m}$ (where $k$ and $m$ are positive integers), which occurs in $k$ different types $\\alpha_i$ for $0\\le i< k$. The rules governing this species' lifecycle involve the sequence $r_n$ defined by:\n

    \n
      \n
    • $r_0 = 306$
    • \n
    • $r_{n+1} = r_n^2 \\bmod 10\\,007$
    • \n
    \n

    \nEvery minute, for each $i$, each bacterium $A$ of type $\\alpha_i$ will independently choose an integer $j$ uniformly at random in the range $0\\le j<m$. What it then does depends on $q = r_{im+j} \\bmod 5$:

    \n
      \n
    • If $q=0$, $A$ dies.
    • \n
    • If $q=1$, $A$ clones itself, resulting in a new bacterium of type $\\alpha_i$ (alongside $A$ who remains).
    • \n
    • If $q=2$, $A$ mutates, changing into type $\\alpha_{(2i) \\bmod k}$.
    • \n
    • If $q=3$, $A$ splits into 3 new bacteria of type $\\alpha_{(i^2+1) \\bmod k}$ (replacing $A$).
    • \n
    • If $q=4$, $A$ spawns a new bacterium of type $\\alpha_{(i+1) \\bmod k}$ (alongside $A$ who remains).
    • \n
    \n

    \nIn fact, our original species was none other than $S_{2,2}$, with $\\alpha=\\alpha_0$ and $\\beta=\\alpha_1$.\n

    \n

    \nLet $P_{k,m}$ be the probability that a population of species $S_{k,m}$, starting with a single bacterium of type $\\alpha_0$, will eventually die out. So $P_{2,2} = 0.07243802$. You are also given that $P_{4,3} = 0.18554021$ and $P_{10,5} = 0.53466253$, all rounded to 8 decimal places.\n

    \n

    \nFind $P_{500,10}$, and give your answer rounded to 8 decimal places.\n

    ", "url": "https://projecteuler.net/problem=666", "answer": "0.48023168"} {"id": 667, "problem": "After buying a Gerver Sofa from the Moving Sofa Company, Jack wants to buy a matching cocktail table from the same company. Most important for him is that the table can be pushed through his L-shaped corridor into the living room without having to be lifted from its table legs.\n\nUnfortunately, the simple square model offered to him is too small for him, so he asks for a bigger model.\n\nHe is offered the new pentagonal model illustrated below:\n\nNote, while the shape and size can be ordered individually, due to the production process, all edges of the pentagonal table have to have the same length.\n\nGiven optimal form and size, what is the biggest pentagonal cocktail table (in terms of area) that Jack can buy that still fits through his unit wide L-shaped corridor?\n\nGive your answer rounded to 10 digits after the decimal point (if Jack had choosen the square model instead the answer would have been 1.0000000000).", "raw_html": "

    \nAfter buying a Gerver Sofa from the Moving Sofa Company, Jack wants to buy a matching cocktail table from the same company. Most important for him is that the table can be pushed through his L-shaped corridor into the living room without having to be lifted from its table legs.
    \nUnfortunately, the simple square model offered to him is too small for him, so he asks for a bigger model.
    \nHe is offered the new pentagonal model illustrated below:

    \n\"p667.png\"\n

    \nNote, while the shape and size can be ordered individually, due to the production process, all edges of the pentagonal table have to have the same length.

    \n

    \nGiven optimal form and size, what is the biggest pentagonal cocktail table (in terms of area) that Jack can buy that still fits through his unit wide L-shaped corridor?

    \n

    \nGive your answer rounded to 10 digits after the decimal point (if Jack had choosen the square model instead the answer would have been 1.0000000000).

    ", "url": "https://projecteuler.net/problem=667", "answer": "1.5276527928"} {"id": 668, "problem": "A positive integer is called square root smooth if all of its prime factors are strictly less than its square root.\n\nIncluding the number $1$, there are $29$ square root smooth numbers not exceeding $100$.\n\nHow many square root smooth numbers are there not exceeding $10\\,000\\,000\\,000$?", "raw_html": "

    \nA positive integer is called square root smooth if all of its prime factors are strictly less than its square root.
    \nIncluding the number $1$, there are $29$ square root smooth numbers not exceeding $100$.\n

    \n

    \nHow many square root smooth numbers are there not exceeding $10\\,000\\,000\\,000$?

    ", "url": "https://projecteuler.net/problem=668", "answer": "2811077773"} {"id": 669, "problem": "The Knights of the Order of Fibonacci are preparing a grand feast for their king. There are $n$ knights, and each knight is assigned a distinct number from $1$ to $n$.\n\nWhen the knights sit down at the roundtable for their feast, they follow a peculiar seating rule: two knights can only sit next to each other if their respective numbers sum to a Fibonacci number.\n\nWhen the $n$ knights all try to sit down around a circular table with $n$ chairs, they are unable to find a suitable seating arrangement for any $n>2$ despite their best efforts. Just when they are about to give up, they remember that the king will sit on his throne at the table as well.\n\nSuppose there are $n=7$ knights and $7$ chairs at the roundtable, in addition to the king’s throne. After some trial and error, they come up with the following seating arrangement ($K$ represents the king):\n\nNotice that the sums $4+1$, $1+7$, $7+6$, $6+2$, $2+3$, and $3+5$ are all Fibonacci numbers, as required. It should also be mentioned that the king always prefers an arrangement where the knight to the his left has a smaller number than the knight to his right. With this additional rule, the above arrangement is unique for $n=7$, and the knight sitting in the 3rd chair from the king’s left is knight number $7$.\n\nLater, several new knights are appointed to the Order, giving $34$ knights and chairs in addition to the king's throne. The knights eventually determine that there is a unique seating arrangement for $n=34$ satisfying the above rules, and this time knight number $30$ is sitting in the 3rd chair from the king's left.\n\nNow suppose there are $n=99\\,194\\,853\\,094\\,755\\,497$ knights and the same number of chairs at the roundtable (not including the king’s throne). After great trials and tribulations, they are finally able to find the unique seating arrangement for this value of $n$ that satisfies the above rules.\n\nFind the number of the knight sitting in the $10\\,000\\,000\\,000\\,000\\,000$th chair from the king’s left.", "raw_html": "

    The Knights of the Order of Fibonacci are preparing a grand feast for their king. There are $n$ knights, and each knight is assigned a distinct number from $1$ to $n$.

    \n\n

    When the knights sit down at the roundtable for their feast, they follow a peculiar seating rule: two knights can only sit next to each other if their respective numbers sum to a Fibonacci number.

    \n\n

    When the $n$ knights all try to sit down around a circular table with $n$ chairs, they are unable to find a suitable seating arrangement for any $n>2$ despite their best efforts. Just when they are about to give up, they remember that the king will sit on his throne at the table as well.

    \n\n

    Suppose there are $n=7$ knights and $7$ chairs at the roundtable, in addition to the king’s throne. After some trial and error, they come up with the following seating arrangement ($K$ represents the king):

    \n\n
    \n\"Roundtable\"\n
    \n\n

    Notice that the sums $4+1$, $1+7$, $7+6$, $6+2$, $2+3$, and $3+5$ are all Fibonacci numbers, as required. It should also be mentioned that the king always prefers an arrangement where the knight to the his left has a smaller number than the knight to his right. With this additional rule, the above arrangement is unique for $n=7$, and the knight sitting in the 3rd chair from the king’s left is knight number $7$.

    \n\n

    Later, several new knights are appointed to the Order, giving $34$ knights and chairs in addition to the king's throne. The knights eventually determine that there is a unique seating arrangement for $n=34$ satisfying the above rules, and this time knight number $30$ is sitting in the 3rd chair from the king's left.

    \n\n

    Now suppose there are $n=99\\,194\\,853\\,094\\,755\\,497$ knights and the same number of chairs at the roundtable (not including the king’s throne). After great trials and tribulations, they are finally able to find the unique seating arrangement for this value of $n$ that satisfies the above rules.

    \n\n

    Find the number of the knight sitting in the $10\\,000\\,000\\,000\\,000\\,000$th chair from the king’s left.

    ", "url": "https://projecteuler.net/problem=669", "answer": "56342087360542122"} {"id": 670, "problem": "A certain type of tile comes in three different sizes - $1 \\times 1$, $1 \\times 2$, and $1 \\times 3$ - and in four different colours: blue, green, red and yellow. There is an unlimited number of tiles available in each combination of size and colour.\n\nThese are used to tile a $2\\times n$ rectangle, where $n$ is a positive integer, subject to the following conditions:\n\n- The rectangle must be fully covered by non-overlapping tiles.\n\n- It is not permitted for four tiles to have their corners meeting at a single point.\n\n- Adjacent tiles must be of different colours.\n\nFor example, the following is an acceptable tiling of a $2\\times 12$ rectangle:\n\nbut the following is not an acceptable tiling, because it violates the \"no four corners meeting at a point\" rule:\n\nLet $F(n)$ be the number of ways the $2\\times n$ rectangle can be tiled subject to these rules. Where reflecting horizontally or vertically would give a different tiling, these tilings are to be counted separately.\n\nFor example, $F(2) = 120$, $F(5) = 45876$, and $F(100)\\equiv 53275818 \\pmod{1\\,000\\,004\\,321}$.\n\nFind $F(10^{16}) \\bmod 1\\,000\\,004\\,321$.", "raw_html": "

    A certain type of tile comes in three different sizes - $1 \\times 1$, $1 \\times 2$, and $1 \\times 3$ - and in four different colours: blue, green, red and yellow. There is an unlimited number of tiles available in each combination of size and colour.

    \n\n

    These are used to tile a $2\\times n$ rectangle, where $n$ is a positive integer, subject to the following conditions:

    \n
      \n
    • The rectangle must be fully covered by non-overlapping tiles.
    • \n
    • It is not permitted for four tiles to have their corners meeting at a single point.
    • \n
    • Adjacent tiles must be of different colours.
    • \n
    \n\n

    For example, the following is an acceptable tiling of a $2\\times 12$ rectangle:

    \n\n
    \n\"Acceptable\n
    \n\n

    but the following is not an acceptable tiling, because it violates the \"no four corners meeting at a point\" rule:

    \n\n
    \n\"Unacceptable\n
    \n\n

    Let $F(n)$ be the number of ways the $2\\times n$ rectangle can be tiled subject to these rules. Where reflecting horizontally or vertically would give a different tiling, these tilings are to be counted separately.

    \n\n

    For example, $F(2) = 120$, $F(5) = 45876$, and $F(100)\\equiv 53275818 \\pmod{1\\,000\\,004\\,321}$.

    \n

    Find $F(10^{16}) \\bmod 1\\,000\\,004\\,321$.

    ", "url": "https://projecteuler.net/problem=670", "answer": "551055065"} {"id": 671, "problem": "A certain type of flexible tile comes in three different sizes - $1 \\times 1$, $1 \\times 2$, and $1 \\times 3$ - and in $k$ different colours. There is an unlimited number of tiles available in each combination of size and colour.\n\nThese are used to tile a closed loop of width $2$ and length (circumference) $n$, where $n$ is a positive integer, subject to the following conditions:\n\n- The loop must be fully covered by non-overlapping tiles.\n\n- It is not permitted for four tiles to have their corners meeting at a single point.\n\n- Adjacent tiles must be of different colours.\n\nFor example, the following is an acceptable tiling of a $2\\times 23$ loop with $k=4$ (blue, green, red and yellow):\n\nbut the following is not an acceptable tiling, because it violates the \"no four corners meeting at a point\" rule:\n\nLet $F_k(n)$ be the number of ways the $2\\times n$ loop can be tiled subject to these rules when $k$ colours are available. (Not all $k$ colours have to be used.) Where reflecting horizontally or vertically would give a different tiling, these tilings are to be counted separately.\n\nFor example, $F_4(3) = 104$, $F_5(7) = 3327300$, and $F_6(101)\\equiv 75309980 \\pmod{1\\,000\\,004\\,321}$.\n\nFind $F_{10}(10\\,004\\,003\\,002\\,001) \\bmod 1\\,000\\,004\\,321$.", "raw_html": "

    A certain type of flexible tile comes in three different sizes - $1 \\times 1$, $1 \\times 2$, and $1 \\times 3$ - and in $k$ different colours. There is an unlimited number of tiles available in each combination of size and colour.

    \n\n

    These are used to tile a closed loop of width $2$ and length (circumference) $n$, where $n$ is a positive integer, subject to the following conditions:

    \n
      \n
    • The loop must be fully covered by non-overlapping tiles.
    • \n
    • It is not permitted for four tiles to have their corners meeting at a single point.
    • \n
    • Adjacent tiles must be of different colours.
    • \n
    \n\n

    For example, the following is an acceptable tiling of a $2\\times 23$ loop with $k=4$ (blue, green, red and yellow):

    \n\n
    \n\"Acceptable\n
    \n\n

    but the following is not an acceptable tiling, because it violates the \"no four corners meeting at a point\" rule:

    \n\n
    \n\"Unacceptable\n
    \n\n

    Let $F_k(n)$ be the number of ways the $2\\times n$ loop can be tiled subject to these rules when $k$ colours are available. (Not all $k$ colours have to be used.) Where reflecting horizontally or vertically would give a different tiling, these tilings are to be counted separately.

    \n\n

    For example, $F_4(3) = 104$, $F_5(7) = 3327300$, and $F_6(101)\\equiv 75309980 \\pmod{1\\,000\\,004\\,321}$.

    \n

    Find $F_{10}(10\\,004\\,003\\,002\\,001) \\bmod 1\\,000\\,004\\,321$.

    ", "url": "https://projecteuler.net/problem=671", "answer": "946106780"} {"id": 672, "problem": "Consider the following process that can be applied recursively to any positive integer $n$:\n\n- if $n = 1$ do nothing and the process stops,\n\n- if $n$ is divisible by $7$ divide it by $7$,\n\n- otherwise add $1$.\n\nDefine $g(n)$ to be the number of $1$'s that must be added before the process ends. For example:\n\n$125\\xrightarrow{\\scriptsize{+1}} 126\\xrightarrow{\\scriptsize{\\div 7}} 18\\xrightarrow{\\scriptsize{+1}} 19\\xrightarrow{\\scriptsize{+1}} 20\\xrightarrow{\\scriptsize{+1}} 21\\xrightarrow{\\scriptsize{\\div 7}} 3\\xrightarrow{\\scriptsize{+1}} 4\\xrightarrow{\\scriptsize{+1}} 5\\xrightarrow{\\scriptsize{+1}} 6\\xrightarrow{\\scriptsize{+1}} 7\\xrightarrow{\\scriptsize{\\div 7}} 1$.\nEight $1$'s are added so $g(125) = 8$. Similarly $g(1000) = 9$ and $g(10000) = 21$.\n\nDefine $S(N) = \\sum_{n=1}^N g(n)$ and $H(K) = S\\left(\\frac{7^K-1}{11}\\right)$. You are given $H(10) = 690409338$.\n\nFind $H(10^9)$ modulo $1\\,117\\,117\\,717$.", "raw_html": "

    Consider the following process that can be applied recursively to any positive integer $n$:

    \n
      \n
    • if $n = 1$ do nothing and the process stops,
    • \n
    • if $n$ is divisible by $7$ divide it by $7$,
    • \n
    • otherwise add $1$.
    • \n
    \n

    Define $g(n)$ to be the number of $1$'s that must be added before the process ends. For example:

    \n
    $125\\xrightarrow{\\scriptsize{+1}} 126\\xrightarrow{\\scriptsize{\\div 7}} 18\\xrightarrow{\\scriptsize{+1}} 19\\xrightarrow{\\scriptsize{+1}} 20\\xrightarrow{\\scriptsize{+1}} 21\\xrightarrow{\\scriptsize{\\div 7}} 3\\xrightarrow{\\scriptsize{+1}} 4\\xrightarrow{\\scriptsize{+1}} 5\\xrightarrow{\\scriptsize{+1}} 6\\xrightarrow{\\scriptsize{+1}} 7\\xrightarrow{\\scriptsize{\\div 7}} 1$.
    \n

    Eight $1$'s are added so $g(125) = 8$. Similarly $g(1000) = 9$ and $g(10000) = 21$.

    \n

    Define $S(N) = \\sum_{n=1}^N g(n)$ and $H(K) = S\\left(\\frac{7^K-1}{11}\\right)$. You are given $H(10) = 690409338$.

    \n

    Find $H(10^9)$ modulo $1\\,117\\,117\\,717$.

    ", "url": "https://projecteuler.net/problem=672", "answer": "91627537"} {"id": 673, "problem": "At Euler University, each of the $n$ students (numbered from 1 to $n$) occupies a bed in the dormitory and uses a desk in the classroom.\n\nSome of the beds are in private rooms which a student occupies alone, while the others are in double rooms occupied by two students as roommates. Similarly, each desk is either a single desk for the sole use of one student, or a twin desk at which two students sit together as desk partners.\n\nWe represent the bed and desk sharing arrangements each by a list of pairs of student numbers. For example, with $n=4$, if $(2,3)$ represents the bed pairing and $(1,3)(2,4)$ the desk pairing, then students 2 and 3 are roommates while 1 and 4 have single rooms, and students 1 and 3 are desk partners, as are students 2 and 4.\n\nThe new chancellor of the university decides to change the organisation of beds and desks: a permutation $\\sigma$ of the numbers $1,2,\\ldots,n$ will be chosen, and each student $k$ will be given both the bed and the desk formerly occupied by student number $\\sigma(k)$.\n\nThe students agree to this change, under the conditions that:\n\n- Any two students currently sharing a room will still be roommates.\n\n- Any two students currently sharing a desk will still be desk partners.\n\nIn the example above, there are only two ways to satisfy these conditions: either take no action ($\\sigma$ is the identity permutation), or reverse the order of the students.\n\nWith $n=6$, for the bed pairing $(1,2)(3,4)(5,6)$ and the desk pairing $(3,6)(4,5)$, there are 8 permutations which satisfy the conditions. One example is the mapping $(1, 2, 3, 4, 5, 6) \\mapsto (1, 2, 5, 6, 3, 4)$.\n\nWith $n=36$, if we have bed pairing:\n\n$(2,13)(4,30)(5,27)(6,16)(10,18)(12,35)(14,19)(15,20)(17,26)(21,32)(22,33)(24,34)(25,28)$\n\nand desk pairing\n\n$(1,35)(2,22)(3,36)(4,28)(5,25)(7,18)(9,23)(13,19)(14,33)(15,34)(20,24)(26,29)(27,30)$\n\nthen among the $36!$ possible permutations (including the identity permutation), 663552 of them satisfy the conditions stipulated by the students.\n\nThe downloadable text files beds.txt and desks.txt contain pairings for $n=500$. Each pairing is written on its own line, with the student numbers of the two roommates (or desk partners) separated with a comma. For example, the desk pairing in the $n=4$ example above would be represented in this file format as:\n\n1,3\n2,4\n\nWith these pairings, find the number of permutations that satisfy the students' conditions. Give your answer modulo $999\\,999\\,937$.", "raw_html": "

    At Euler University, each of the $n$ students (numbered from 1 to $n$) occupies a bed in the dormitory and uses a desk in the classroom.

    \n\n

    Some of the beds are in private rooms which a student occupies alone, while the others are in double rooms occupied by two students as roommates. Similarly, each desk is either a single desk for the sole use of one student, or a twin desk at which two students sit together as desk partners.

    \n\n

    We represent the bed and desk sharing arrangements each by a list of pairs of student numbers. For example, with $n=4$, if $(2,3)$ represents the bed pairing and $(1,3)(2,4)$ the desk pairing, then students 2 and 3 are roommates while 1 and 4 have single rooms, and students 1 and 3 are desk partners, as are students 2 and 4.

    \n\n

    The new chancellor of the university decides to change the organisation of beds and desks: a permutation $\\sigma$ of the numbers $1,2,\\ldots,n$ will be chosen, and each student $k$ will be given both the bed and the desk formerly occupied by student number $\\sigma(k)$.

    \n\n

    The students agree to this change, under the conditions that:

    \n
      \n
    1. Any two students currently sharing a room will still be roommates.
    2. \n
    3. Any two students currently sharing a desk will still be desk partners.
    4. \n
    \n\n

    In the example above, there are only two ways to satisfy these conditions: either take no action ($\\sigma$ is the identity permutation), or reverse the order of the students.

    \n\n

    With $n=6$, for the bed pairing $(1,2)(3,4)(5,6)$ and the desk pairing $(3,6)(4,5)$, there are 8 permutations which satisfy the conditions. One example is the mapping $(1, 2, 3, 4, 5, 6) \\mapsto (1, 2, 5, 6, 3, 4)$.

    \n\n

    With $n=36$, if we have bed pairing:
    \n$(2,13)(4,30)(5,27)(6,16)(10,18)(12,35)(14,19)(15,20)(17,26)(21,32)(22,33)(24,34)(25,28)$
    \nand desk pairing
    \n$(1,35)(2,22)(3,36)(4,28)(5,25)(7,18)(9,23)(13,19)(14,33)(15,34)(20,24)(26,29)(27,30)$
    \nthen among the $36!$ possible permutations (including the identity permutation), 663552 of them satisfy the conditions stipulated by the students.

    \n\n

    The downloadable text files beds.txt and desks.txt contain pairings for $n=500$. Each pairing is written on its own line, with the student numbers of the two roommates (or desk partners) separated with a comma. For example, the desk pairing in the $n=4$ example above would be represented in this file format as:

    \n
    \n1,3\n2,4\n
    \n

    With these pairings, find the number of permutations that satisfy the students' conditions. Give your answer modulo $999\\,999\\,937$.

    ", "url": "https://projecteuler.net/problem=673", "answer": "700325380"} {"id": 674, "problem": "We define the $\\mathcal{I}$ operator as the function\n$$\\mathcal{I}(x,y) = (1+x+y)^2+y-x$$\nand $\\mathcal{I}$-expressions as arithmetic expressions built only from variable names and applications of $\\mathcal{I}$. A variable name may consist of one or more letters. For example, the three expressions $x$, $\\mathcal{I}(x,y)$, and $\\mathcal{I}(\\mathcal{I}(x,ab),x)$ are all $\\mathcal{I}$-expressions.\n\nFor two $\\mathcal{I}$-expressions $e_1$ and $e_2$ such that the equation $e_1=e_2$ has a solution in non-negative integers, we define the least simultaneous value of $e_1$ and $e_2$ to be the minimum value taken by $e_1$ and $e_2$ on such a solution. If the equation $e_1=e_2$ has no solution in non-negative integers, we define the least simultaneous value of $e_1$ and $e_2$ to be $0$. For example, consider the following three $\\mathcal{I}$-expressions:\n$$\\begin{array}{l}A = \\mathcal{I}(x,\\mathcal{I}(z,t))\\\\\nB = \\mathcal{I}(\\mathcal{I}(y,z),y)\\\\\nC = \\mathcal{I}(\\mathcal{I}(x,z),y)\\end{array}$$\nThe least simultaneous value of $A$ and $B$ is $23$, attained for $x=3,y=1,z=t=0$. On the other hand, $A=C$ has no solutions in non-negative integers, so the least simultaneous value of $A$ and $C$ is $0$. The total sum of least simultaneous pairs made of $\\mathcal{I}$-expressions from $\\{A,B,C\\}$ is $26$.\n\nFind the sum of least simultaneous values of all $\\mathcal{I}$-expressions pairs made of distinct expressions from file I-expressions.txt (pairs $(e_1,e_2)$ and $(e_2,e_1)$ are considered to be identical). Give the last nine digits of the result as the answer.", "raw_html": "

    We define the $\\mathcal{I}$ operator as the function\n$$\\mathcal{I}(x,y) = (1+x+y)^2+y-x$$\nand $\\mathcal{I}$-expressions as arithmetic expressions built only from variable names and applications of $\\mathcal{I}$. A variable name may consist of one or more letters. For example, the three expressions $x$, $\\mathcal{I}(x,y)$, and $\\mathcal{I}(\\mathcal{I}(x,ab),x)$ are all $\\mathcal{I}$-expressions.

    \n\n

    For two $\\mathcal{I}$-expressions $e_1$ and $e_2$ such that the equation $e_1=e_2$ has a solution in non-negative integers, we define the least simultaneous value of $e_1$ and $e_2$ to be the minimum value taken by $e_1$ and $e_2$ on such a solution. If the equation $e_1=e_2$ has no solution in non-negative integers, we define the least simultaneous value of $e_1$ and $e_2$ to be $0$. For example, consider the following three $\\mathcal{I}$-expressions:\n$$\\begin{array}{l}A = \\mathcal{I}(x,\\mathcal{I}(z,t))\\\\\nB = \\mathcal{I}(\\mathcal{I}(y,z),y)\\\\\nC = \\mathcal{I}(\\mathcal{I}(x,z),y)\\end{array}$$\nThe least simultaneous value of $A$ and $B$ is $23$, attained for $x=3,y=1,z=t=0$. On the other hand, $A=C$ has no solutions in non-negative integers, so the least simultaneous value of $A$ and $C$ is $0$. The total sum of least simultaneous pairs made of $\\mathcal{I}$-expressions from $\\{A,B,C\\}$ is $26$.

    \n\n

    Find the sum of least simultaneous values of all $\\mathcal{I}$-expressions pairs made of distinct expressions from file I-expressions.txt (pairs $(e_1,e_2)$ and $(e_2,e_1)$ are considered to be identical). Give the last nine digits of the result as the answer.

    ", "url": "https://projecteuler.net/problem=674", "answer": "416678753"} {"id": 675, "problem": "Let $\\omega(n)$ denote the number of distinct prime divisors of a positive integer $n$.\n\nSo $\\omega(1) = 0$ and $\\omega(360) = \\omega(2^{3} \\times 3^{2} \\times 5) = 3$.\n\nLet $S(n)$ be $ \\sum_{d \\mid n} 2^{\\omega(d)} $.\n\nE.g. $S(6) = 2^{\\omega(1)}+2^{\\omega(2)}+2^{\\omega(3)}+2^{\\omega(6)} = 2^0+2^1+2^1+2^2 = 9$.\n\nLet $F(n)=\\sum_{i=2}^n S(i!)$.\n$F(10)=4821.$\n\nFind $F(10\\,000\\,000)$. Give your answer modulo $1\\,000\\,000\\,087$.", "raw_html": "

    \nLet $\\omega(n)$ denote the number of distinct prime divisors of a positive integer $n$.
    \nSo $\\omega(1) = 0$ and $\\omega(360) = \\omega(2^{3} \\times 3^{2} \\times 5) = 3$.\n

    \n

    \nLet $S(n)$ be $ \\sum_{d \\mid n} 2^{\\omega(d)} $.\n
    \nE.g. $S(6) = 2^{\\omega(1)}+2^{\\omega(2)}+2^{\\omega(3)}+2^{\\omega(6)} = 2^0+2^1+2^1+2^2 = 9$.\n

    \n

    \nLet $F(n)=\\sum_{i=2}^n S(i!)$.\n$F(10)=4821.$\n

    \n

    \nFind $F(10\\,000\\,000)$. Give your answer modulo $1\\,000\\,000\\,087$.\n

    ", "url": "https://projecteuler.net/problem=675", "answer": "416146418"} {"id": 676, "problem": "Let $d(i,b)$ be the digit sum of the number $i$ in base $b$. For example $d(9,2)=2$, since $9=1001_2$.\nWhen using different bases, the respective digit sums most of the time deviate from each other, for example $d(9,4)=3 \\ne d(9,2)$.\n\nHowever, for some numbers $i$ there will be a match, like $d(17,4)=d(17,2)=2$.\nLet $ M(n,b_1,b_2)$ be the sum of all natural numbers $i \\le n$ for which $d(i,b_1)=d(i,b_2)$.\nFor example, $M(10,8,2)=18$, $M(100,8,2)=292$ and $M(10^6,8,2)=19173952$.\n\nFind $\\displaystyle \\sum_{k=3}^6 \\sum_{l=1}^{k-2}M(10^{16},2^k,2^l)$, giving the last $16$ digits as the answer.", "raw_html": "

    \nLet $d(i,b)$ be the digit sum of the number $i$ in base $b$. For example $d(9,2)=2$, since $9=1001_2$.\nWhen using different bases, the respective digit sums most of the time deviate from each other, for example $d(9,4)=3 \\ne d(9,2)$.\n

    \n\n

    \nHowever, for some numbers $i$ there will be a match, like $d(17,4)=d(17,2)=2$.\nLet $ M(n,b_1,b_2)$ be the sum of all natural numbers $i \\le n$ for which $d(i,b_1)=d(i,b_2)$.\nFor example, $M(10,8,2)=18$, $M(100,8,2)=292$ and $M(10^6,8,2)=19173952$.\n

    \n\n

    \nFind $\\displaystyle \\sum_{k=3}^6 \\sum_{l=1}^{k-2}M(10^{16},2^k,2^l)$, giving the last $16$ digits as the answer.\n

    ", "url": "https://projecteuler.net/problem=676", "answer": "3562668074339584"} {"id": 677, "problem": "Let $g(n)$ be the number of undirected graphs with $n$ nodes satisfying the following properties:\n\n- The graph is connected and has no cycles or multiple edges.\n\n- Each node is either red, blue, or yellow.\n\n- A red node may have no more than 4 edges connected to it.\n\n- A blue or yellow node may have no more than 3 edges connected to it.\n\n- An edge may not directly connect a yellow node to a yellow node.\n\nFor example, $g(2)=5$, $g(3)=15$, and $g(4) = 57$.\n\nYou are also given that $g(10) = 710249$ and $g(100) \\equiv 919747298 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $g(10\\,000) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

    Let $g(n)$ be the number of undirected graphs with $n$ nodes satisfying the following properties:

    \n
      \n
    • The graph is connected and has no cycles or multiple edges.
    • \n
    • Each node is either red, blue, or yellow.
    • \n
    • A red node may have no more than 4 edges connected to it.
    • \n
    • A blue or yellow node may have no more than 3 edges connected to it.
    • \n
    • An edge may not directly connect a yellow node to a yellow node.
    • \n
    \n\n

    For example, $g(2)=5$, $g(3)=15$, and $g(4) = 57$.
    \nYou are also given that $g(10) = 710249$ and $g(100) \\equiv 919747298 \\pmod{1\\,000\\,000\\,007}$.

    \n\n

    Find $g(10\\,000) \\bmod 1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=677", "answer": "984183023"} {"id": 678, "problem": "If a triple of positive integers $(a, b, c)$ satisfies $a^2+b^2=c^2$, it is called a Pythagorean triple. No triple $(a, b, c)$ satisfies $a^e+b^e=c^e$ when $e \\ge 3$ (Fermat's Last Theorem). However, if the exponents of the left-hand side and right-hand side differ, this is not true. For example, $3^3+6^3=3^5$.\n\nLet $a, b, c, e, f$ be all positive integers, $0 \\lt a \\lt b$, $e \\ge 2$, $f \\ge 3$ and $c^f \\le N$. Let $F(N)$ be the number of $(a, b, c, e, f)$ such that $a^e+b^e=c^f$. You are given $F(10^3) = 7$, $F(10^5) = 53$ and $F(10^7) = 287$.\n\nFind $F(10^{18})$.", "raw_html": "

    If a triple of positive integers $(a, b, c)$ satisfies $a^2+b^2=c^2$, it is called a Pythagorean triple. No triple $(a, b, c)$ satisfies $a^e+b^e=c^e$ when $e \\ge 3$ (Fermat's Last Theorem). However, if the exponents of the left-hand side and right-hand side differ, this is not true. For example, $3^3+6^3=3^5$.\n

    \n

    \nLet $a, b, c, e, f$ be all positive integers, $0 \\lt a \\lt b$, $e \\ge 2$, $f \\ge 3$ and $c^f \\le N$. Let $F(N)$ be the number of $(a, b, c, e, f)$ such that $a^e+b^e=c^f$. You are given $F(10^3) = 7$, $F(10^5) = 53$ and $F(10^7) = 287$.\n

    \n

    \nFind $F(10^{18})$.\n

    ", "url": "https://projecteuler.net/problem=678", "answer": "1986065"} {"id": 679, "problem": "Let $S$ be the set consisting of the four letters $\\{\\texttt{`A'},\\texttt{`E'},\\texttt{`F'},\\texttt{`R'}\\}$.\n\nFor $n\\ge 0$, let $S^*(n)$ denote the set of words of length $n$ consisting of letters belonging to $S$.\n\nWe designate the words $\\texttt{FREE}, \\texttt{FARE}, \\texttt{AREA}, \\texttt{REEF}$ as keywords.\n\nLet $f(n)$ be the number of words in $S^*(n)$ that contains all four keywords exactly once.\n\nThis first happens for $n=9$, and indeed there is a unique 9 lettered word that contain each of the keywords once: $\\texttt{FREEFAREA}$\n\nSo, $f(9)=1$.\n\nYou are also given that $f(15)=72863$.\n\nFind $f(30)$.", "raw_html": "

    Let $S$ be the set consisting of the four letters $\\{\\texttt{`A'},\\texttt{`E'},\\texttt{`F'},\\texttt{`R'}\\}$.
    \nFor $n\\ge 0$, let $S^*(n)$ denote the set of words of length $n$ consisting of letters belonging to $S$.
    \nWe designate the words $\\texttt{FREE}, \\texttt{FARE}, \\texttt{AREA}, \\texttt{REEF}$ as keywords.

    \n\n

    Let $f(n)$ be the number of words in $S^*(n)$ that contains all four keywords exactly once.

    \n\n

    This first happens for $n=9$, and indeed there is a unique 9 lettered word that contain each of the keywords once: $\\texttt{FREEFAREA}$
    \nSo, $f(9)=1$.

    \n\n

    You are also given that $f(15)=72863$.

    \n\n

    Find $f(30)$.

    ", "url": "https://projecteuler.net/problem=679", "answer": "644997092988678"} {"id": 680, "problem": "Let $N$ and $K$ be two positive integers.\n\n$F_n$ is the $n$-th Fibonacci number: $F_1 = F_2 = 1$, $F_n = F_{n - 1} + F_{n - 2}$ for all $n \\geq 3$.\n\nLet $s_n = F_{2n - 1} \\bmod N$ and let $t_n = F_{2n} \\bmod N$.\n\nStart with an array of integers $A = (A[0], \\cdots, A[N - 1])$ where initially every $A\\text{[}i]$ is equal to $i$.\nNow perform $K$ successive operations on $A$, where the $j$-th operation consists of reversing the order of those elements in $A$ with indices between $s_j$ and $t_j$ (both ends inclusive).\n\nDefine $R(N,K)$ to be $\\sum_{i = 0}^{N - 1}i \\times A\\text {[}i]$ after $K$ operations.\n\nFor example, $R(5, 4) = 27$, as can be seen from the following procedure:\n\nInitial position: $(0, 1, 2, 3, 4)$\n\nStep 1 - Reverse $A[1]$ to $A[1]$: $(0, 1, 2, 3, 4)$\n\nStep 2 - Reverse $A[2]$ to $A[3]$: $(0, 1, 3, 2, 4)$\n\nStep 3 - Reverse $A[0]$ to $A[3]$: $(2, 3, 1, 0, 4)$\n\nStep 4 - Reverse $A[3]$ to $A[1]$: $(2, 0, 1, 3, 4)$\n\n$R(5, 4) = 0 \\times 2 + 1 \\times 0 + 2 \\times 1 + 3 \\times 3 + 4 \\times 4 = 27$\n\nAlso, $R(10^2, 10^2) = 246597$ and $R(10^4, 10^4) = 249275481640$.\n\nFind $R(10^{18}, 10^6)$ giving your answer modulo $10^9$.", "raw_html": "

    Let $N$ and $K$ be two positive integers.

    \n\n

    $F_n$ is the $n$-th Fibonacci number: $F_1 = F_2 = 1$, $F_n = F_{n - 1} + F_{n - 2}$ for all $n \\geq 3$.
    \nLet $s_n = F_{2n - 1} \\bmod N$ and let $t_n = F_{2n} \\bmod N$.

    \n\n

    Start with an array of integers $A = (A[0], \\cdots, A[N - 1])$ where initially every $A\\text{[}i]$ is equal to $i$.\nNow perform $K$ successive operations on $A$, where the $j$-th operation consists of reversing the order of those elements in $A$ with indices between $s_j$ and $t_j$ (both ends inclusive).

    \n\n

    Define $R(N,K)$ to be $\\sum_{i = 0}^{N - 1}i \\times A\\text {[}i]$ after $K$ operations.

    \n\n

    For example, $R(5, 4) = 27$, as can be seen from the following procedure:

    \n\n

    Initial position: $(0, 1, 2, 3, 4)$
    \nStep 1 - Reverse $A[1]$ to $A[1]$: $(0, 1, 2, 3, 4)$
    \nStep 2 - Reverse $A[2]$ to $A[3]$: $(0, 1, 3, 2, 4)$
    \nStep 3 - Reverse $A[0]$ to $A[3]$: $(2, 3, 1, 0, 4)$
    \nStep 4 - Reverse $A[3]$ to $A[1]$: $(2, 0, 1, 3, 4)$
    \n$R(5, 4) = 0 \\times 2 + 1 \\times 0 + 2 \\times 1 + 3 \\times 3 + 4 \\times 4 = 27$

    \n\n

    Also, $R(10^2, 10^2) = 246597$ and $R(10^4, 10^4) = 249275481640$.

    \n\n

    Find $R(10^{18}, 10^6)$ giving your answer modulo $10^9$.

    ", "url": "https://projecteuler.net/problem=680", "answer": "563917241"} {"id": 681, "problem": "Given positive integers $a \\le b \\le c \\le d$, it may be possible to form quadrilaterals with edge lengths $a,b,c,d$ (in any order). When this is the case, let $M(a,b,c,d)$ denote the maximal area of such a quadrilateral.\nFor example, $M(2,2,3,3)=6$, attained e.g. by a $2\\times 3$ rectangle.\n\nLet $SP(n)$ be the sum of $a+b+c+d$ over all choices $a \\le b \\le c \\le d$ for which $M(a,b,c,d)$ is a positive integer not exceeding $n$.\n\n$SP(10)=186$ and $SP(100)=23238$.\n\nFind $SP(1\\,000\\,000)$.", "raw_html": "

    \nGiven positive integers $a \\le b \\le c \\le d$, it may be possible to form quadrilaterals with edge lengths $a,b,c,d$ (in any order). When this is the case, let $M(a,b,c,d)$ denote the maximal area of such a quadrilateral.
    For example, $M(2,2,3,3)=6$, attained e.g. by a $2\\times 3$ rectangle.\n

    \n

    \nLet $SP(n)$ be the sum of $a+b+c+d$ over all choices $a \\le b \\le c \\le d$ for which $M(a,b,c,d)$ is a positive integer not exceeding $n$.
    \n$SP(10)=186$ and $SP(100)=23238$.\n

    \n

    \nFind $SP(1\\,000\\,000)$.\n

    ", "url": "https://projecteuler.net/problem=681", "answer": "2611227421428"} {"id": 682, "problem": "$5$-smooth numbers are numbers whose largest prime factor doesn't exceed $5$.\n\n$5$-smooth numbers are also called Hamming numbers.\n\nLet $\\Omega(a)$ be the count of prime factors of $a$ (counted with multiplicity).\n\nLet $s(a)$ be the sum of the prime factors of $a$ (with multiplicity).\n\nFor example, $\\Omega(300) = 5$ and $s(300) = 2+2+3+5+5 = 17$.\n\nLet $f(n)$ be the number of pairs, $(p,q)$, of Hamming numbers such that $\\Omega(p)=\\Omega(q)$ and $s(p)+s(q)=n$.\n\nYou are given $f(10)=4$ (the pairs are $(4,9),(5,5),(6,6),(9,4)$) and $f(10^2)=3629$.\n\nFind $f(10^7) \\bmod 1\\,000\\,000\\,007$.", "raw_html": "

    $5$-smooth numbers are numbers whose largest prime factor doesn't exceed $5$.
    \n$5$-smooth numbers are also called Hamming numbers.

    \n\n

    Let $\\Omega(a)$ be the count of prime factors of $a$ (counted with multiplicity).
    \nLet $s(a)$ be the sum of the prime factors of $a$ (with multiplicity).
    \nFor example, $\\Omega(300) = 5$ and $s(300) = 2+2+3+5+5 = 17$.

    \n\n

    Let $f(n)$ be the number of pairs, $(p,q)$, of Hamming numbers such that $\\Omega(p)=\\Omega(q)$ and $s(p)+s(q)=n$.
    \nYou are given $f(10)=4$ (the pairs are $(4,9),(5,5),(6,6),(9,4)$) and $f(10^2)=3629$.

    \n\n

    Find $f(10^7) \\bmod 1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=682", "answer": "290872710"} {"id": 683, "problem": "Consider the following variant of \"The Chase\" game. This game is played between $n$ players sitting around a circular table using two dice. It consists of $n-1$ rounds, and at the end of each round one player is eliminated and has to pay a certain amount of money into a pot. The last player remaining is the winner and receives the entire contents of the pot.\n\nAt the beginning of a round, each die is given to a randomly selected player. A round then consists of a number of turns.\n\nDuring each turn, each of the two players with a die rolls it. If a player rolls a 1 or a 2, the die is passed to the neighbour on the left; if the player rolls a 5 or a 6, the die is passed to the neighbour on the right; otherwise, the player keeps the die for the next turn.\n\nThe round ends when one player has both dice at the beginning of a turn. At which point that player is immediately eliminated and has to pay $s^2$ where $s$ is the number of completed turns in this round. Note that if both dice happen to be handed to the same player at the beginning of a round, then no turns are completed, so the player is eliminated without having to pay any money into the pot.\n\nLet $G(n)$ be the expected amount that the winner will receive. For example $G(5)$ is approximately 96.544, and $G(50)$ is 2.82491788e6 in scientific notation rounded to 9 significant digits.\n\nFind $G(500)$, giving your answer in scientific notation rounded to 9 significant digits.", "raw_html": "

    Consider the following variant of \"The Chase\" game. This game is played between $n$ players sitting around a circular table using two dice. It consists of $n-1$ rounds, and at the end of each round one player is eliminated and has to pay a certain amount of money into a pot. The last player remaining is the winner and receives the entire contents of the pot.

    \n\n

    At the beginning of a round, each die is given to a randomly selected player. A round then consists of a number of turns.

    \n\n

    During each turn, each of the two players with a die rolls it. If a player rolls a 1 or a 2, the die is passed to the neighbour on the left; if the player rolls a 5 or a 6, the die is passed to the neighbour on the right; otherwise, the player keeps the die for the next turn.

    \n\n

    The round ends when one player has both dice at the beginning of a turn. At which point that player is immediately eliminated and has to pay $s^2$ where $s$ is the number of completed turns in this round. Note that if both dice happen to be handed to the same player at the beginning of a round, then no turns are completed, so the player is eliminated without having to pay any money into the pot.

    \n\n

    Let $G(n)$ be the expected amount that the winner will receive. For example $G(5)$ is approximately 96.544, and $G(50)$ is 2.82491788e6 in scientific notation rounded to 9 significant digits.

    \n\n

    Find $G(500)$, giving your answer in scientific notation rounded to 9 significant digits.

    ", "url": "https://projecteuler.net/problem=683", "answer": "2.38955315e11"} {"id": 684, "problem": "Define $s(n)$ to be the smallest number that has a digit sum of $n$. For example $s(10) = 19$.\n\nLet $\\displaystyle S(k) = \\sum_{n=1}^k s(n)$. You are given $S(20) = 1074$.\n\nFurther let $f_i$ be the Fibonacci sequence defined by $f_0=0, f_1=1$ and $f_i=f_{i-2}+f_{i-1}$ for all $i \\ge 2$.\n\nFind $\\displaystyle \\sum_{i=2}^{90} S(f_i)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Define $s(n)$ to be the smallest number that has a digit sum of $n$. For example $s(10) = 19$.
    \nLet $\\displaystyle S(k) = \\sum_{n=1}^k s(n)$. You are given $S(20) = 1074$.

    \n

    \nFurther let $f_i$ be the Fibonacci sequence defined by $f_0=0, f_1=1$ and $f_i=f_{i-2}+f_{i-1}$ for all $i \\ge 2$.

    \n

    \nFind $\\displaystyle \\sum_{i=2}^{90} S(f_i)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=684", "answer": "922058210"} {"id": 685, "problem": "Writing down the numbers which have a digit sum of 10 in ascending order, we get:\n$19, 28, 37, 46,55,64,73,82,91,109, 118,\\dots$\n\nLet $f(n,m)$ be the $m^{\\text{th}}$ occurrence of the digit sum $n$. For example, $f(10,1)=19$, $f(10,10)=109$ and $f(10,100)=1423$.\n\nLet $\\displaystyle S(k)=\\sum_{n=1}^k f(n^3,n^4)$. For example $S(3)=7128$ and $S(10)\\equiv 32287064 \\mod 1\\,000\\,000\\,007$.\n\nFind $S(10\\,000)$ modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Writing down the numbers which have a digit sum of 10 in ascending order, we get:\n$19, 28, 37, 46,55,64,73,82,91,109, 118,\\dots$

    \n

    \nLet $f(n,m)$ be the $m^{\\text{th}}$ occurrence of the digit sum $n$. For example, $f(10,1)=19$, $f(10,10)=109$ and $f(10,100)=1423$.

    \n

    \nLet $\\displaystyle S(k)=\\sum_{n=1}^k f(n^3,n^4)$. For example $S(3)=7128$ and $S(10)\\equiv 32287064 \\mod 1\\,000\\,000\\,007$.

    \n

    \nFind $S(10\\,000)$ modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=685", "answer": "662878999"} {"id": 686, "problem": "$2^7=128$ is the first power of two whose leading digits are \"12\".\n\nThe next power of two whose leading digits are \"12\" is $2^{80}$.\n\nDefine $p(L, n)$ to be the $n$th-smallest value of $j$ such that the base 10 representation of $2^j$ begins with the digits of $L$.\n\nSo $p(12, 1) = 7$ and $p(12, 2) = 80$.\n\nYou are also given that $p(123, 45) = 12710$.\n\nFind $p(123, 678910)$.", "raw_html": "

    $2^7=128$ is the first power of two whose leading digits are \"12\".
    \nThe next power of two whose leading digits are \"12\" is $2^{80}$.

    \n\n

    Define $p(L, n)$ to be the $n$th-smallest value of $j$ such that the base 10 representation of $2^j$ begins with the digits of $L$.
    \nSo $p(12, 1) = 7$ and $p(12, 2) = 80$.

    \n\n

    You are also given that $p(123, 45) = 12710$.

    \n\n

    Find $p(123, 678910)$.

    ", "url": "https://projecteuler.net/problem=686", "answer": "193060223"} {"id": 687, "problem": "A standard deck of $52$ playing cards, which consists of thirteen ranks (Ace, Two, ..., Ten, King, Queen and Jack) each in four suits (Clubs, Diamonds, Hearts and Spades), is randomly shuffled. Let us call a rank perfect if no two cards of that same rank appear next to each other after the shuffle.\n\nIt can be seen that the expected number of ranks that are perfect after a random shuffle equals $\\frac {4324} {425} \\approx 10.1741176471$.\n\nFind the probability that the number of perfect ranks is prime. Give your answer rounded to $10$ decimal places.", "raw_html": "

    A standard deck of $52$ playing cards, which consists of thirteen ranks (Ace, Two, ..., Ten, King, Queen and Jack) each in four suits (Clubs, Diamonds, Hearts and Spades), is randomly shuffled. Let us call a rank perfect if no two cards of that same rank appear next to each other after the shuffle.

    \n

    \nIt can be seen that the expected number of ranks that are perfect after a random shuffle equals $\\frac {4324} {425} \\approx 10.1741176471$.

    \n

    \nFind the probability that the number of perfect ranks is prime. Give your answer rounded to $10$ decimal places.

    ", "url": "https://projecteuler.net/problem=687", "answer": "0.3285320869"} {"id": 688, "problem": "We stack $n$ plates into $k$ non-empty piles where each pile is a different size. Define $f(n,k)$ to be the maximum number of plates possible in the smallest pile. For example when $n = 10$ and $k = 3$ the piles $2,3,5$ is the best that can be done and so $f(10,3) = 2$. It is impossible to divide 10 into 5 non-empty differently-sized piles and hence $f(10,5) = 0$.\n\nDefine $F(n)$ to be the sum of $f(n,k)$ for all possible pile sizes $k\\ge 1$. For example $F(100) = 275$.\n\nFurther define $S(N) = \\displaystyle\\sum_{n=1}^N F(n)$. You are given $S(100) = 12656$.\n\nFind $S(10^{16})$ giving your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nWe stack $n$ plates into $k$ non-empty piles where each pile is a different size. Define $f(n,k)$ to be the maximum number of plates possible in the smallest pile. For example when $n = 10$ and $k = 3$ the piles $2,3,5$ is the best that can be done and so $f(10,3) = 2$. It is impossible to divide 10 into 5 non-empty differently-sized piles and hence $f(10,5) = 0$.\n

    \n

    \nDefine $F(n)$ to be the sum of $f(n,k)$ for all possible pile sizes $k\\ge 1$. For example $F(100) = 275$.\n

    \n

    \nFurther define $S(N) = \\displaystyle\\sum_{n=1}^N F(n)$. You are given $S(100) = 12656$.\n

    \n

    \nFind $S(10^{16})$ giving your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=688", "answer": "110941813"} {"id": 689, "problem": "For $0 \\le x \\lt 1$, define $d_i(x)$ to be the $i$th digit after the binary point of the binary representation of $x$.\n\nFor example $d_2(0.25) = 1$, $d_i(0.25) = 0$ for $i \\ne 2$.\n\nLet $f(x) = \\displaystyle{\\sum_{i=1}^{\\infty}\\frac{d_i(x)}{i^2}}$.\n\nLet $p(a)$ be probability that $f(x) \\gt a$, given that $x$ is uniformly distributed between $0$ and $1$.\n\nFind $p(0.5)$. Give your answer rounded to $8$ digits after the decimal point.", "raw_html": "

    For $0 \\le x \\lt 1$, define $d_i(x)$ to be the $i$th digit after the binary point of the binary representation of $x$.
    \nFor example $d_2(0.25) = 1$, $d_i(0.25) = 0$ for $i \\ne 2$.

    \n\n

    Let $f(x) = \\displaystyle{\\sum_{i=1}^{\\infty}\\frac{d_i(x)}{i^2}}$.

    \n\n

    Let $p(a)$ be probability that $f(x) \\gt a$, given that $x$ is uniformly distributed between $0$ and $1$.

    \n\n

    Find $p(0.5)$. Give your answer rounded to $8$ digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=689", "answer": "0.56565454"} {"id": 690, "problem": "Tom (the cat) and Jerry (the mouse) are playing on a simple graph $G$.\n\nEvery vertex of $G$ is a mousehole, and every edge of $G$ is a tunnel connecting two mouseholes.\n\nOriginally, Jerry is hiding in one of the mouseholes.\n\nEvery morning, Tom can check one (and only one) of the mouseholes. If Jerry happens to be hiding there then Tom catches Jerry and the game is over.\n\nEvery evening, if the game continues, Jerry moves to a mousehole which is adjacent (i.e. connected by a tunnel, if there is one available) to his current hiding place. The next morning Tom checks again and the game continues like this.\n\nLet us call a graph $G$ a Tom graph, if our super-smart Tom, who knows the configuration of the graph but does not know the location of Jerry, can guarantee to catch Jerry in finitely many days.\nFor example consider all graphs on 3 nodes:\n\nFor graphs 1 and 2, Tom will catch Jerry in at most three days. For graph 3 Tom can check the middle connection on two consecutive days and hence guarantee to catch Jerry in at most two days. These three graphs are therefore Tom Graphs. However, graph 4 is not a Tom Graph because the game could potentially continue forever.\n\nLet $T(n)$ be the number of different Tom graphs with $n$ vertices. Two graphs are considered the same if there is a bijection $f$ between their vertices, such that $(v,w)$ is an edge if and only if $(f(v),f(w))$ is an edge.\n\nWe have $T(3) = 3$, $T(7) = 37$, $T(10) = 328$ and $T(20) = 1416269$.\n\nFind $T(2019)$ giving your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nTom (the cat) and Jerry (the mouse) are playing on a simple graph $G$.\n

    \n

    \nEvery vertex of $G$ is a mousehole, and every edge of $G$ is a tunnel connecting two mouseholes.\n

    \n

    \nOriginally, Jerry is hiding in one of the mouseholes.
    \nEvery morning, Tom can check one (and only one) of the mouseholes. If Jerry happens to be hiding there then Tom catches Jerry and the game is over.
    \nEvery evening, if the game continues, Jerry moves to a mousehole which is adjacent (i.e. connected by a tunnel, if there is one available) to his current hiding place. The next morning Tom checks again and the game continues like this.\n

    \n

    \nLet us call a graph $G$ a Tom graph, if our super-smart Tom, who knows the configuration of the graph but does not know the location of Jerry, can guarantee to catch Jerry in finitely many days.\nFor example consider all graphs on 3 nodes:\n

    \n
    \n\"Graphs\n
    \n

    \nFor graphs 1 and 2, Tom will catch Jerry in at most three days. For graph 3 Tom can check the middle connection on two consecutive days and hence guarantee to catch Jerry in at most two days. These three graphs are therefore Tom Graphs. However, graph 4 is not a Tom Graph because the game could potentially continue forever.\n

    \n

    \nLet $T(n)$ be the number of different Tom graphs with $n$ vertices. Two graphs are considered the same if there is a bijection $f$ between their vertices, such that $(v,w)$ is an edge if and only if $(f(v),f(w))$ is an edge.\n

    \n

    \nWe have $T(3) = 3$, $T(7) = 37$, $T(10) = 328$ and $T(20) = 1416269$.\n

    \n

    \nFind $T(2019)$ giving your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=690", "answer": "415157690"} {"id": 691, "problem": "Given a character string $s$, we define $L(k,s)$ to be the length of the longest substring of $s$ which appears at least $k$ times in $s$, or $0$ if such a substring does not exist. For example, $L(3,\\text{“bbabcabcabcacba”})=4$ because of the three occurrences of the substring $\\text{“abca”}$, and $L(2,\\text{“bbabcabcabcacba”})=7$ because of the repeated substring $\\text{“abcabca”}$. Note that the occurrences can overlap.\n\nLet $a_n$, $b_n$ and $c_n$ be the $0/1$ sequences defined by:\n\n- $a_0 = 0$\n\n- $a_{2n} = a_{n}$\n\n- $a_{2n+1} = 1-a_{n}$\n\n- $b_n = \\lfloor\\frac{n+1}{\\varphi}\\rfloor - \\lfloor\\frac{n}{\\varphi}\\rfloor$ (where $\\varphi$ is the golden ratio)\n\n- $c_n = a_n + b_n - 2a_nb_n$\n\nand $S_n$ the character string $c_0\\ldots c_{n-1}$. You are given that $L(2,S_{10})=5$, $L(3,S_{10})=2$, $L(2,S_{100})=14$, $L(4,S_{100})=6$, $L(2,S_{1000})=86$, $L(3,S_{1000}) = 45$, $L(5,S_{1000}) = 31$, and that the sum of non-zero $L(k,S_{1000})$ for $k\\ge 1$ is $2460$.\n\nFind the sum of non-zero $L(k,S_{5000000})$ for $k\\ge 1$.", "raw_html": "

    Given a character string $s$, we define $L(k,s)$ to be the length of the longest substring of $s$ which appears at least $k$ times in $s$, or $0$ if such a substring does not exist. For example, $L(3,\\text{“bbabcabcabcacba”})=4$ because of the three occurrences of the substring $\\text{“abca”}$, and $L(2,\\text{“bbabcabcabcacba”})=7$ because of the repeated substring $\\text{“abcabca”}$. Note that the occurrences can overlap.

    \n\n

    Let $a_n$, $b_n$ and $c_n$ be the $0/1$ sequences defined by:

    \n
      \n
    • $a_0 = 0$
    • \n
    • $a_{2n} = a_{n}$
    • \n
    • $a_{2n+1} = 1-a_{n}$
    • \n
    • $b_n = \\lfloor\\frac{n+1}{\\varphi}\\rfloor - \\lfloor\\frac{n}{\\varphi}\\rfloor$ (where $\\varphi$ is the golden ratio)
    • \n
    • $c_n = a_n + b_n - 2a_nb_n$
    • \n
    \n

    and $S_n$ the character string $c_0\\ldots c_{n-1}$. You are given that $L(2,S_{10})=5$, $L(3,S_{10})=2$, $L(2,S_{100})=14$, $L(4,S_{100})=6$, $L(2,S_{1000})=86$, $L(3,S_{1000}) = 45$, $L(5,S_{1000}) = 31$, and that the sum of non-zero $L(k,S_{1000})$ for $k\\ge 1$ is $2460$.

    \n\n

    Find the sum of non-zero $L(k,S_{5000000})$ for $k\\ge 1$.

    ", "url": "https://projecteuler.net/problem=691", "answer": "11570761"} {"id": 692, "problem": "Siegbert and Jo take turns playing a game with a heap of $N$ pebbles:\n\n1. Siegbert is the first to take some pebbles. He can take as many pebbles as he wants. (Between 1 and $N$ inclusive.)\n\n2. In each of the following turns the current player must take at least one pebble and at most twice the amount of pebbles taken by the previous player.\n\n3. The player who takes the last pebble wins.\n\nAlthough Siegbert can always win by taking all the pebbles on his first turn, to make the game more interesting he chooses to take the smallest number of pebbles that guarantees he will still win (assuming both Siegbert and Jo play optimally for the rest of the game).\n\nLet $H(N)$ be that minimal amount for a heap of $N$ pebbles.\n\n$H(1)=1$, $H(4)=1$, $H(17)=1$, $H(8)=8$ and $H(18)=5$ .\n\nLet $G(n)$ be $\\displaystyle{\\sum_{k=1}^n H(k)}$.\n\n$G(13)=43$.\n\nFind $G(23416728348467685)$.", "raw_html": "

    \nSiegbert and Jo take turns playing a game with a heap of $N$ pebbles:
    \n1. Siegbert is the first to take some pebbles. He can take as many pebbles as he wants. (Between 1 and $N$ inclusive.)
    \n2. In each of the following turns the current player must take at least one pebble and at most twice the amount of pebbles taken by the previous player.
    \n3. The player who takes the last pebble wins.
    \n

    \n

    \nAlthough Siegbert can always win by taking all the pebbles on his first turn, to make the game more interesting he chooses to take the smallest number of pebbles that guarantees he will still win (assuming both Siegbert and Jo play optimally for the rest of the game).\n

    \n

    \nLet $H(N)$ be that minimal amount for a heap of $N$ pebbles.
    \n$H(1)=1$, $H(4)=1$, $H(17)=1$, $H(8)=8$ and $H(18)=5$ .\n

    \n

    \nLet $G(n)$ be $\\displaystyle{\\sum_{k=1}^n H(k)}$.
    \n$G(13)=43$.\n

    \n

    \nFind $G(23416728348467685)$.\n

    ", "url": "https://projecteuler.net/problem=692", "answer": "842043391019219959"} {"id": 693, "problem": "Two positive integers $x$ and $y$ ($x > y$) can generate a sequence in the following manner:\n\n- $a_x = y$ is the first term,\n\n- $a_{z+1} = a_z^2 \\bmod z$ for $z = x, x+1,x+2,\\ldots$ and\n\n- the generation stops when a term becomes $0$ or $1$.\n\nThe number of terms in this sequence is denoted $l(x,y)$.\n\nFor example, with $x = 5$ and $y = 3$, we get $a_5 = 3$, $a_6 = 3^2 \\bmod 5 = 4$, $a_7 = 4^2\\bmod 6 = 4$, etc. Giving the sequence of 29 terms:\n\n$\t3,4,4,2,4,7,9,4,4,3,9,6,4,16,4,16,16,4,16,3,9,6,10,19,25,16,16,8,0\t\t$\n\nHence $l(5,3) = 29$.\n\n$g(x)$ is defined to be the maximum value of $l(x,y)$ for $y \\lt x$. For example, $g(5) = 29$.\n\nFurther, define $f(n)$ to be the maximum value of $g(x)$ for $x \\le n$. For example, $f(100) = 145$ and $f(10\\,000) = 8824$.\n\nFind $f(3\\,000\\,000)$.", "raw_html": "

    Two positive integers $x$ and $y$ ($x > y$) can generate a sequence in the following manner:

    \n
      \n
    • $a_x = y$ is the first term,
    • \n
    • $a_{z+1} = a_z^2 \\bmod z$ for $z = x, x+1,x+2,\\ldots$ and
    • \n
    • the generation stops when a term becomes $0$ or $1$.
    • \n
    \n

    The number of terms in this sequence is denoted $l(x,y)$.

    \n\n

    For example, with $x = 5$ and $y = 3$, we get $a_5 = 3$, $a_6 = 3^2 \\bmod 5 = 4$, $a_7 = 4^2\\bmod 6 = 4$, etc. Giving the sequence of 29 terms:
    \n$\t3,4,4,2,4,7,9,4,4,3,9,6,4,16,4,16,16,4,16,3,9,6,10,19,25,16,16,8,0\t\t$
    \nHence $l(5,3) = 29$.

    \n\n

    $g(x)$ is defined to be the maximum value of $l(x,y)$ for $y \\lt x$. For example, $g(5) = 29$.

    \n\n

    Further, define $f(n)$ to be the maximum value of $g(x)$ for $x \\le n$. For example, $f(100) = 145$ and $f(10\\,000) = 8824$.

    \n\n

    Find $f(3\\,000\\,000)$.

    ", "url": "https://projecteuler.net/problem=693", "answer": "699161"} {"id": 694, "problem": "A positive integer $n$ is considered cube-full, if for every prime $p$ that divides $n$, so does $p^3$. Note that $1$ is considered cube-full.\n\nLet $s(n)$ be the function that counts the number of cube-full divisors of $n$. For example, $1$, $8$ and $16$ are the three cube-full divisors of $16$. Therefore, $s(16)=3$.\n\nLet $S(n)$ represent the summatory function of $s(n)$, that is $S(n)=\\displaystyle\\sum_{i=1}^n s(i)$.\n\nYou are given $S(16) = 19$, $S(100) = 126$ and $S(10000) = 13344$.\n\nFind $S(10^{18})$.", "raw_html": "

    \nA positive integer $n$ is considered cube-full, if for every prime $p$ that divides $n$, so does $p^3$. Note that $1$ is considered cube-full.\n

    \n

    \nLet $s(n)$ be the function that counts the number of cube-full divisors of $n$. For example, $1$, $8$ and $16$ are the three cube-full divisors of $16$. Therefore, $s(16)=3$.\n

    \n

    \nLet $S(n)$ represent the summatory function of $s(n)$, that is $S(n)=\\displaystyle\\sum_{i=1}^n s(i)$.\n

    \n

    \nYou are given $S(16) = 19$, $S(100) = 126$ and $S(10000) = 13344$.\n

    \n

    \nFind $S(10^{18})$.\n

    ", "url": "https://projecteuler.net/problem=694", "answer": "1339784153569958487"} {"id": 695, "problem": "Three points, $P_1$, $P_2$ and $P_3$, are randomly selected within a unit square. Consider the three rectangles with sides parallel to the sides of the unit square and a diagonal that is one of the three line segments $\\overline{P_1P_2}$, $\\overline{P_1P_3}$ or $\\overline{P_2P_3}$ (see picture below).\n\nWe are interested in the rectangle with the second biggest area. In the example above that happens to be the green rectangle defined with the diagonal $\\overline{P_2P_3}$.\n\nFind the expected value of the area of the second biggest of the three rectangles. Give your answer rounded to 10 digits after the decimal point.", "raw_html": "

    Three points, $P_1$, $P_2$ and $P_3$, are randomly selected within a unit square. Consider the three rectangles with sides parallel to the sides of the unit square and a diagonal that is one of the three line segments $\\overline{P_1P_2}$, $\\overline{P_1P_3}$ or $\\overline{P_2P_3}$ (see picture below).

    \n\n
    \n\"3\n
    \n\n

    We are interested in the rectangle with the second biggest area. In the example above that happens to be the green rectangle defined with the diagonal $\\overline{P_2P_3}$.

    \n\n

    Find the expected value of the area of the second biggest of the three rectangles. Give your answer rounded to 10 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=695", "answer": "0.1017786859"} {"id": 696, "problem": "The game of Mahjong is played with tiles belonging to $s$ suits. Each tile also has a number in the range $1\\ldots n$, and for each suit/number combination there are exactly four indistinguishable tiles with that suit and number. (The real Mahjong game also contains other bonus tiles, but those will not feature in this problem.)\n\nA winning hand is a collection of $3t+2$ Tiles (where $t$ is a fixed integer) that can be arranged as $t$ Triples and one Pair, where:\n\n- A Triple is either a Chow or a Pung\n\n- A Chow is three tiles of the same suit and consecutive numbers\n\n- A Pung is three identical tiles (same suit and same number)\n\n- A Pair is two identical tiles (same suit and same number)\n\nFor example, here is a winning hand with $n=9$, $s=3$, $t=4$, consisting in this case of two Chows, two Pungs, and one Pair:\n\nNote that sometimes the same collection of tiles can be represented as $t$ Triples and one Pair in more than one way. This only counts as one winning hand. For example, this is considered to be the same winning hand as above, because it consists of the same tiles:\n\nLet $w(n, s, t)$ be the number of distinct winning hands formed of $t$ Triples and one Pair, where there are $s$ suits available and tiles are numbered up to $n$.\n\nFor example, with a single suit and tiles numbered up to $4$, we have $w(4, 1, 1) = 20$: there are $12$ winning hands consisting of a Pung and a Pair, and another $8$ containing a Chow and a Pair. You are also given that $w(9, 1, 4) = 13259$, $w(9, 3, 4) = 5237550$, and $w(1000, 1000, 5) \\equiv 107662178 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $w(10^8, 10^8, 30)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    The game of Mahjong is played with tiles belonging to $s$ suits. Each tile also has a number in the range $1\\ldots n$, and for each suit/number combination there are exactly four indistinguishable tiles with that suit and number. (The real Mahjong game also contains other bonus tiles, but those will not feature in this problem.)

    \n\n

    A winning hand is a collection of $3t+2$ Tiles (where $t$ is a fixed integer) that can be arranged as $t$ Triples and one Pair, where:

    \n
      \n
    • A Triple is either a Chow or a Pung
    • \n
    • A Chow is three tiles of the same suit and consecutive numbers
    • \n
    • A Pung is three identical tiles (same suit and same number)
    • \n
    • A Pair is two identical tiles (same suit and same number)
    • \n
    \n\n

    For example, here is a winning hand with $n=9$, $s=3$, $t=4$, consisting in this case of two Chows, two Pungs, and one Pair:

    \n
    \n\"A\n
    \n\n

    Note that sometimes the same collection of tiles can be represented as $t$ Triples and one Pair in more than one way. This only counts as one winning hand. For example, this is considered to be the same winning hand as above, because it consists of the same tiles:

    \n
    \n\"Alternative\n
    \n\n

    Let $w(n, s, t)$ be the number of distinct winning hands formed of $t$ Triples and one Pair, where there are $s$ suits available and tiles are numbered up to $n$.

    \n\n

    For example, with a single suit and tiles numbered up to $4$, we have $w(4, 1, 1) = 20$: there are $12$ winning hands consisting of a Pung and a Pair, and another $8$ containing a Chow and a Pair. You are also given that $w(9, 1, 4) = 13259$, $w(9, 3, 4) = 5237550$, and $w(1000, 1000, 5) \\equiv 107662178 \\pmod{1\\,000\\,000\\,007}$.

    \n\n

    Find $w(10^8, 10^8, 30)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=696", "answer": "436944244"} {"id": 697, "problem": "Given a fixed real number $c$, define a random sequence $(X_n)_{n\\ge 0}$ by the following random process:\n\n- $X_0 = c$ (with probability 1).\n\n- For $n>0$, $X_n = U_n X_{n-1}$ where $U_n$ is a real number chosen at random between zero and one, uniformly, and independently of all previous choices $(U_m)_{mGiven a fixed real number $c$, define a random sequence $(X_n)_{n\\ge 0}$ by the following random process:

    \n
      \n
    • $X_0 = c$ (with probability 1).
    • \n
    • For $n>0$, $X_n = U_n X_{n-1}$ where $U_n$ is a real number chosen at random between zero and one, uniformly, and independently of all previous choices $(U_m)_{m<n}$.
    • \n
    \n\n

    If we desire there to be precisely a 25% probability that $X_{100}<1$, then this can be arranged by fixing $c$ such that $\\log_{10} c \\approx 46.27$.

    \n\n

    Suppose now that $c$ is set to a different value, so that there is precisely a 25% probability that $X_{10\\,000\\,000}<1$.

    \n

    Find $\\log_{10} c$ and give your answer rounded to two places after the decimal point.

    ", "url": "https://projecteuler.net/problem=697", "answer": "4343871.06"} {"id": 698, "problem": "We define 123-numbers as follows:\n\n- 1 is the smallest 123-number.\n\n- When written in base 10 the only digits that can be present are \"1\", \"2\" and \"3\" and if present the number of times they each occur is also a 123-number.\n\nSo 2 is a 123-number, since it consists of one digit \"2\" and 1 is a 123-number. Therefore, 33 is a 123-number as well since it consists of two digits \"3\" and 2 is a 123-number.\n\nOn the other hand, 1111 is not a 123-number, since it contains 4 digits \"1\" and 4 is not a 123-number.\n\nIn ascending order, the first 123-numbers are:\n\n$1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33, 111, 112, 113, 121, 122, 123, 131, \\ldots$\n\nLet $F(n)$ be the $n$-th 123-number. For example $F(4)=11$, $F(10)=31$, $F(40)=1112$, $F(1000)=1223321$ and $F(6000)= 2333333333323$.\n\nFind $F(111\\,111\\,111\\,111\\,222\\,333)$. Give your answer modulo $123\\,123\\,123$.", "raw_html": "

    \nWe define 123-numbers as follows:\n

    \n\n
      \n
    • 1 is the smallest 123-number.
    • \n
    • When written in base 10 the only digits that can be present are \"1\", \"2\" and \"3\" and if present the number of times they each occur is also a 123-number.
    • \n
    \n\n

    \nSo 2 is a 123-number, since it consists of one digit \"2\" and 1 is a 123-number. Therefore, 33 is a 123-number as well since it consists of two digits \"3\" and 2 is a 123-number.
    \nOn the other hand, 1111 is not a 123-number, since it contains 4 digits \"1\" and 4 is not a 123-number.\n

    \n

    \nIn ascending order, the first 123-numbers are:
    \n$1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33, 111, 112, 113, 121, 122, 123, 131, \\ldots$\n

    \n

    \nLet $F(n)$ be the $n$-th 123-number. For example $F(4)=11$, $F(10)=31$, $F(40)=1112$, $F(1000)=1223321$ and $F(6000)= 2333333333323$.\n

    \n

    \nFind $F(111\\,111\\,111\\,111\\,222\\,333)$. Give your answer modulo $123\\,123\\,123$.\n

    ", "url": "https://projecteuler.net/problem=698", "answer": "57808202"} {"id": 699, "problem": "Let $\\sigma(n)$ be the sum of all the divisors of the positive integer $n$, for example:\n\n$\\sigma(10) = 1+2+5+10 = 18$.\n\nDefine $T(N)$ to be the sum of all numbers $n \\le N$ such that when the fraction $\\frac{\\sigma(n)}{n}$ is written in its lowest form $\\frac ab$, the denominator is a power of 3 i.e. $b = 3^k, k > 0$.\n\nYou are given $T(100) = 270$ and $T(10^6) = 26089287$.\n\nFind $T(10^{14})$.", "raw_html": "

    \nLet $\\sigma(n)$ be the sum of all the divisors of the positive integer $n$, for example:
    \n$\\sigma(10) = 1+2+5+10 = 18$.\n

    \n

    \nDefine $T(N)$ to be the sum of all numbers $n \\le N$ such that when the fraction $\\frac{\\sigma(n)}{n}$ is written in its lowest form $\\frac ab$, the denominator is a power of 3 i.e. $b = 3^k, k > 0$.\n

    \n

    \nYou are given $T(100) = 270$ and $T(10^6) = 26089287$.\n

    \n

    \nFind $T(10^{14})$.\n

    ", "url": "https://projecteuler.net/problem=699", "answer": "37010438774467572"} {"id": 700, "problem": "Leonhard Euler was born on 15 April 1707.\n\nConsider the sequence 1504170715041707n mod 4503599627370517.\n\nAn element of this sequence is defined to be an Eulercoin if it is strictly smaller than all previously found Eulercoins.\n\nFor example, the first term is 1504170715041707 which is the first Eulercoin. The second term is 3008341430083414 which is greater than 1504170715041707 so is not an Eulercoin. However, the third term is 8912517754604 which is small enough to be a new Eulercoin.\n\nThe sum of the first 2 Eulercoins is therefore 1513083232796311.\n\nFind the sum of all Eulercoins.", "raw_html": "

    Leonhard Euler was born on 15 April 1707.

    \n\n

    Consider the sequence 1504170715041707n mod 4503599627370517.

    \n\n

    An element of this sequence is defined to be an Eulercoin if it is strictly smaller than all previously found Eulercoins.

    \n\n

    For example, the first term is 1504170715041707 which is the first Eulercoin. The second term is 3008341430083414 which is greater than 1504170715041707 so is not an Eulercoin. However, the third term is 8912517754604 which is small enough to be a new Eulercoin.

    \n\n

    The sum of the first 2 Eulercoins is therefore 1513083232796311.

    \n\n

    Find the sum of all Eulercoins.

    ", "url": "https://projecteuler.net/problem=700", "answer": "1517926517777556"} {"id": 701, "problem": "Consider a rectangle made up of $W \\times H$ square cells each with area $1$.\nEach cell is independently coloured black with probability $0.5$ otherwise white. Black cells sharing an edge are assumed to be connected.\nConsider the maximum area of connected cells.\n\nDefine $E(W,H)$ to be the expected value of this maximum area.\nFor example, $E(2,2)=1.875$, as illustrated below.\n\nYou are also given $E(4, 4) = 5.76487732$, rounded to $8$ decimal places.\n\nFind $E(7, 7)$, rounded to $8$ decimal places.", "raw_html": "

    \nConsider a rectangle made up of $W \\times H$ square cells each with area $1$.
    Each cell is independently coloured black with probability $0.5$ otherwise white. Black cells sharing an edge are assumed to be connected.
    Consider the maximum area of connected cells.

    \n\n

    \nDefine $E(W,H)$ to be the expected value of this maximum area.\nFor example, $E(2,2)=1.875$, as illustrated below.\n

    \n
    \n\"3\n
    \n

    \nYou are also given $E(4, 4) = 5.76487732$, rounded to $8$ decimal places.\n

    \n

    \nFind $E(7, 7)$, rounded to $8$ decimal places.\n

    ", "url": "https://projecteuler.net/problem=701", "answer": "13.51099836"} {"id": 702, "problem": "A regular hexagon table of side length $N$ is divided into equilateral triangles of side length $1$. The picture below is an illustration of the case $N = 3$.\n\nAn flea of negligible size is jumping on this table. The flea starts at the centre of the table. Thereafter, at each step, it chooses one of the six corners of the table, and jumps to the mid-point between its current position and the chosen corner.\n\nFor every triangle $T$, we denote by $J(T)$ the minimum number of jumps required for the flea to reach the interior of $T$. Landing on an edge or vertex of $T$ is not sufficient.\n\nFor example, $J(T) = 3$ for the triangle marked with a star in the picture: by jumping from the centre half way towards F, then towards C, then towards E.\n\nLet $S(N)$ be the sum of $J(T)$ for all the upper-pointing triangles $T$ in the upper half of the table. For the case $N = 3$, these are the triangles painted black in the above picture.\n\nYou are given that $S(3) = 42$, $S(5) = 126$, $S(123) = 167178$, and $S(12345) = 3185041956$.\n\nFind $S(123456789)$.", "raw_html": "

    A regular hexagon table of side length $N$ is divided into equilateral triangles of side length $1$. The picture below is an illustration of the case $N = 3$.

    \n\n
    \n\"hexagonal\n
    \n\n

    An flea of negligible size is jumping on this table. The flea starts at the centre of the table. Thereafter, at each step, it chooses one of the six corners of the table, and jumps to the mid-point between its current position and the chosen corner.

    \n\n

    For every triangle $T$, we denote by $J(T)$ the minimum number of jumps required for the flea to reach the interior of $T$. Landing on an edge or vertex of $T$ is not sufficient.

    \n\n

    For example, $J(T) = 3$ for the triangle marked with a star in the picture: by jumping from the centre half way towards F, then towards C, then towards E.

    \n\n

    Let $S(N)$ be the sum of $J(T)$ for all the upper-pointing triangles $T$ in the upper half of the table. For the case $N = 3$, these are the triangles painted black in the above picture.

    \n\n

    You are given that $S(3) = 42$, $S(5) = 126$, $S(123) = 167178$, and $S(12345) = 3185041956$.

    \n\n

    Find $S(123456789)$.

    ", "url": "https://projecteuler.net/problem=702", "answer": "622305608172525546"} {"id": 703, "problem": "Given an integer $n$, $n \\geq 3$, let $B=\\{\\mathrm{false},\\mathrm{true}\\}$ and let $B^n$ be the set of sequences of $n$ values from $B$. The function $f$ from $B^n$ to $B^n$ is defined by $f(b_1 \\dots b_n) = c_1 \\dots c_n$ where:\n\n- $c_i = b_{i+1}$ for $1 \\leq i < n$.\n\n- $c_n = b_1 \\;\\mathrm{AND}\\; (b_2 \\;\\mathrm{XOR}\\; b_3)$, where $\\mathrm{AND}$ and $\\mathrm{XOR}$ are the logical $\\mathrm{AND}$ and exclusive $\\mathrm{OR}$ operations.\n\nLet $S(n)$ be the number of functions $T$ from $B^n$ to $B$ such that for all $x$ in $B^n$, $T(x) ~\\mathrm{AND}~ T(f(x)) = \\mathrm{false}$.\nYou are given that $S(3) = 35$ and $S(4) = 2118$.\n\nFind $S(20)$. Give your answer modulo $1\\,001\\,001\\,011$.", "raw_html": "

    Given an integer $n$, $n \\geq 3$, let $B=\\{\\mathrm{false},\\mathrm{true}\\}$ and let $B^n$ be the set of sequences of $n$ values from $B$. The function $f$ from $B^n$ to $B^n$ is defined by $f(b_1 \\dots b_n) = c_1 \\dots c_n$ where:

    \n
      \n
    • $c_i = b_{i+1}$ for $1 \\leq i < n$.
    • \n
    • $c_n = b_1 \\;\\mathrm{AND}\\; (b_2 \\;\\mathrm{XOR}\\; b_3)$, where $\\mathrm{AND}$ and $\\mathrm{XOR}$ are the logical $\\mathrm{AND}$ and exclusive $\\mathrm{OR}$ operations.
    • \n
    \n\n

    Let $S(n)$ be the number of functions $T$ from $B^n$ to $B$ such that for all $x$ in $B^n$, $T(x) ~\\mathrm{AND}~ T(f(x)) = \\mathrm{false}$.\nYou are given that $S(3) = 35$ and $S(4) = 2118$.

    \n\n

    Find $S(20)$. Give your answer modulo $1\\,001\\,001\\,011$.

    ", "url": "https://projecteuler.net/problem=703", "answer": "843437991"} {"id": 704, "problem": "Define $g(n, m)$ to be the largest integer $k$ such that $2^k$ divides $\\binom{n}m$.\nFor example, $\\binom{12}5 = 792 = 2^3 \\cdot 3^2 \\cdot 11$, hence $g(12, 5) = 3$.\nThen define $F(n) = \\max \\{ g(n, m) : 0 \\le m \\le n \\}$. $F(10) = 3$ and $F(100) = 6$.\n\nLet $S(N)$ = $\\displaystyle\\sum_{n=1}^N{F(n)}$. You are given that $S(100) = 389$ and $S(10^7) = 203222840$.\n\nFind $S(10^{16})$.", "raw_html": "

    \nDefine $g(n, m)$ to be the largest integer $k$ such that $2^k$ divides $\\binom{n}m$. \nFor example, $\\binom{12}5 = 792 = 2^3 \\cdot 3^2 \\cdot 11$, hence $g(12, 5) = 3$. \nThen define $F(n) = \\max \\{ g(n, m) : 0 \\le m \\le n \\}$. $F(10) = 3$ and $F(100) = 6$.\n

    \n

    \nLet $S(N)$ = $\\displaystyle\\sum_{n=1}^N{F(n)}$. You are given that $S(100) = 389$ and $S(10^7) = 203222840$.\n

    \n

    \nFind $S(10^{16})$.\n

    ", "url": "https://projecteuler.net/problem=704", "answer": "501985601490518144"} {"id": 705, "problem": "The inversion count of a sequence of digits is the smallest number of adjacent pairs that must be swapped to sort the sequence.\n\nFor example, $34214$ has inversion count of $5$:\n$34214 \\to 32414 \\to 23414 \\to 23144 \\to 21344 \\to12344$.\n\nIf each digit of a sequence is replaced by one of its divisors a divided sequence is obtained.\n\nFor example, the sequence $332$ has $8$ divided sequences: $\\{332,331,312,311,132,131,112,111\\}$.\n\nDefine $G(N)$ to be the concatenation of all primes less than $N$, ignoring any zero digit.\n\nFor example, $G(20) = 235711131719$.\n\nDefine $F(N)$ to be the sum of the inversion count for all possible divided sequences from the master sequence $G(N)$.\n\nYou are given $F(20) = 3312$ and $F(50) = 338079744$.\n\nFind $F(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nThe inversion count of a sequence of digits is the smallest number of adjacent pairs that must be swapped to sort the sequence.
    \nFor example, $34214$ has inversion count of $5$:\n$34214 \\to 32414 \\to 23414 \\to 23144 \\to 21344 \\to12344$.\n

    \n

    \nIf each digit of a sequence is replaced by one of its divisors a divided sequence is obtained.
    \nFor example, the sequence $332$ has $8$ divided sequences: $\\{332,331,312,311,132,131,112,111\\}$.\n

    \n

    \nDefine $G(N)$ to be the concatenation of all primes less than $N$, ignoring any zero digit.
    \nFor example, $G(20) = 235711131719$.\n

    \n

    \nDefine $F(N)$ to be the sum of the inversion count for all possible divided sequences from the master sequence $G(N)$.
    \nYou are given $F(20) = 3312$ and $F(50) = 338079744$.\n

    \n

    \nFind $F(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=705", "answer": "480440153"} {"id": 706, "problem": "For a positive integer $n$, define $f(n)$ to be the number of non-empty substrings of $n$ that are divisible by $3$. For example, the string \"2573\" has $10$ non-empty substrings, three of which represent numbers that are divisible by $3$, namely $57$, $573$ and $3$. So $f(2573) = 3$.\n\nIf $f(n)$ is divisible by $3$ then we say that $n$ is $3$-like.\n\nDefine $F(d)$ to be how many $d$ digit numbers are $3$-like. For example, $F(2) = 30$ and $F(6) = 290898$.\n\nFind $F(10^5)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nFor a positive integer $n$, define $f(n)$ to be the number of non-empty substrings of $n$ that are divisible by $3$. For example, the string \"2573\" has $10$ non-empty substrings, three of which represent numbers that are divisible by $3$, namely $57$, $573$ and $3$. So $f(2573) = 3$.\n

    \n

    \nIf $f(n)$ is divisible by $3$ then we say that $n$ is $3$-like.\n

    \n

    \nDefine $F(d)$ to be how many $d$ digit numbers are $3$-like. For example, $F(2) = 30$ and $F(6) = 290898$.\n

    \n

    \nFind $F(10^5)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=706", "answer": "884837055"} {"id": 707, "problem": "Consider a $w\\times h$ grid. A cell is either ON or OFF. When a cell is selected, that cell and all cells connected to that cell by an edge are toggled on-off, off-on. See the diagram for the 3 cases of selecting a corner cell, an edge cell or central cell in a grid that has all cells on (white).\n\nThe goal is to get every cell to be off simultaneously. This is not possible for all starting states. A state is solvable if, by a process of selecting cells, the goal can be achieved.\n\nLet $F(w,h)$ be the number of solvable states for a $w\\times h$ grid.\nYou are given $F(1,2)=2$, $F(3,3) = 512$, $F(4,4) = 4096$ and $F(7,11) \\equiv 270016253 \\pmod{1\\,000\\,000\\,007}$.\n\nLet $f_1=f_2 = 1$ and $f_n=f_{n-1}+f_{n-2}, n \\ge 3$ be the Fibonacci sequence and define\n$$ S(w,n) = \\sum_{k=1}^n F(w,f_k)$$\nYou are given $S(3,3) = 32$, $S(4,5) = 1052960$ and $S(5,7) \\equiv 346547294 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $S(199,199)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nConsider a $w\\times h$ grid. A cell is either ON or OFF. When a cell is selected, that cell and all cells connected to that cell by an edge are toggled on-off, off-on. See the diagram for the 3 cases of selecting a corner cell, an edge cell or central cell in a grid that has all cells on (white).\n

    \n
    \n\"LightsOut\"\n
    \n

    The goal is to get every cell to be off simultaneously. This is not possible for all starting states. A state is solvable if, by a process of selecting cells, the goal can be achieved.\n

    \n

    \nLet $F(w,h)$ be the number of solvable states for a $w\\times h$ grid. \nYou are given $F(1,2)=2$, $F(3,3) = 512$, $F(4,4) = 4096$ and $F(7,11) \\equiv 270016253 \\pmod{1\\,000\\,000\\,007}$.\n

    \n

    \nLet $f_1=f_2 = 1$ and $f_n=f_{n-1}+f_{n-2}, n \\ge 3$ be the Fibonacci sequence and define \n$$ S(w,n) = \\sum_{k=1}^n F(w,f_k)$$\nYou are given $S(3,3) = 32$, $S(4,5) = 1052960$ and $S(5,7) \\equiv 346547294 \\pmod{1\\,000\\,000\\,007}$.\n

    \n

    \nFind $S(199,199)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=707", "answer": "652907799"} {"id": 708, "problem": "A positive integer, $n$, is factorised into prime factors. We define $f(n)$ to be the product when each prime factor is replaced with $2$. In addition we define $f(1)=1$.\n\nFor example, $90 = 2\\times 3\\times 3\\times 5$, then replacing the primes, $2\\times 2\\times 2\\times 2 = 16$, hence $f(90) = 16$.\n\n\n\nLet $\\displaystyle S(N)=\\sum_{n=1}^{N} f(n)$. You are given $S(10^8)=9613563919$.\n\n\n\nFind $S(10^{14})$.", "raw_html": "

    A positive integer, $n$, is factorised into prime factors. We define $f(n)$ to be the product when each prime factor is replaced with $2$. In addition we define $f(1)=1$.

    \n\n

    For example, $90 = 2\\times 3\\times 3\\times 5$, then replacing the primes, $2\\times 2\\times 2\\times 2 = 16$, hence $f(90) = 16$.

    \n \n

    Let $\\displaystyle S(N)=\\sum_{n=1}^{N} f(n)$. You are given $S(10^8)=9613563919$.

    \n\n

    Find $S(10^{14})$.

    ", "url": "https://projecteuler.net/problem=708", "answer": "28874142998632109"} {"id": 709, "problem": "Every day for the past $n$ days Even Stevens brings home his groceries in a plastic bag. He stores these plastic bags in a cupboard. He either puts the plastic bag into the cupboard with the rest, or else he takes an even number of the existing bags (which may either be empty or previously filled with other bags themselves) and places these into the current bag.\n\nAfter 4 days there are 5 possible packings and if the bags are numbered 1 (oldest), 2, 3, 4, they are:\n\n- Four empty bags,\n\n- 1 and 2 inside 3, 4 empty,\n\n- 1 and 3 inside 4, 2 empty,\n\n- 1 and 2 inside 4, 3 empty,\n\n- 2 and 3 inside 4, 1 empty.\n\nNote that 1, 2, 3 inside 4 is invalid because every bag must contain an even number of bags.\n\nDefine $f(n)$ to be the number of possible packings of $n$ bags. Hence $f(4)=5$. You are also given $f(8)=1\\,385$.\n\nFind $f(24\\,680)$ giving your answer modulo $1\\,020\\,202\\,009$.", "raw_html": "

    Every day for the past $n$ days Even Stevens brings home his groceries in a plastic bag. He stores these plastic bags in a cupboard. He either puts the plastic bag into the cupboard with the rest, or else he takes an even number of the existing bags (which may either be empty or previously filled with other bags themselves) and places these into the current bag.

    \n\n

    After 4 days there are 5 possible packings and if the bags are numbered 1 (oldest), 2, 3, 4, they are:

    \n
      \n
    • Four empty bags,
    • \n
    • 1 and 2 inside 3, 4 empty,
    • \n
    • 1 and 3 inside 4, 2 empty,
    • \n
    • 1 and 2 inside 4, 3 empty,
    • \n
    • 2 and 3 inside 4, 1 empty.
    • \n
    \n

    Note that 1, 2, 3 inside 4 is invalid because every bag must contain an even number of bags.

    \n\n

    Define $f(n)$ to be the number of possible packings of $n$ bags. Hence $f(4)=5$. You are also given $f(8)=1\\,385$.

    \n\n

    Find $f(24\\,680)$ giving your answer modulo $1\\,020\\,202\\,009$.

    ", "url": "https://projecteuler.net/problem=709", "answer": "773479144"} {"id": 710, "problem": "On Sunday 5 April 2020 the Project Euler membership first exceeded one million members. We would like to present this problem to celebrate that milestone. Thank you to everyone for being a part of Project Euler.\n\nThe number 6 can be written as a palindromic sum in exactly eight different ways:\n\n$$(1, 1, 1, 1, 1, 1), (1, 1, 2, 1, 1), (1, 2, 2, 1), (1, 4, 1), (2, 1, 1, 2), (2, 2, 2), (3, 3), (6)$$\n\nWe shall define a twopal to be a palindromic tuple having at least one element with a value of 2. It should also be noted that elements are not restricted to single digits. For example, $(3, 2, 13, 6, 13, 2, 3)$ is a valid twopal.\n\nIf we let $t(n)$ be the number of twopals whose elements sum to $n$, then it can be seen that $t(6) = 4$:\n\n$$(1, 1, 2, 1, 1), (1, 2, 2, 1), (2, 1, 1, 2), (2, 2, 2)$$\n\nSimilarly, $t(20) = 824$.\n\nIn searching for the answer to the ultimate question of life, the universe, and everything, it can be verified that $t(42) = 1999923$, which happens to be the first value of $t(n)$ that exceeds one million.\n\nHowever, your challenge to the \"ultimatest\" question of life, the universe, and everything is to find the least value of $n \\gt 42$ such that $t(n)$ is divisible by one million.", "raw_html": "

    On Sunday 5 April 2020 the Project Euler membership first exceeded one million members. We would like to present this problem to celebrate that milestone. Thank you to everyone for being a part of Project Euler.

    \n\n

    The number 6 can be written as a palindromic sum in exactly eight different ways:

    \n$$(1, 1, 1, 1, 1, 1), (1, 1, 2, 1, 1), (1, 2, 2, 1), (1, 4, 1), (2, 1, 1, 2), (2, 2, 2), (3, 3), (6)$$\n\n

    We shall define a twopal to be a palindromic tuple having at least one element with a value of 2. It should also be noted that elements are not restricted to single digits. For example, $(3, 2, 13, 6, 13, 2, 3)$ is a valid twopal.

    \n\n

    If we let $t(n)$ be the number of twopals whose elements sum to $n$, then it can be seen that $t(6) = 4$:

    \n$$(1, 1, 2, 1, 1), (1, 2, 2, 1), (2, 1, 1, 2), (2, 2, 2)$$\n\n

    Similarly, $t(20) = 824$.

    \n\n

    In searching for the answer to the ultimate question of life, the universe, and everything, it can be verified that $t(42) = 1999923$, which happens to be the first value of $t(n)$ that exceeds one million.

    \n\n

    However, your challenge to the \"ultimatest\" question of life, the universe, and everything is to find the least value of $n \\gt 42$ such that $t(n)$ is divisible by one million.

    ", "url": "https://projecteuler.net/problem=710", "answer": "1275000"} {"id": 711, "problem": "Oscar and Eric play the following game. First, they agree on a positive integer $n$, and they begin by writing its binary representation on a blackboard. They then take turns, with Oscar going first, to write a number on the blackboard in binary representation, such that the sum of all written numbers does not exceed $2n$.\n\nThe game ends when there are no valid moves left. Oscar wins if the number of $1$s on the blackboard is odd, and Eric wins if it is even.\n\nLet $S(N)$ be the sum of all $n \\le 2^N$ for which Eric can guarantee winning, assuming optimal play.\n\nFor example, the first few values of $n$ for which Eric can guarantee winning are $1,3,4,7,15,16$. Hence $S(4)=46$.\n\nYou are also given that $S(12) = 54532$ and $S(1234) \\equiv 690421393 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $S(12\\,345\\,678)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Oscar and Eric play the following game. First, they agree on a positive integer $n$, and they begin by writing its binary representation on a blackboard. They then take turns, with Oscar going first, to write a number on the blackboard in binary representation, such that the sum of all written numbers does not exceed $2n$.

    \n\n

    The game ends when there are no valid moves left. Oscar wins if the number of $1$s on the blackboard is odd, and Eric wins if it is even.

    \n\n

    Let $S(N)$ be the sum of all $n \\le 2^N$ for which Eric can guarantee winning, assuming optimal play.

    \n\n

    For example, the first few values of $n$ for which Eric can guarantee winning are $1,3,4,7,15,16$. Hence $S(4)=46$.
    \nYou are also given that $S(12) = 54532$ and $S(1234) \\equiv 690421393 \\pmod{1\\,000\\,000\\,007}$.

    \n\n

    Find $S(12\\,345\\,678)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=711", "answer": "541510990"} {"id": 712, "problem": "For any integer $n>0$ and prime number $p,$ define $\\nu_p(n)$ as the greatest integer $r$ such that $p^r$ divides $n$.\n\nDefine $$D(n, m) = \\sum_{p \\text{ prime}} \\left| \\nu_p(n) - \\nu_p(m)\\right|.$$ For example, $D(14,24) = 4$.\n\nFurthermore, define $$S(N) = \\sum_{1 \\le n, m \\le N} D(n, m).$$ You are given $S(10) = 210$ and $S(10^2) = 37018$.\n\nFind $S(10^{12})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nFor any integer $n>0$ and prime number $p,$ define $\\nu_p(n)$ as the greatest integer $r$ such that $p^r$ divides $n$. \n

    \n

    \nDefine $$D(n, m) = \\sum_{p \\text{ prime}} \\left| \\nu_p(n) - \\nu_p(m)\\right|.$$ For example, $D(14,24) = 4$.\n

    \n

    \nFurthermore, define $$S(N) = \\sum_{1 \\le n, m \\le N} D(n, m).$$ You are given $S(10) = 210$ and $S(10^2) = 37018$.\n

    \n

    \nFind $S(10^{12})$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=712", "answer": "413876461"} {"id": 713, "problem": "Turan has the electrical water heating system outside his house in a shed. The electrical system uses two fuses in series, one in the house and one in the shed. (Nowadays old fashioned fuses are often replaced with reusable mini circuit breakers, but Turan's system still uses old fashioned fuses.)\nFor the heating system to work both fuses must work.\n\nTuran has $N$ fuses. He knows that $m$ of them are working and the rest are blown. However, he doesn't know which ones are blown. So he tries different combinations until the heating system turns on.\n\nWe denote by $T(N,m)$ the smallest number of tries required to ensure the heating system turns on.\n\n$T(3,2)=3$ and $T(8,4)=7$.\n\nLet $L(N)$ be the sum of all $T(N, m)$ for $2 \\leq m \\leq N$.\n\n$L(10^3)=3281346$.\n\nFind $L(10^7)$.", "raw_html": "

    \nTuran has the electrical water heating system outside his house in a shed. The electrical system uses two fuses in series, one in the house and one in the shed. (Nowadays old fashioned fuses are often replaced with reusable mini circuit breakers, but Turan's system still uses old fashioned fuses.)\nFor the heating system to work both fuses must work.\n

    \n

    \nTuran has $N$ fuses. He knows that $m$ of them are working and the rest are blown. However, he doesn't know which ones are blown. So he tries different combinations until the heating system turns on.
    \nWe denote by $T(N,m)$ the smallest number of tries required to ensure the heating system turns on.
    \n$T(3,2)=3$ and $T(8,4)=7$.\n

    \n

    \nLet $L(N)$ be the sum of all $T(N, m)$ for $2 \\leq m \\leq N$.
    \n$L(10^3)=3281346$.\n

    \n

    \nFind $L(10^7)$.\n

    ", "url": "https://projecteuler.net/problem=713", "answer": "788626351539895"} {"id": 714, "problem": "We call a natural number a duodigit if its decimal representation uses no more than two different digits.\nFor example, $12$, $110$ and $33333$ are duodigits, while $102$ is not.\n\nIt can be shown that every natural number has duodigit multiples. Let $d(n)$ be the smallest (positive) multiple of the number $n$ that happens to be a duodigit. For example, $d(12)=12$, $d(102)=1122$, $d(103)=515$, $d(290)=11011010$ and $d(317)=211122$.\n\nLet $\\displaystyle D(k)=\\sum_{n=1}^k d(n)$. You are given $D(110)=11\\,047$, $D(150)=53\\,312$ and $D(500)=29\\,570\\,988$.\n\nFind $D(50\\,000)$. Give your answer in scientific notation rounded to $13$ significant digits ($12$ after the decimal point). If, for example, we had asked for $D(500)$ instead, the answer format would have been 2.957098800000e7.", "raw_html": "

    We call a natural number a duodigit if its decimal representation uses no more than two different digits.\nFor example, $12$, $110$ and $33333$ are duodigits, while $102$ is not.
    \nIt can be shown that every natural number has duodigit multiples. Let $d(n)$ be the smallest (positive) multiple of the number $n$ that happens to be a duodigit. For example, $d(12)=12$, $d(102)=1122$, $d(103)=515$, $d(290)=11011010$ and $d(317)=211122$.

    \n

    \nLet $\\displaystyle D(k)=\\sum_{n=1}^k d(n)$. You are given $D(110)=11\\,047$, $D(150)=53\\,312$ and $D(500)=29\\,570\\,988$.

    \n

    \nFind $D(50\\,000)$. Give your answer in scientific notation rounded to $13$ significant digits ($12$ after the decimal point). If, for example, we had asked for $D(500)$ instead, the answer format would have been 2.957098800000e7.

    ", "url": "https://projecteuler.net/problem=714", "answer": "2.452767775565e20"} {"id": 715, "problem": "Let $f(n)$ be the number of $6$-tuples $(x_1,x_2,x_3,x_4,x_5,x_6)$ such that:\n\n- All $x_i$ are integers with $0 \\leq x_i < n$\n\n- $\\gcd(x_1^2+x_2^2+x_3^2+x_4^2+x_5^2+x_6^2,\\ n^2)=1$\n\nLet $\\displaystyle G(n)=\\displaystyle\\sum_{k=1}^n \\frac{f(k)}{k^2\\varphi(k)}$\n\nwhere $\\varphi(n)$ is Euler's totient function.\n\nFor example, $G(10)=3053$ and $G(10^5) \\equiv 157612967 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $G(10^{12})\\bmod 1\\,000\\,000\\,007$.", "raw_html": "

    Let $f(n)$ be the number of $6$-tuples $(x_1,x_2,x_3,x_4,x_5,x_6)$ such that:

    \n
      \n
    • All $x_i$ are integers with $0 \\leq x_i < n$
    • \n
    • $\\gcd(x_1^2+x_2^2+x_3^2+x_4^2+x_5^2+x_6^2,\\ n^2)=1$
    • \n
    \n\n

    Let $\\displaystyle G(n)=\\displaystyle\\sum_{k=1}^n \\frac{f(k)}{k^2\\varphi(k)}$
    \nwhere $\\varphi(n)$ is Euler's totient function.

    \n\n

    For example, $G(10)=3053$ and $G(10^5) \\equiv 157612967 \\pmod{1\\,000\\,000\\,007}$.

    \n\n

    Find $G(10^{12})\\bmod 1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=715", "answer": "883188017"} {"id": 716, "problem": "Consider a directed graph made from an orthogonal lattice of $H\\times W$ nodes.\nThe edges are the horizontal and vertical connections between adjacent nodes.\n$W$ vertical directed lines are drawn and all the edges on these lines inherit that direction. Similarly, $H$ horizontal directed lines are drawn and all the edges on these lines inherit that direction.\n\nTwo nodes, $A$ and $B$ in a directed graph, are strongly connected if there is both a path, along the directed edges, from $A$ to $B$ as well as from $B$ to $A$. Note that every node is strongly connected to itself.\n\nA strongly connected component in a directed graph is a non-empty set $M$ of nodes satisfying the following two properties:\n\n- All nodes in $M$ are strongly connected to each other.\n\n- $M$ is maximal, in the sense that no node in $M$ is strongly connected to any node outside of $M$.\n\nThere are $2^H\\times 2^W$ ways of drawing the directed lines. Each way gives a directed graph $\\mathcal{G}$. We define $S(\\mathcal{G})$ to be the number of strongly connected components in $\\mathcal{G}$.\n\nThe illustration below shows a directed graph with $H=3$ and $W=4$ that consists of four different strongly connected components (indicated by the different colours).\n\nDefine $C(H,W)$ to be the sum of $S(\\mathcal{G})$ for all possible graphs on a grid of $H\\times W$. You are given $C(3,3) = 408$, $C(3,6) = 4696$ and $C(10,20) \\equiv 988971143 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $C(10\\,000,20\\,000)$ giving your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nConsider a directed graph made from an orthogonal lattice of $H\\times W$ nodes. \nThe edges are the horizontal and vertical connections between adjacent nodes.\n$W$ vertical directed lines are drawn and all the edges on these lines inherit that direction. Similarly, $H$ horizontal directed lines are drawn and all the edges on these lines inherit that direction.\n

    \n

    \nTwo nodes, $A$ and $B$ in a directed graph, are strongly connected if there is both a path, along the directed edges, from $A$ to $B$ as well as from $B$ to $A$. Note that every node is strongly connected to itself.\n

    \n

    \nA strongly connected component in a directed graph is a non-empty set $M$ of nodes satisfying the following two properties:\n

    \n
      \n
    • All nodes in $M$ are strongly connected to each other.
    • \n
    • $M$ is maximal, in the sense that no node in $M$ is strongly connected to any node outside of $M$.
    • \n
    \n

    \nThere are $2^H\\times 2^W$ ways of drawing the directed lines. Each way gives a directed graph $\\mathcal{G}$. We define $S(\\mathcal{G})$ to be the number of strongly connected components in $\\mathcal{G}$.\n

    \n

    \nThe illustration below shows a directed graph with $H=3$ and $W=4$ that consists of four different strongly connected components (indicated by the different colours).\n

    \n
    \n\"\"
    \n

    \nDefine $C(H,W)$ to be the sum of $S(\\mathcal{G})$ for all possible graphs on a grid of $H\\times W$. You are given $C(3,3) = 408$, $C(3,6) = 4696$ and $C(10,20) \\equiv 988971143 \\pmod{1\\,000\\,000\\,007}$.\n

    \n

    \nFind $C(10\\,000,20\\,000)$ giving your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=716", "answer": "238948623"} {"id": 717, "problem": "For an odd prime $p$, define $f(p) = \\left\\lfloor\\frac{2^{(2^p)}}{p}\\right\\rfloor\\bmod{2^p}$\n\nFor example, when $p=3$, $\\lfloor 2^8/3\\rfloor = 85 \\equiv 5 \\pmod 8$ and so $f(3) = 5$.\n\n\n\nFurther define $g(p) = f(p)\\bmod p$. You are given $g(31) = 17$.\n\nNow define $G(N)$ to be the summation of $g(p)$ for all odd primes less than $N$.\n\nYou are given $G(100) = 474$ and $G(10^4) = 2819236$.\n\nFind $G(10^7)$.", "raw_html": "

    For an odd prime $p$, define $f(p) = \\left\\lfloor\\frac{2^{(2^p)}}{p}\\right\\rfloor\\bmod{2^p}$
    \nFor example, when $p=3$, $\\lfloor 2^8/3\\rfloor = 85 \\equiv 5 \\pmod 8$ and so $f(3) = 5$.

    \n\n

    Further define $g(p) = f(p)\\bmod p$. You are given $g(31) = 17$.

    \n\n

    Now define $G(N)$ to be the summation of $g(p)$ for all odd primes less than $N$.
    \nYou are given $G(100) = 474$ and $G(10^4) = 2819236$.

    \n\n

    Find $G(10^7)$.

    ", "url": "https://projecteuler.net/problem=717", "answer": "1603036763131"} {"id": 718, "problem": "Consider the equation\n$17^pa+19^pb+23^pc = n$ where $a$, $b$, $c$ and $p$ are positive integers, i.e.\n$a,b,c,p \\gt 0$.\n\nFor a given $p$ there are some values of $n > 0$ for which the equation cannot be solved. We call these unreachable values.\n\nDefine $G(p)$ to be the sum of all unreachable values of $n$ for the given value of $p$. For example $G(1) = 8253$ and $G(2)= 60258000$.\n\nFind $G(6)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Consider the equation\n$17^pa+19^pb+23^pc = n$ where $a$, $b$, $c$ and $p$ are positive integers, i.e.\n$a,b,c,p \\gt 0$.

    \n\n

    For a given $p$ there are some values of $n > 0$ for which the equation cannot be solved. We call these unreachable values.

    \n\n

    Define $G(p)$ to be the sum of all unreachable values of $n$ for the given value of $p$. For example $G(1) = 8253$ and $G(2)= 60258000$.

    \n\n

    Find $G(6)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=718", "answer": "228579116"} {"id": 719, "problem": "We define an $S$-number to be a natural number, $n$, that is a perfect square and its square root can be obtained by splitting the decimal representation of $n$ into $2$ or more numbers then adding the numbers.\n\nFor example, $81$ is an $S$-number because $\\sqrt{81} = 8+1$.\n\n$6724$ is an $S$-number: $\\sqrt{6724} = 6+72+4$.\n\n$8281$ is an $S$-number: $\\sqrt{8281} = 8+2+81 = 82+8+1$.\n\n$9801$ is an $S$-number: $\\sqrt{9801}=98+0+1$.\n\nFurther we define $T(N)$ to be the sum of all $S$ numbers $n\\le N$. You are given $T(10^4) = 41333$.\n\nFind $T(10^{12})$.", "raw_html": "

    \nWe define an $S$-number to be a natural number, $n$, that is a perfect square and its square root can be obtained by splitting the decimal representation of $n$ into $2$ or more numbers then adding the numbers.\n

    \n

    \nFor example, $81$ is an $S$-number because $\\sqrt{81} = 8+1$.
    \n$6724$ is an $S$-number: $\\sqrt{6724} = 6+72+4$.
    \n$8281$ is an $S$-number: $\\sqrt{8281} = 8+2+81 = 82+8+1$.
    \n$9801$ is an $S$-number: $\\sqrt{9801}=98+0+1$.\n

    \n

    \nFurther we define $T(N)$ to be the sum of all $S$ numbers $n\\le N$. You are given $T(10^4) = 41333$.\n

    \n

    \nFind $T(10^{12})$.\n

    ", "url": "https://projecteuler.net/problem=719", "answer": "128088830547982"} {"id": 720, "problem": "Consider all permutations of $\\{1, 2, \\ldots N\\}$, listed in lexicographic order.\nFor example, for $N=4$, the list starts as follows:\n\n$$\\displaylines{\n(1, 2, 3, 4) \\\\\n(1, 2, 4, 3) \\\\\n(1, 3, 2, 4) \\\\\n(1, 3, 4, 2) \\\\\n(1, 4, 2, 3) \\\\\n(1, 4, 3, 2) \\\\\n(2, 1, 3, 4) \\\\\n\\vdots\n}$$\n\nLet us call a permutation $P$ unpredictable if there is no choice of three indices $i \\lt j \\lt k$ such that $P(i)$, $P(j)$ and $P(k)$ constitute an arithmetic progression.\nFor example, $P=(3, 4, 2, 1)$ is not unpredictable because $P(1), P(3), P(4)$ is an arithmetic progression.\n\nLet $S(N)$ be the position within the list of the first unpredictable permutation.\n\nFor example, given $N = 4$, the first unpredictable permutation is $(1, 3, 2, 4)$ so $S(4) = 3$.\n\nYou are also given that $S(8) = 2295$ and $S(32) \\equiv 641839205 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $S(2^{25})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Consider all permutations of $\\{1, 2, \\ldots N\\}$, listed in lexicographic order.
    For example, for $N=4$, the list starts as follows:

    \n
    \n$$\\displaylines{\n(1, 2, 3, 4) \\\\\n(1, 2, 4, 3) \\\\\n(1, 3, 2, 4) \\\\\n(1, 3, 4, 2) \\\\\n(1, 4, 2, 3) \\\\\n(1, 4, 3, 2) \\\\\n(2, 1, 3, 4) \\\\\n\\vdots\n}$$\n
    \n

    \nLet us call a permutation $P$ unpredictable if there is no choice of three indices $i \\lt j \\lt k$ such that $P(i)$, $P(j)$ and $P(k)$ constitute an arithmetic progression.
    For example, $P=(3, 4, 2, 1)$ is not unpredictable because $P(1), P(3), P(4)$ is an arithmetic progression.\n

    \n

    \nLet $S(N)$ be the position within the list of the first unpredictable permutation.\n

    \n\n

    \nFor example, given $N = 4$, the first unpredictable permutation is $(1, 3, 2, 4)$ so $S(4) = 3$.
    \nYou are also given that $S(8) = 2295$ and $S(32) \\equiv 641839205 \\pmod{1\\,000\\,000\\,007}$.\n

    \n

    \nFind $S(2^{25})$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=720", "answer": "688081048"} {"id": 721, "problem": "Given is the function $f(a,n)=\\lfloor (\\lceil \\sqrt a \\rceil + \\sqrt a)^n \\rfloor$.\n\n$\\lfloor \\cdot \\rfloor$ denotes the floor function and $\\lceil \\cdot \\rceil$ denotes the ceiling function.\n\n$f(5,2)=27$ and $f(5,5)=3935$.\n\n$G(n) = \\displaystyle \\sum_{a=1}^n f(a, a^2).$\n\n$G(1000) \\bmod 999\\,999\\,937=163861845. $\n\nFind $G(5\\,000\\,000).$ Give your answer modulo $999\\,999\\,937$.", "raw_html": "

    \nGiven is the function $f(a,n)=\\lfloor (\\lceil \\sqrt a \\rceil + \\sqrt a)^n \\rfloor$.
    \n$\\lfloor \\cdot \\rfloor$ denotes the floor function and $\\lceil \\cdot \\rceil$ denotes the ceiling function.
    \n$f(5,2)=27$ and $f(5,5)=3935$.\n

    \n

    \n$G(n) = \\displaystyle \\sum_{a=1}^n f(a, a^2).$
    \n$G(1000) \\bmod 999\\,999\\,937=163861845. $
    \nFind $G(5\\,000\\,000).$ Give your answer modulo $999\\,999\\,937$.\n

    ", "url": "https://projecteuler.net/problem=721", "answer": "700792959"} {"id": 722, "problem": "For a non-negative integer $k$, define\n$$\nE_k(q) = \\sum\\limits_{n = 1}^\\infty \\sigma_k(n)q^n\n$$\nwhere $\\sigma_k(n) = \\sum_{d \\mid n} d^k$ is the sum of the $k$-th powers of the positive divisors of $n$.\n\nIt can be shown that, for every $k$, the series $E_k(q)$ converges for any $0 < q < 1$.\n\nFor example,\n\n$E_1(1 - \\frac{1}{2^4}) = 3.872155809243\\mathrm e2$\n\n$E_3(1 - \\frac{1}{2^8}) = 2.767385314772\\mathrm e10$\n\n$E_7(1 - \\frac{1}{2^{15}}) = 6.725803486744\\mathrm e39$\n\nAll the above values are given in scientific notation rounded to twelve digits after the decimal point.\n\nFind the value of $E_{15}(1 - \\frac{1}{2^{25}})$.\n\nGive the answer in scientific notation rounded to twelve digits after the decimal point.", "raw_html": "

    For a non-negative integer $k$, define\n$$\nE_k(q) = \\sum\\limits_{n = 1}^\\infty \\sigma_k(n)q^n\n$$\nwhere $\\sigma_k(n) = \\sum_{d \\mid n} d^k$ is the sum of the $k$-th powers of the positive divisors of $n$.

    \n\n

    It can be shown that, for every $k$, the series $E_k(q)$ converges for any $0 < q < 1$.

    \n\n

    For example,
    \n$E_1(1 - \\frac{1}{2^4}) = 3.872155809243\\mathrm e2$
    \n$E_3(1 - \\frac{1}{2^8}) = 2.767385314772\\mathrm e10$
    \n$E_7(1 - \\frac{1}{2^{15}}) = 6.725803486744\\mathrm e39$
    \nAll the above values are given in scientific notation rounded to twelve digits after the decimal point.

    \n\n

    Find the value of $E_{15}(1 - \\frac{1}{2^{25}})$.
    \nGive the answer in scientific notation rounded to twelve digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=722", "answer": "3.376792776502e132"} {"id": 723, "problem": "A pythagorean triangle with catheti $a$ and $b$ and hypotenuse $c$ is characterized by the well-known equation $a^2+b^2=c^2$. However, this can also be formulated differently:\n\nWhen inscribed into a circle with radius $r$, a triangle with sides $a$, $b$ and $c$ is pythagorean, if and only if $a^2+b^2+c^2=8\\, r^2$.\n\nAnalogously, we call a quadrilateral $ABCD$ with sides $a$, $b$, $c$ and $d$, inscribed in a circle with radius $r$, a pythagorean quadrilateral, if $a^2+b^2+c^2+d^2=8\\, r^2$.\n\nWe further call a pythagorean quadrilateral a pythagorean lattice grid quadrilateral, if all four vertices are lattice grid points with the same distance $r$ from the origin $O$ (which then happens to be the centre of the circumcircle).\n\nLet $f(r)$ be the number of different pythagorean lattice grid quadrilaterals for which the radius of the circumcircle is $r$. For example $f(1)=1$, $f(\\sqrt 2)=1$, $f(\\sqrt 5)=38$ and $f(5)=167$.\n\nTwo of the pythagorean lattice grid quadrilaterals with $r=\\sqrt 5$ are illustrated below:\n\nLet $\\displaystyle S(n)=\\sum_{d \\mid n} f(\\sqrt d)$. For example, $S(325)=S(5^2 \\cdot 13)=f(1)+f(\\sqrt 5)+f(5)+f(\\sqrt {13})+f(\\sqrt{65})+f(5\\sqrt{13})=2370$ and $S(1105)=S(5\\cdot 13 \\cdot 17)=5535$.\n\nFind $S(1411033124176203125)=S(5^6 \\cdot 13^3 \\cdot 17^2 \\cdot 29 \\cdot 37 \\cdot 41 \\cdot 53 \\cdot 61)$.", "raw_html": "

    A pythagorean triangle with catheti $a$ and $b$ and hypotenuse $c$ is characterized by the well-known equation $a^2+b^2=c^2$. However, this can also be formulated differently:
    \nWhen inscribed into a circle with radius $r$, a triangle with sides $a$, $b$ and $c$ is pythagorean, if and only if $a^2+b^2+c^2=8\\, r^2$.

    \n\n

    Analogously, we call a quadrilateral $ABCD$ with sides $a$, $b$, $c$ and $d$, inscribed in a circle with radius $r$, a pythagorean quadrilateral, if $a^2+b^2+c^2+d^2=8\\, r^2$.
    \nWe further call a pythagorean quadrilateral a pythagorean lattice grid quadrilateral, if all four vertices are lattice grid points with the same distance $r$ from the origin $O$ (which then happens to be the centre of the circumcircle).

    \n

    \nLet $f(r)$ be the number of different pythagorean lattice grid quadrilaterals for which the radius of the circumcircle is $r$. For example $f(1)=1$, $f(\\sqrt 2)=1$, $f(\\sqrt 5)=38$ and $f(5)=167$.
    \nTwo of the pythagorean lattice grid quadrilaterals with $r=\\sqrt 5$ are illustrated below:

    \n
    \n\"PythagoreanQ_1\"\n
    \n
    \n
    \n\"PythagoreanQ_2\"\n
    \n

    \nLet $\\displaystyle S(n)=\\sum_{d \\mid n} f(\\sqrt d)$. For example, $S(325)=S(5^2 \\cdot 13)=f(1)+f(\\sqrt 5)+f(5)+f(\\sqrt {13})+f(\\sqrt{65})+f(5\\sqrt{13})=2370$ and $S(1105)=S(5\\cdot 13 \\cdot 17)=5535$.

    \n

    \nFind $S(1411033124176203125)=S(5^6 \\cdot 13^3 \\cdot 17^2 \\cdot 29 \\cdot 37 \\cdot 41 \\cdot 53 \\cdot 61)$.

    ", "url": "https://projecteuler.net/problem=723", "answer": "1395793419248"} {"id": 724, "problem": "A depot uses $n$ drones to disperse packages containing essential supplies along a long straight road.\n\nInitially all drones are stationary, loaded with a supply package.\n\nEvery second, the depot selects a drone at random and sends it this instruction:\n\n- If you are stationary, start moving at one centimetre per second along the road.\n\n- If you are moving, increase your speed by one centimetre per second along the road without changing direction.\n\nThe road is wide enough that drones can overtake one another without risk of collision.\n\nEventually, there will only be one drone left at the depot waiting to receive its first instruction. As soon as that drone has flown one centimetre along the road, all drones drop their packages and return to the depot.\n\nLet $E(n)$ be the expected distance in centimetres from the depot that the supply packages land.\n\nFor example, $E(2) = \\frac{7}{2}$, $E(5) = \\frac{12019}{720}$, and $E(100) \\approx 1427.193470$.\n\nFind $E(10^8)$. Give your answer rounded to the nearest integer.", "raw_html": "

    A depot uses $n$ drones to disperse packages containing essential supplies along a long straight road.
    \nInitially all drones are stationary, loaded with a supply package.
    \nEvery second, the depot selects a drone at random and sends it this instruction:

    \n
      \n
    • If you are stationary, start moving at one centimetre per second along the road.
    • \n
    • If you are moving, increase your speed by one centimetre per second along the road without changing direction.
    • \n
    \n

    The road is wide enough that drones can overtake one another without risk of collision.

    \n

    Eventually, there will only be one drone left at the depot waiting to receive its first instruction. As soon as that drone has flown one centimetre along the road, all drones drop their packages and return to the depot.

    \n\n

    Let $E(n)$ be the expected distance in centimetres from the depot that the supply packages land.
    \nFor example, $E(2) = \\frac{7}{2}$, $E(5) = \\frac{12019}{720}$, and $E(100) \\approx 1427.193470$.

    \n

    Find $E(10^8)$. Give your answer rounded to the nearest integer.

    ", "url": "https://projecteuler.net/problem=724", "answer": "18128250110"} {"id": 725, "problem": "A number where one digit is the sum of the other digits is called a digit sum number or DS-number for short. For example, $352$, $3003$ and $32812$ are DS-numbers.\n\nWe define $S(n)$ to be the sum of all DS-numbers of $n$ digits or less.\n\nYou are given $S(3) = 63270$ and $S(7) = 85499991450$.\n\nFind $S(2020)$. Give your answer modulo $10^{16}$.", "raw_html": "

    \nA number where one digit is the sum of the other digits is called a digit sum number or DS-number for short. For example, $352$, $3003$ and $32812$ are DS-numbers.\n

    \n

    \nWe define $S(n)$ to be the sum of all DS-numbers of $n$ digits or less.\n

    \n

    \nYou are given $S(3) = 63270$ and $S(7) = 85499991450$.\n

    \n

    \nFind $S(2020)$. Give your answer modulo $10^{16}$.\n

    ", "url": "https://projecteuler.net/problem=725", "answer": "4598797036650685"} {"id": 726, "problem": "Consider a stack of bottles of wine. There are $n$ layers in the stack with the top layer containing only one bottle and the bottom layer containing $n$ bottles. For $n=4$ the stack looks like the picture below.\n\nThe collapsing process happens every time a bottle is taken. A space is created in the stack and that space is filled according to the following recursive steps:\n\n- No bottle touching from above: nothing happens. For example, taking $F$.\n\n- One bottle touching from above: that will drop down to fill the space creating another space. For example, taking $D$.\n\n- Two bottles touching from above: one will drop down to fill the space creating another space. For example, taking $C$.\n\nThis process happens recursively; for example, taking bottle $A$ in the diagram above. Its place can be filled with either $B$ or $C$. If it is filled with $C$ then the space that $C$ creates can be filled with $D$ or $E$. So there are 3 different collapsing processes that can happen if $A$ is taken, although the final shape (in this case) is the same.\n\nDefine $f(n)$ to be the number of ways that we can take all the bottles from a stack with $n$ layers.\nTwo ways are considered different if at any step we took a different bottle or the collapsing process went differently.\n\nYou are given $f(1) = 1$, $f(2) = 6$ and $f(3) = 1008$.\n\nAlso define\n$$S(n) = \\sum_{k=1}^n f(k).$$\n\nFind $S(10^4)$ and give your answer modulo $1\\,000\\,000\\,033$.", "raw_html": "

    \nConsider a stack of bottles of wine. There are $n$ layers in the stack with the top layer containing only one bottle and the bottom layer containing $n$ bottles. For $n=4$ the stack looks like the picture below.\n

    \n
    \n\"\"
    \n

    \nThe collapsing process happens every time a bottle is taken. A space is created in the stack and that space is filled according to the following recursive steps:\n

      \n
    • No bottle touching from above: nothing happens. For example, taking $F$.
    • \n
    • One bottle touching from above: that will drop down to fill the space creating another space. For example, taking $D$.
    • \n
    • Two bottles touching from above: one will drop down to fill the space creating another space. For example, taking $C$.
    • \n
    \n

    \nThis process happens recursively; for example, taking bottle $A$ in the diagram above. Its place can be filled with either $B$ or $C$. If it is filled with $C$ then the space that $C$ creates can be filled with $D$ or $E$. So there are 3 different collapsing processes that can happen if $A$ is taken, although the final shape (in this case) is the same.\n

    \n

    \nDefine $f(n)$ to be the number of ways that we can take all the bottles from a stack with $n$ layers. \nTwo ways are considered different if at any step we took a different bottle or the collapsing process went differently.\n

    \n

    \nYou are given $f(1) = 1$, $f(2) = 6$ and $f(3) = 1008$.\n

    \n

    \nAlso define\n$$S(n) = \\sum_{k=1}^n f(k).$$

    \n

    \nFind $S(10^4)$ and give your answer modulo $1\\,000\\,000\\,033$.\n

    ", "url": "https://projecteuler.net/problem=726", "answer": "578040951"} {"id": 727, "problem": "Let $r_a$, $r_b$ and $r_c$ be the radii of three circles that are mutually and externally tangent to each other. The three circles then form a triangle of circular arcs between their tangency points as shown for the three blue circles in the picture below.\n\nDefine the circumcircle of this triangle to be the red circle, with centre $D$, passing through their tangency points. Further define the incircle of this triangle to be the green circle, with centre $E$, that is mutually and externally tangent to all the three blue circles. Let $d=\\vert DE \\vert$ be the distance between the centres of the circumcircle and the incircle.\n\nLet $\\mathbb{E}(d)$ be the expected value of $d$ when $r_a$, $r_b$ and $r_c$ are integers chosen uniformly such that $1\\leq r_aLet $r_a$, $r_b$ and $r_c$ be the radii of three circles that are mutually and externally tangent to each other. The three circles then form a triangle of circular arcs between their tangency points as shown for the three blue circles in the picture below.

    \n

    \n
    \n\"CircularArcs\"\n
    \n\n

    \nDefine the circumcircle of this triangle to be the red circle, with centre $D$, passing through their tangency points. Further define the incircle of this triangle to be the green circle, with centre $E$, that is mutually and externally tangent to all the three blue circles. Let $d=\\vert DE \\vert$ be the distance between the centres of the circumcircle and the incircle.\n

    \nLet $\\mathbb{E}(d)$ be the expected value of $d$ when $r_a$, $r_b$ and $r_c$ are integers chosen uniformly such that $1\\leq r_a<r_b<r_c \\leq 100$ and $\\text{gcd}(r_a,r_b,r_c)=1$.

    \n

    \nFind $\\mathbb{E}(d)$, rounded to eight places after the decimal point.

    ", "url": "https://projecteuler.net/problem=727", "answer": "3.64039141"} {"id": 728, "problem": "Consider $n$ coins arranged in a circle where each coin shows heads or tails. A move consists of turning over $k$ consecutive coins: tail-head or head-tail. Using a sequence of these moves the objective is to get all the coins showing heads.\n\nConsider the example, shown below, where $n=8$ and $k=3$ and the initial state is one coin showing tails (black). The example shows a solution for this state.\n\nFor given values of $n$ and $k$ not all states are solvable. Let $F(n,k)$ be the number of states that are solvable. You are given that $F(3,2) = 4$, $F(8,3) = 256$ and $F(9,3) = 128$.\n\nFurther define:\n$$S(N) = \\sum_{n=1}^N\\sum_{k=1}^n F(n,k).$$\n\nYou are also given that $S(3) = 22$, $S(10) = 10444$ and $S(10^3) \\equiv 853837042 \\pmod{1\\,000\\,000\\,007}$\n\nFind $S(10^7)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Consider $n$ coins arranged in a circle where each coin shows heads or tails. A move consists of turning over $k$ consecutive coins: tail-head or head-tail. Using a sequence of these moves the objective is to get all the coins showing heads.

    \n\n

    Consider the example, shown below, where $n=8$ and $k=3$ and the initial state is one coin showing tails (black). The example shows a solution for this state.

    \n\n
    \n\"\"
    \n\n

    For given values of $n$ and $k$ not all states are solvable. Let $F(n,k)$ be the number of states that are solvable. You are given that $F(3,2) = 4$, $F(8,3) = 256$ and $F(9,3) = 128$.

    \n\n

    Further define:\n$$S(N) = \\sum_{n=1}^N\\sum_{k=1}^n F(n,k).$$

    \n\n

    You are also given that $S(3) = 22$, $S(10) = 10444$ and $S(10^3) \\equiv 853837042 \\pmod{1\\,000\\,000\\,007}$

    \n\n

    Find $S(10^7)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=728", "answer": "709874991"} {"id": 729, "problem": "Consider the sequence of real numbers $a_n$ defined by the starting value $a_0$ and the recurrence\n$\\displaystyle a_{n+1}=a_n-\\frac 1 {a_n}$ for any $n \\ge 0$.\n\nFor some starting values $a_0$ the sequence will be periodic. For example, $a_0=\\sqrt{\\frac 1 2}$ yields the sequence:\n$\\sqrt{\\frac 1 2},-\\sqrt{\\frac 1 2},\\sqrt{\\frac 1 2}, \\dots$\n\nWe are interested in the range of such a periodic sequence which is the difference between the maximum and minimum of the sequence. For example, the range of the sequence above would be $\\sqrt{\\frac 1 2}-(-\\sqrt{\\frac 1 2})=\\sqrt{ 2}$.\n\nLet $S(P)$ be the sum of the ranges of all such periodic sequences with a period not exceeding $P$.\n\nFor example, $S(2)=2\\sqrt{2} \\approx 2.8284$, being the sum of the ranges of the two sequences starting with $a_0=\\sqrt{\\frac 1 2}$ and $a_0=-\\sqrt{\\frac 1 2}$.\n\nYou are given $S(3) \\approx 14.6461$ and $S(5) \\approx 124.1056$.\n\nFind $S(25)$, rounded to $4$ decimal places.", "raw_html": "

    Consider the sequence of real numbers $a_n$ defined by the starting value $a_0$ and the recurrence\n$\\displaystyle a_{n+1}=a_n-\\frac 1 {a_n}$ for any $n \\ge 0$.

    \n

    \nFor some starting values $a_0$ the sequence will be periodic. For example, $a_0=\\sqrt{\\frac 1 2}$ yields the sequence:\n$\\sqrt{\\frac 1 2},-\\sqrt{\\frac 1 2},\\sqrt{\\frac 1 2}, \\dots$

    \n

    \nWe are interested in the range of such a periodic sequence which is the difference between the maximum and minimum of the sequence. For example, the range of the sequence above would be $\\sqrt{\\frac 1 2}-(-\\sqrt{\\frac 1 2})=\\sqrt{ 2}$.

    \n

    \nLet $S(P)$ be the sum of the ranges of all such periodic sequences with a period not exceeding $P$.
    \nFor example, $S(2)=2\\sqrt{2} \\approx 2.8284$, being the sum of the ranges of the two sequences starting with $a_0=\\sqrt{\\frac 1 2}$ and $a_0=-\\sqrt{\\frac 1 2}$.
    \nYou are given $S(3) \\approx 14.6461$ and $S(5) \\approx 124.1056$.\n

    \nFind $S(25)$, rounded to $4$ decimal places.

    ", "url": "https://projecteuler.net/problem=729", "answer": "308896374.2502"} {"id": 730, "problem": "For a non-negative integer $k$, the triple $(p,q,r)$ of positive integers is called a $k$-shifted Pythagorean triple if $$p^2 + q^2 + k = r^2$$\n\n$(p, q, r)$ is said to be primitive if $\\gcd(p, q, r)=1$.\n\nLet $P_k(n)$ be the number of primitive $k$-shifted Pythagorean triples such that $1 \\le p \\le q \\le r$ and $p + q + r \\le n$.\nFor example, $P_0(10^4) = 703$ and $P_{20}(10^4) = 1979$.\n\nDefine\n$$\\displaystyle S(m,n)=\\sum_{k=0}^{m}P_k(n).$$\nYou are given that $S(10,10^4) = 10956$.\n\nFind $S(10^2,10^8)$.", "raw_html": "

    \nFor a non-negative integer $k$, the triple $(p,q,r)$ of positive integers is called a $k$-shifted Pythagorean triple if $$p^2 + q^2 + k = r^2$$\n

    \n

    \n$(p, q, r)$ is said to be primitive if $\\gcd(p, q, r)=1$.\n

    \n

    \nLet $P_k(n)$ be the number of primitive $k$-shifted Pythagorean triples such that $1 \\le p \\le q \\le r$ and $p + q + r \\le n$.
    For example, $P_0(10^4) = 703$ and $P_{20}(10^4) = 1979$. \n

    \n

    \nDefine \n$$\\displaystyle S(m,n)=\\sum_{k=0}^{m}P_k(n).$$\nYou are given that $S(10,10^4) = 10956$. \n

    \n

    \nFind $S(10^2,10^8)$.\n

    ", "url": "https://projecteuler.net/problem=730", "answer": "1315965924"} {"id": 731, "problem": "$$A=\\sum_{i=1}^{\\infty} \\frac{1}{3^i 10^{3^i}}$$\n\nDefine $A(n)$ to be the $10$ decimal digits from the $n$th digit onward.\nFor example, $A(100) = 4938271604$ and $A(10^8)=2584642393$.\n\nFind $A(10^{16})$.", "raw_html": "

    \n$$A=\\sum_{i=1}^{\\infty} \\frac{1}{3^i 10^{3^i}}$$\n

    \n

    \nDefine $A(n)$ to be the $10$ decimal digits from the $n$th digit onward. \nFor example, $A(100) = 4938271604$ and $A(10^8)=2584642393$.\n

    \n

    \nFind $A(10^{16})$.\n

    ", "url": "https://projecteuler.net/problem=731", "answer": "6086371427"} {"id": 732, "problem": "$N$ trolls are in a hole that is $D_N$ cm deep. The $n$-th troll is characterized by:\n\n- the distance from his feet to his shoulders in cm, $h_n$\n\n- the length of his arms in cm, $l_n$\n\n- his IQ (Irascibility Quotient), $q_n$.\n\nTrolls can pile up on top of each other, with each troll standing on the shoulders of the one below him. A troll can climb out of the hole and escape if his hands can reach to the surface. Once a troll escapes he cannot participate any further in the escaping effort.\n\nThe trolls execute an optimal strategy for maximizing the total IQ of the escaping trolls, defined as $Q(N)$.\n\nLet\n\n$r_n = \\left[ \\left( 5^n \\bmod (10^9 + 7) \\right) \\bmod 101 \\right] + 50$\n\n$h_n = r_{3n}$\n\n$l_n = r_{3n+1}$\n\n$q_n = r_{3n+2}$\n\n$D_N = \\frac{1}{\\sqrt{2}} \\sum_{n=0}^{N-1} h_n$.\n\nFor example, the first troll ($n=0$) is 51cm tall to his shoulders, has 55cm long arms, and has an IQ of 75.\n\nYou are given that $Q(5) = 401$ and $Q(15)=941$.\n\nFind $Q(1000)$.", "raw_html": "

    \n$N$ trolls are in a hole that is $D_N$ cm deep. The $n$-th troll is characterized by:\n

    \n
      \n
    • the distance from his feet to his shoulders in cm, $h_n$
    • \n
    • the length of his arms in cm, $l_n$
    • \n
    • his IQ (Irascibility Quotient), $q_n$.
    • \n
    \n

    \nTrolls can pile up on top of each other, with each troll standing on the shoulders of the one below him. A troll can climb out of the hole and escape if his hands can reach to the surface. Once a troll escapes he cannot participate any further in the escaping effort.\n

    \n

    \nThe trolls execute an optimal strategy for maximizing the total IQ of the escaping trolls, defined as $Q(N)$.\n

    \n

    \nLet
    \n$r_n = \\left[ \\left( 5^n \\bmod (10^9 + 7) \\right) \\bmod 101 \\right] + 50$\n
    \n$h_n = r_{3n}$\n
    \n$l_n = r_{3n+1}$\n
    \n$q_n = r_{3n+2}$\n
    \n$D_N = \\frac{1}{\\sqrt{2}} \\sum_{n=0}^{N-1} h_n$.\n

    \n

    \nFor example, the first troll ($n=0$) is 51cm tall to his shoulders, has 55cm long arms, and has an IQ of 75.\n

    \n

    \nYou are given that $Q(5) = 401$ and $Q(15)=941$.\n

    \n

    \nFind $Q(1000)$.

    ", "url": "https://projecteuler.net/problem=732", "answer": "45609"} {"id": 733, "problem": "Let $a_i$ be the sequence defined by $a_i=153^i \\bmod 10\\,000\\,019$ for $i \\ge 1$.\n\nThe first terms of $a_i$ are:\n$153, 23409, 3581577, 7980255, 976697, 9434375, \\dots$\n\nConsider the subsequences consisting of $4$ terms in ascending order. For the part of the sequence shown above, these are:\n\n$153, 23409, 3581577, 7980255$\n\n$153, 23409, 3581577, 9434375$\n\n$153, 23409, 7980255, 9434375$\n\n$153, 23409, 976697, 9434375$\n\n$153, 3581577, 7980255, 9434375$ and\n\n$23409, 3581577, 7980255, 9434375$.\n\nDefine $S(n)$ to be the sum of the terms for all such subsequences within the first $n$ terms of $a_i$. Thus $S(6)=94513710$.\n\nYou are given that $S(100)=4465488724217$.\n\nFind $S(10^6)$ modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nLet $a_i$ be the sequence defined by $a_i=153^i \\bmod 10\\,000\\,019$ for $i \\ge 1$.
    \nThe first terms of $a_i$ are:\n$153, 23409, 3581577, 7980255, 976697, 9434375, \\dots$\n

    \n

    \nConsider the subsequences consisting of $4$ terms in ascending order. For the part of the sequence shown above, these are:
    \n$153, 23409, 3581577, 7980255$
    \n$153, 23409, 3581577, 9434375$
    \n$153, 23409, 7980255, 9434375$
    \n$153, 23409, 976697, 9434375$
    \n$153, 3581577, 7980255, 9434375$ and
    \n$23409, 3581577, 7980255, 9434375$.\n

    \n

    \nDefine $S(n)$ to be the sum of the terms for all such subsequences within the first $n$ terms of $a_i$. Thus $S(6)=94513710$.
    \nYou are given that $S(100)=4465488724217$.\n

    \n

    \nFind $S(10^6)$ modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=733", "answer": "574368578"} {"id": 734, "problem": "The logical-OR of two bits is $0$ if both bits are $0$, otherwise it is $1$.\n\nThe bitwise-OR of two positive integers performs a logical-OR operation on each pair of corresponding bits in the binary expansion of its inputs.\n\nFor example, the bitwise-OR of $10$ and $6$ is $14$ because $10 = 1010_2$, $6 = 0110_2$ and $14 = 1110_2$.\n\nLet $T(n, k)$ be the number of $k$-tuples $(x_1, x_2,\\cdots,x_k)$ such that\n\n- every $x_i$ is a prime $\\leq n$\n\n- the bitwise-OR of the tuple is a prime $\\leq n$\n\nFor example, $T(5, 2)=5$. The five $2$-tuples are $(2, 2)$, $(2, 3)$, $(3, 2)$, $(3, 3)$ and $(5, 5)$.\n\nYou are given $T(100, 3) = 3355$ and $T(1000, 10) \\equiv 2071632 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $T(10^6,999983)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nThe logical-OR of two bits is $0$ if both bits are $0$, otherwise it is $1$.
    \nThe bitwise-OR of two positive integers performs a logical-OR operation on each pair of corresponding bits in the binary expansion of its inputs.\n

    \n

    \nFor example, the bitwise-OR of $10$ and $6$ is $14$ because $10 = 1010_2$, $6 = 0110_2$ and $14 = 1110_2$.\n

    \n

    \nLet $T(n, k)$ be the number of $k$-tuples $(x_1, x_2,\\cdots,x_k)$ such that\n

    \n
      \n
    • every $x_i$ is a prime $\\leq n$
    • \n
    • the bitwise-OR of the tuple is a prime $\\leq n$
    • \n
    \n

    \nFor example, $T(5, 2)=5$. The five $2$-tuples are $(2, 2)$, $(2, 3)$, $(3, 2)$, $(3, 3)$ and $(5, 5)$.\n

    \nYou are given $T(100, 3) = 3355$ and $T(1000, 10) \\equiv 2071632 \\pmod{1\\,000\\,000\\,007}$.\n

    \n

    \nFind $T(10^6,999983)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=734", "answer": "557988060"} {"id": 735, "problem": "Let $f(n)$ be the number of divisors of $2n^2$ that are no greater than n. For example, $f(15)=8$ because there are 8 such divisors: 1,2,3,5,6,9,10,15. Note that 18 is also a divisor of $2\\times 15^2$ but it is not counted because it is greater than 15.\n\nLet $\\displaystyle F(N) = \\sum_{n=1}^N f(n)$. You are given $F(15)=63$, and $F(1000)=15066$.\n\nFind $F(10^{12})$.", "raw_html": "

    Let $f(n)$ be the number of divisors of $2n^2$ that are no greater than n. For example, $f(15)=8$ because there are 8 such divisors: 1,2,3,5,6,9,10,15. Note that 18 is also a divisor of $2\\times 15^2$ but it is not counted because it is greater than 15.

    \n\n

    Let $\\displaystyle F(N) = \\sum_{n=1}^N f(n)$. You are given $F(15)=63$, and $F(1000)=15066$.

    \n\n

    Find $F(10^{12})$.

    ", "url": "https://projecteuler.net/problem=735", "answer": "174848216767932"} {"id": 736, "problem": "Define two functions on lattice points:\n\n$r(x,y) = (x+1,2y)$\n$s(x,y) = (2x,y+1)$\nA path to equality of length $n$ for a pair $(a,b)$ is a sequence $\\Big((a_1,b_1),(a_2,b_2),\\ldots,(a_n,b_n)\\Big)$, where:\n\n- $(a_1,b_1) = (a,b)$\n\n- $(a_k,b_k) = r(a_{k-1},b_{k-1})$ or $(a_k,b_k) = s(a_{k-1},b_{k-1})$ for $k > 1$\n\n- $a_k \\ne b_k$ for $k < n$\n\n- $a_n = b_n$\n\n$a_n = b_n$ is called the final value.\n\nFor example,\n\n$(45,90)\\xrightarrow{r} (46,180)\\xrightarrow{s}(92,181)\\xrightarrow{s}(184,182)\\xrightarrow{s}(368,183)\\xrightarrow{s}(736,184)\\xrightarrow{r}$\n$(737,368)\\xrightarrow{s}(1474,369)\\xrightarrow{r}(1475,738)\\xrightarrow{r}(1476,1476)$\nThis is a path to equality for $(45,90)$ and is of length 10 with final value 1476. There is no path to equality of $(45,90)$ with smaller length.\n\nFind the unique path to equality for $(45,90)$ with smallest odd length. Enter the final value as your answer.", "raw_html": "

    Define two functions on lattice points:

    \n
    $r(x,y) = (x+1,2y)$
    \n
    $s(x,y) = (2x,y+1)$
    \n

    A path to equality of length $n$ for a pair $(a,b)$ is a sequence $\\Big((a_1,b_1),(a_2,b_2),\\ldots,(a_n,b_n)\\Big)$, where:

    \n
      \n
    • $(a_1,b_1) = (a,b)$
    • \n
    • $(a_k,b_k) = r(a_{k-1},b_{k-1})$ or $(a_k,b_k) = s(a_{k-1},b_{k-1})$ for $k > 1$
    • \n
    • $a_k \\ne b_k$ for $k < n$
    • \n
    • $a_n = b_n$
    • \n
    \n

    $a_n = b_n$ is called the final value.

    \n

    For example,

    \n
    $(45,90)\\xrightarrow{r} (46,180)\\xrightarrow{s}(92,181)\\xrightarrow{s}(184,182)\\xrightarrow{s}(368,183)\\xrightarrow{s}(736,184)\\xrightarrow{r}$
    \n
    $(737,368)\\xrightarrow{s}(1474,369)\\xrightarrow{r}(1475,738)\\xrightarrow{r}(1476,1476)$
    \n

    This is a path to equality for $(45,90)$ and is of length 10 with final value 1476. There is no path to equality of $(45,90)$ with smaller length.

    \n

    Find the unique path to equality for $(45,90)$ with smallest odd length. Enter the final value as your answer.

    ", "url": "https://projecteuler.net/problem=736", "answer": "25332747903959376"} {"id": 737, "problem": "A game is played with many identical, round coins on a flat table.\n\nConsider a line perpendicular to the table.\n\nThe first coin is placed on the table touching the line.\n\nThen, one by one, the coins are placed horizontally on top of the previous coin and touching the line.\n\nThe complete stack of coins must be balanced after every placement.\n\nThe diagram below [not to scale] shows a possible placement of 8 coins where point $P$ represents the line.\n\nIt is found that a minimum of $31$ coins are needed to form a coin loop around the line, i.e. if in the projection of the coins on the table the centre of the $n$th coin is rotated $\\theta_n$, about the line, from the centre of the $(n-1)$th coin then the sum of $\\displaystyle\\sum_{k=2}^n \\theta_k$ is first larger than $360^\\circ$ when $n=31$. In general, to loop $k$ times, $n$ is the smallest number for which the sum is greater than $360^\\circ k$.\n\nAlso, $154$ coins are needed to loop two times around the line, and $6947$ coins to loop ten times.\n\nCalculate the number of coins needed to loop $2020$ times around the line.", "raw_html": "

    \nA game is played with many identical, round coins on a flat table.\n

    \n

    \nConsider a line perpendicular to the table.
    \nThe first coin is placed on the table touching the line.
    \nThen, one by one, the coins are placed horizontally on top of the previous coin and touching the line.
    \nThe complete stack of coins must be balanced after every placement.\n

    \n

    \nThe diagram below [not to scale] shows a possible placement of 8 coins where point $P$ represents the line.\n

    \n
    \n\"\"
    \n

    \nIt is found that a minimum of $31$ coins are needed to form a coin loop around the line, i.e. if in the projection of the coins on the table the centre of the $n$th coin is rotated $\\theta_n$, about the line, from the centre of the $(n-1)$th coin then the sum of $\\displaystyle\\sum_{k=2}^n \\theta_k$ is first larger than $360^\\circ$ when $n=31$. In general, to loop $k$ times, $n$ is the smallest number for which the sum is greater than $360^\\circ k$.\n

    \n

    \nAlso, $154$ coins are needed to loop two times around the line, and $6947$ coins to loop ten times.\n

    \n

    \nCalculate the number of coins needed to loop $2020$ times around the line.\n

    ", "url": "https://projecteuler.net/problem=737", "answer": "757794899"} {"id": 738, "problem": "Define $d(n,k)$ to be the number of ways to write $n$ as a product of $k$ ordered integers\n\n$$\nn = x_1\\times x_2\\times x_3\\times \\ldots\\times x_k\\qquad 1\\le x_1\\le x_2\\le\\ldots\\le x_k\n$$\nFurther define $D(N,K)$ to be the sum of $d(n,k)$ for $1\\le n\\le N$ and $1\\le k\\le K$.\n\nYou are given that $D(10, 10) = 153$ and $D(100, 100) = 35384$.\n\nFind $D(10^{10},10^{10})$ giving your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Define $d(n,k)$ to be the number of ways to write $n$ as a product of $k$ ordered integers

    \n$$\nn = x_1\\times x_2\\times x_3\\times \\ldots\\times x_k\\qquad 1\\le x_1\\le x_2\\le\\ldots\\le x_k\n$$\n

    Further define $D(N,K)$ to be the sum of $d(n,k)$ for $1\\le n\\le N$ and $1\\le k\\le K$.

    \n\n

    You are given that $D(10, 10) = 153$ and $D(100, 100) = 35384$.

    \n\n

    Find $D(10^{10},10^{10})$ giving your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=738", "answer": "143091030"} {"id": 739, "problem": "Take a sequence of length $n$. Discard the first term then make a sequence of the partial summations. Continue to do this over and over until we are left with a single term. We define this to be $f(n)$.\n\nConsider the example where we start with a sequence of length 8:\n\n$\n\\begin{array}{rrrrrrrr}\n1&1&1&1&1&1&1&1\\\\\n&1&2&3&4&5& 6 &7\\\\\n& &2&5&9&14&20&27\\\\\n& & &5&14&28&48&75\\\\\n& & & &14&42&90&165\\\\\n& & & & & 42 & 132 & 297\\\\\n& & & & & & 132 &429\\\\\n& & & & & & &429\\\\\n\\end{array}\n$\n\nThen the final number is $429$, so $f(8) = 429$.\n\nFor this problem we start with the sequence $1,3,4,7,11,18,29,47,\\ldots$\n\nThis is the Lucas sequence where two terms are added to get the next term.\n\nApplying the same process as above we get $f(8) = 2663$.\n\nYou are also given $f(20) = 742296999 $ modulo $1\\,000\\,000\\,007$\n\nFind $f(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nTake a sequence of length $n$. Discard the first term then make a sequence of the partial summations. Continue to do this over and over until we are left with a single term. We define this to be $f(n)$.\n

    \n

    \nConsider the example where we start with a sequence of length 8:\n

    \n

    \n$\n\\begin{array}{rrrrrrrr}\n1&1&1&1&1&1&1&1\\\\\n &1&2&3&4&5& 6 &7\\\\\n & &2&5&9&14&20&27\\\\\n & & &5&14&28&48&75\\\\\n & & & &14&42&90&165\\\\\n & & & & & 42 & 132 & 297\\\\\n & & & & & & 132 &429\\\\\n & & & & & & &429\\\\\n\\end{array}\n$\n

    \n

    \nThen the final number is $429$, so $f(8) = 429$.\n

    \n

    \nFor this problem we start with the sequence $1,3,4,7,11,18,29,47,\\ldots$
    \nThis is the Lucas sequence where two terms are added to get the next term.
    \nApplying the same process as above we get $f(8) = 2663$.
    \nYou are also given $f(20) = 742296999 $ modulo $1\\,000\\,000\\,007$\n

    \n

    \nFind $f(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=739", "answer": "711399016"} {"id": 740, "problem": "Secret Santa is a process that allows $n$ people to give each other presents, so that each person gives a single present and receives a single present. At the beginning each of the $n$ people write their name on a slip of paper and put the slip into a hat. Each person takes a random slip from the hat. If the slip has their name they draw another random slip from the hat and then put the slip with their name back into the hat. At the end everyone buys a Christmas present for the person whose name is on the slip they are holding. This process will fail if the last person draws their own name.\n\nIn this variation each of the $n$ people gives and receives two presents. At the beginning each of the $n$ people writes their name on two slips of paper and puts the slips into a hat (there will be $2n$ slips of paper in the hat). As before each person takes from the hat a random slip that does not contain their own name. Then the same person repeats this process thus ending up with two slips, neither of which contains that person's own name. Then the next person draws two slips in the same way, and so on. The process will fail if the last person gets at least one slip with their own name.\n\nDefine $q(n)$ to be the probability of this happening. You are given $q(3) = 0.3611111111$ and $q(5) = 0.2476095994$ both rounded to 10 decimal places.\n\nFind $q(100)$ rounded to 10 decimal places.", "raw_html": "

    \nSecret Santa is a process that allows $n$ people to give each other presents, so that each person gives a single present and receives a single present. At the beginning each of the $n$ people write their name on a slip of paper and put the slip into a hat. Each person takes a random slip from the hat. If the slip has their name they draw another random slip from the hat and then put the slip with their name back into the hat. At the end everyone buys a Christmas present for the person whose name is on the slip they are holding. This process will fail if the last person draws their own name.\n

    \n

    \nIn this variation each of the $n$ people gives and receives two presents. At the beginning each of the $n$ people writes their name on two slips of paper and puts the slips into a hat (there will be $2n$ slips of paper in the hat). As before each person takes from the hat a random slip that does not contain their own name. Then the same person repeats this process thus ending up with two slips, neither of which contains that person's own name. Then the next person draws two slips in the same way, and so on. The process will fail if the last person gets at least one slip with their own name. \n

    \n

    \nDefine $q(n)$ to be the probability of this happening. You are given $q(3) = 0.3611111111$ and $q(5) = 0.2476095994$ both rounded to 10 decimal places.\n

    \n

    \nFind $q(100)$ rounded to 10 decimal places.\n

    ", "url": "https://projecteuler.net/problem=740", "answer": "0.0189581208"} {"id": 741, "problem": "Let $f(n)$ be the number of ways an $n\\times n$ square grid can be coloured, each cell either black or white, such that each row and each column contains exactly two black cells.\n\nFor example, $f(4)=90$, $f(7) = 3110940$ and $f(8) = 187530840$.\n\nLet $g(n)$ be the number of colourings in $f(n)$ that are unique up to rotations and reflections.\n\nYou are given $g(4)=20$, $g(7) = 390816$ and $g(8) = 23462347$ giving $g(7)+g(8) = 23853163$.\n\nFind $g(7^7) + g(8^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nLet $f(n)$ be the number of ways an $n\\times n$ square grid can be coloured, each cell either black or white, such that each row and each column contains exactly two black cells.
    \nFor example, $f(4)=90$, $f(7) = 3110940$ and $f(8) = 187530840$.\n

    \n

    \nLet $g(n)$ be the number of colourings in $f(n)$ that are unique up to rotations and reflections.
    \nYou are given $g(4)=20$, $g(7) = 390816$ and $g(8) = 23462347$ giving $g(7)+g(8) = 23853163$.\n

    \n

    \nFind $g(7^7) + g(8^8)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=741", "answer": "512895223"} {"id": 742, "problem": "A symmetrical convex grid polygon is a polygon such that:\n\n- All its vertices have integer coordinates.\n\n- All its internal angles are strictly smaller than $180^\\circ$.\n\n- It has both horizontal and vertical symmetry.\n\nFor example, the left polygon is a convex grid polygon which has neither horizontal nor vertical symmetry, while the right one is a valid symmetrical convex grid polygon with six vertices:\n\nDefine $A(N)$, the minimum area of a symmetrical convex grid polygon with $N$ vertices.\n\nYou are given $A(4) = 1$, $A(8) = 7$, $A(40) = 1039$ and $A(100) = 17473$.\n\nFind $A(1000)$.", "raw_html": "

    A symmetrical convex grid polygon is a polygon such that:

    \n
      \n
    • All its vertices have integer coordinates.
    • \n
    • All its internal angles are strictly smaller than $180^\\circ$.
    • \n
    • It has both horizontal and vertical symmetry.
    • \n
    \n\n

    For example, the left polygon is a convex grid polygon which has neither horizontal nor vertical symmetry, while the right one is a valid symmetrical convex grid polygon with six vertices:

    \n
    \n\"\"
    \n\n

    Define $A(N)$, the minimum area of a symmetrical convex grid polygon with $N$ vertices.

    \n\n

    You are given $A(4) = 1$, $A(8) = 7$, $A(40) = 1039$ and $A(100) = 17473$.

    \n\n

    Find $A(1000)$.

    ", "url": "https://projecteuler.net/problem=742", "answer": "18397727"} {"id": 743, "problem": "A window into a matrix is a contiguous sub matrix.\n\nConsider a $2\\times n$ matrix where every entry is either 0 or 1.\n\nLet $A(k,n)$ be the total number of these matrices such that the sum of the entries in every $2\\times k$ window is $k$.\n\nYou are given that $A(3,9) = 560$ and $A(4,20) = 1060870$.\n\nFind $A(10^8,10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nA window into a matrix is a contiguous sub matrix.\n

    \n

    \nConsider a $2\\times n$ matrix where every entry is either 0 or 1.
    \nLet $A(k,n)$ be the total number of these matrices such that the sum of the entries in every $2\\times k$ window is $k$.\n

    \n

    \nYou are given that $A(3,9) = 560$ and $A(4,20) = 1060870$.\n

    \n

    \nFind $A(10^8,10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=743", "answer": "259158998"} {"id": 744, "problem": "\"What? Where? When?\" is a TV game show in which a team of experts attempt to answer questions. The following is a simplified version of the game.\n\nIt begins with $2n+1$ envelopes. $2n$ of them contain a question and one contains a RED card.\n\nIn each round one of the remaining envelopes is randomly chosen. If the envelope contains the RED card the game ends. If the envelope contains a question the expert gives their answer. If their answer is correct they earn one point, otherwise the viewers earn one point. The game ends normally when either the expert obtains n points or the viewers obtain n points.\n\nAssuming that the expert provides the correct answer with a fixed probability $p$, let $f(n,p)$ be the probability that the game ends normally (i.e. RED card never turns up).\n\nYou are given (rounded to 10 decimal places) that\n\n$f(6,\\frac{1}{2})=0.2851562500$,\n\n$f(10,\\frac{3}{7})=0.2330040743$,\n\n$f(10^4,0.3)=0.2857499982$.\n\nFind $f(10^{11},0.4999)$. Give your answer rounded to 10 places behind the decimal point.", "raw_html": "

    \"What? Where? When?\" is a TV game show in which a team of experts attempt to answer questions. The following is a simplified version of the game.

    \n\n

    It begins with $2n+1$ envelopes. $2n$ of them contain a question and one contains a RED card.

    \n\n

    In each round one of the remaining envelopes is randomly chosen. If the envelope contains the RED card the game ends. If the envelope contains a question the expert gives their answer. If their answer is correct they earn one point, otherwise the viewers earn one point. The game ends normally when either the expert obtains n points or the viewers obtain n points.

    \n\n

    Assuming that the expert provides the correct answer with a fixed probability $p$, let $f(n,p)$ be the probability that the game ends normally (i.e. RED card never turns up).

    \n\n

    You are given (rounded to 10 decimal places) that
    \n$f(6,\\frac{1}{2})=0.2851562500$,
    \n$f(10,\\frac{3}{7})=0.2330040743$,
    \n$f(10^4,0.3)=0.2857499982$.\n

    \n\n

    Find $f(10^{11},0.4999)$. Give your answer rounded to 10 places behind the decimal point.

    ", "url": "https://projecteuler.net/problem=744", "answer": "0.0001999600"} {"id": 745, "problem": "For a positive integer, $n$, define $g(n)$ to be the maximum perfect square that divides $n$.\n\nFor example, $g(18) = 9$, $g(19) = 1$.\n\nAlso define\n$$\\displaystyle\tS(N) = \\sum_{n=1}^N g(n)$$\n\nFor example, $S(10) = 24$ and $S(100) = 767$.\n\nFind $S(10^{14})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nFor a positive integer, $n$, define $g(n)$ to be the maximum perfect square that divides $n$.
    \nFor example, $g(18) = 9$, $g(19) = 1$.\n

    \n

    \nAlso define\n$$\\displaystyle\tS(N) = \\sum_{n=1}^N g(n)$$\n

    \n

    \nFor example, $S(10) = 24$ and $S(100) = 767$.\n

    \n

    \nFind $S(10^{14})$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=745", "answer": "94586478"} {"id": 746, "problem": "$n$ families, each with four members, a father, a mother, a son and a daughter, were invited to a restaurant. They were all seated at a large circular table with $4n$ seats such that men and women alternate.\n\nLet $M(n)$ be the number of ways the families can be seated such that none of the families were seated together. A family is considered to be seated together only when all the members of a family sit next to each other.\n\nFor example, $M(1)=0$, $M(2)=896$, $M(3)=890880$ and $M(10) \\equiv 170717180 \\pmod {1\\,000\\,000\\,007}$.\n\nLet $S(n)=\\displaystyle \\sum_{k=2}^nM(k)$.\n\nFor example, $S(10) \\equiv 399291975 \\pmod {1\\,000\\,000\\,007}$.\n\nFind $S(2021)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    $n$ families, each with four members, a father, a mother, a son and a daughter, were invited to a restaurant. They were all seated at a large circular table with $4n$ seats such that men and women alternate.

    \n\n

    Let $M(n)$ be the number of ways the families can be seated such that none of the families were seated together. A family is considered to be seated together only when all the members of a family sit next to each other.

    \n\n

    For example, $M(1)=0$, $M(2)=896$, $M(3)=890880$ and $M(10) \\equiv 170717180 \\pmod {1\\,000\\,000\\,007}$.

    \n\n

    Let $S(n)=\\displaystyle \\sum_{k=2}^nM(k)$.

    \n\n

    For example, $S(10) \\equiv 399291975 \\pmod {1\\,000\\,000\\,007}$.

    \n\n

    Find $S(2021)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=746", "answer": "867150922"} {"id": 747, "problem": "Mamma Triangolo baked a triangular pizza. She wants to cut the pizza into $n$ pieces. She first chooses a point $P$ in the interior (not boundary) of the triangle pizza, and then performs $n$ cuts, which all start from $P$ and extend straight to the boundary of the pizza so that the $n$ pieces are all triangles and all have the same area.\n\nLet $\\psi(n)$ be the number of different ways for Mamma Triangolo to cut the pizza, subject to the constraints.\n\nFor example, $\\psi(3)=7$.\n\nAlso $\\psi(6)=34$, and $\\psi(10)=90$.\n\nLet $\\Psi(m)=\\displaystyle\\sum_{n=3}^m \\psi(n)$. You are given $\\Psi(10)=345$ and $\\Psi(1000)=172166601$.\n\nFind $\\Psi(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Mamma Triangolo baked a triangular pizza. She wants to cut the pizza into $n$ pieces. She first chooses a point $P$ in the interior (not boundary) of the triangle pizza, and then performs $n$ cuts, which all start from $P$ and extend straight to the boundary of the pizza so that the $n$ pieces are all triangles and all have the same area.

    \n\n

    Let $\\psi(n)$ be the number of different ways for Mamma Triangolo to cut the pizza, subject to the constraints.
    \nFor example, $\\psi(3)=7$.

    \n\n
    \n\"\"
    \n\n

    Also $\\psi(6)=34$, and $\\psi(10)=90$.

    \n\n

    Let $\\Psi(m)=\\displaystyle\\sum_{n=3}^m \\psi(n)$. You are given $\\Psi(10)=345$ and $\\Psi(1000)=172166601$.

    \n\n

    Find $\\Psi(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=747", "answer": "681813395"} {"id": 748, "problem": "Upside Down is a modification of the famous Pythagorean equation:\n$$\\begin{align}\n\\frac{1}{x^2}+\\frac{1}{y^2}=\\frac{13}{z^2}.\n\\end{align}$$\n\nA solution $(x,y,z)$ to this equation with $x,y$ and $z$ positive integers is a primitive solution if $\\gcd(x,y,z)=1$.\n\nLet $S(N)$ be the sum of $x+y+z$ over primitive Upside Down solutions such that $1 \\leq x,y,z \\leq N$ and $x \\le y$.\n\nFor $N=100$ the primitive solutions are $(2,3,6)$ and $(5,90,18)$, thus $S(10^2)=124$.\n\nIt can be checked that $S(10^3)=1470$ and $S(10^5)=2340084$.\n\nFind $S(10^{16})$ and give the last $9$ digits as your answer.", "raw_html": "

    \nUpside Down is a modification of the famous Pythagorean equation:\n$$\\begin{align}\n\\frac{1}{x^2}+\\frac{1}{y^2}=\\frac{13}{z^2}.\n\\end{align}$$\n

    \n

    \nA solution $(x,y,z)$ to this equation with $x,y$ and $z$ positive integers is a primitive solution if $\\gcd(x,y,z)=1$.\n

    \n

    \nLet $S(N)$ be the sum of $x+y+z$ over primitive Upside Down solutions such that $1 \\leq x,y,z \\leq N$ and $x \\le y$.
    \nFor $N=100$ the primitive solutions are $(2,3,6)$ and $(5,90,18)$, thus $S(10^2)=124$.
    \nIt can be checked that $S(10^3)=1470$ and $S(10^5)=2340084$.\n

    \n

    \nFind $S(10^{16})$ and give the last $9$ digits as your answer.\n

    ", "url": "https://projecteuler.net/problem=748", "answer": "276402862"} {"id": 749, "problem": "A positive integer, $n$, is a near power sum if there exists a positive integer, $k$, such that the sum of the $k$th powers of the digits in its decimal representation is equal to either $n+1$ or $n-1$. For example $35$ is a near power sum number because $3^2+5^2 = 34$.\n\nDefine $S(d)$ to be the sum of all near power sum numbers of $d$ digits or less.\nThen $S(2) = 110$ and $S(6) = 2562701$.\n\nFind $S(16)$.", "raw_html": "

    \nA positive integer, $n$, is a near power sum if there exists a positive integer, $k$, such that the sum of the $k$th powers of the digits in its decimal representation is equal to either $n+1$ or $n-1$. For example $35$ is a near power sum number because $3^2+5^2 = 34$.\n

    \n

    \nDefine $S(d)$ to be the sum of all near power sum numbers of $d$ digits or less. \nThen $S(2) = 110$ and $S(6) = 2562701$.\n

    \n

    \nFind $S(16)$.\n

    ", "url": "https://projecteuler.net/problem=749", "answer": "13459471903176422"} {"id": 750, "problem": "Card Stacking is a game on a computer starting with an array of $N$ cards labelled $1,2,\\ldots,N$.\nA stack of cards can be moved by dragging horizontally with the mouse to another stack but only when the resulting stack is in sequence. The goal of the game is to combine the cards into a single stack using minimal total drag distance.\n\nFor the given arrangement of 6 cards the minimum total distance is $1 + 3 + 1 + 1 + 2 = 8$.\n\nFor $N$ cards, the cards are arranged so that the card at position $n$ is $3^n\\bmod(N+1), 1\\le n\\le N$.\n\nWe define $G(N)$ to be the minimal total drag distance to arrange these cards into a single sequence.\n\nFor example, when $N = 6$ we get the sequence $3,2,6,4,5,1$ and $G(6) = 8$.\n\nYou are given $G(16) = 47$.\n\nFind $G(976)$.\n\nNote: $G(N)$ is not defined for all values of $N$.", "raw_html": "

    \nCard Stacking is a game on a computer starting with an array of $N$ cards labelled $1,2,\\ldots,N$.\nA stack of cards can be moved by dragging horizontally with the mouse to another stack but only when the resulting stack is in sequence. The goal of the game is to combine the cards into a single stack using minimal total drag distance.\n

    \n\n
    \n\"\"\n
    \n\n

    \nFor the given arrangement of 6 cards the minimum total distance is $1 + 3 + 1 + 1 + 2 = 8$.\n

    \n\n

    \nFor $N$ cards, the cards are arranged so that the card at position $n$ is $3^n\\bmod(N+1), 1\\le n\\le N$.\n

    \n

    \nWe define $G(N)$ to be the minimal total drag distance to arrange these cards into a single sequence.
    \nFor example, when $N = 6$ we get the sequence $3,2,6,4,5,1$ and $G(6) = 8$.
    \nYou are given $G(16) = 47$.\n

    \n\n

    \nFind $G(976)$.\n

    \n\n

    \nNote: $G(N)$ is not defined for all values of $N$.\n

    ", "url": "https://projecteuler.net/problem=750", "answer": "160640"} {"id": 751, "problem": "A non-decreasing sequence of integers $a_n$ can be generated from any positive real value $\\theta$ by the following procedure:\n$$\\begin{align}\n\\begin{split}\nb_1 &= \\theta \\\\\nb_n &= \\left\\lfloor b_{n-1} \\right\\rfloor \\left(b_{n-1} - \\left\\lfloor b_{n-1} \\right\\rfloor + 1\\right)~~~\\forall ~ n \\geq 2 \\\\\na_n &= \\left\\lfloor b_{n} \\right\\rfloor\n\\end{split}\n\\end{align}$$\nWhere $\\left\\lfloor \\cdot \\right\\rfloor$ is the floor function.\n\nFor example, $\\theta=2.956938891377988...$ generates the Fibonacci sequence: $2, 3, 5, 8, 13, 21, 34, 55, 89, ...$\n\nThe concatenation of a sequence of positive integers $a_n$ is a real value denoted $\\tau$ constructed by concatenating the elements of the sequence after the decimal point, starting at $a_1$: $a_1.a_2a_3a_4...$\n\nFor example, the Fibonacci sequence constructed from $\\theta=2.956938891377988...$ yields the concatenation $\\tau=2.3581321345589...$ Clearly, $\\tau \\neq \\theta$ for this value of $\\theta$.\n\nFind the only value of $\\theta$ for which the generated sequence starts at $a_1=2$ and the concatenation of the generated sequence equals the original value: $\\tau = \\theta$. Give your answer rounded to $24$ places after the decimal point.", "raw_html": "

    A non-decreasing sequence of integers $a_n$ can be generated from any positive real value $\\theta$ by the following procedure:\n$$\\begin{align}\n\\begin{split}\nb_1 &= \\theta \\\\\nb_n &= \\left\\lfloor b_{n-1} \\right\\rfloor \\left(b_{n-1} - \\left\\lfloor b_{n-1} \\right\\rfloor + 1\\right)~~~\\forall ~ n \\geq 2 \\\\\na_n &= \\left\\lfloor b_{n} \\right\\rfloor\n\\end{split}\n\\end{align}$$\nWhere $\\left\\lfloor \\cdot \\right\\rfloor$ is the floor function.

    \n\n

    For example, $\\theta=2.956938891377988...$ generates the Fibonacci sequence: $2, 3, 5, 8, 13, 21, 34, 55, 89, ...$

    \n\n

    The concatenation of a sequence of positive integers $a_n$ is a real value denoted $\\tau$ constructed by concatenating the elements of the sequence after the decimal point, starting at $a_1$: $a_1.a_2a_3a_4...$

    \n\n

    For example, the Fibonacci sequence constructed from $\\theta=2.956938891377988...$ yields the concatenation $\\tau=2.3581321345589...$ Clearly, $\\tau \\neq \\theta$ for this value of $\\theta$.

    \n\n

    Find the only value of $\\theta$ for which the generated sequence starts at $a_1=2$ and the concatenation of the generated sequence equals the original value: $\\tau = \\theta$. Give your answer rounded to $24$ places after the decimal point.

    ", "url": "https://projecteuler.net/problem=751", "answer": "2.223561019313554106173177"} {"id": 752, "problem": "When $(1+\\sqrt 7)$ is raised to an integral power, $n$, we always get a number of the form $(a+b\\sqrt 7)$.\n\nWe write $(1+\\sqrt 7)^n = \\alpha(n) + \\beta(n)\\sqrt 7$.\n\nFor a given number $x$ we define $g(x)$ to be the smallest positive integer $n$ such that:\n$$\\begin{align}\n\\alpha(n) &\\equiv 1 \\pmod x\\qquad \\text{and }\\\\\n\\beta(n) &\\equiv 0 \\pmod x\\end{align}\n$$\nand $g(x) = 0$ if there is no such value of $n$. For example, $g(3) = 0$, $g(5) = 12$.\n\nFurther define\n$$ G(N) = \\sum_{x=2}^N g(x)$$\nYou are given $G(10^2) = 28891$ and $G(10^3) = 13131583$.\n\nFind $G(10^6)$.", "raw_html": "

    \nWhen $(1+\\sqrt 7)$ is raised to an integral power, $n$, we always get a number of the form $(a+b\\sqrt 7)$.
    \nWe write $(1+\\sqrt 7)^n = \\alpha(n) + \\beta(n)\\sqrt 7$.\n

    \n

    \nFor a given number $x$ we define $g(x)$ to be the smallest positive integer $n$ such that:\n$$\\begin{align}\n\\alpha(n) &\\equiv 1 \\pmod x\\qquad \\text{and }\\\\\n\\beta(n) &\\equiv 0 \\pmod x\\end{align}\n$$\nand $g(x) = 0$ if there is no such value of $n$. For example, $g(3) = 0$, $g(5) = 12$.\n

    \n

    \nFurther define\n$$ G(N) = \\sum_{x=2}^N g(x)$$\nYou are given $G(10^2) = 28891$ and $G(10^3) = 13131583$.\n

    \n

    \nFind $G(10^6)$.\n

    ", "url": "https://projecteuler.net/problem=752", "answer": "5610899769745488"} {"id": 753, "problem": "Fermat's Last Theorem states that no three positive integers $a$, $b$, $c$ satisfy the equation\n$$a^n+b^n=c^n$$\nfor any integer value of $n$ greater than 2.\n\nFor this problem we are only considering the case $n=3$. For certain values of $p$, it is possible to solve the congruence equation:\n$$a^3+b^3 \\equiv c^3 \\pmod{p}$$\n\nFor a prime $p$, we define $F(p)$ as the number of integer solutions to this equation for $1 \\le a,b,c < p$.\n\nYou are given $F(5) = 12$ and $F(7) = 0$.\n\nFind the sum of $F(p)$ over all primes $p$ less than $6\\,000\\,000$.", "raw_html": "

    Fermat's Last Theorem states that no three positive integers $a$, $b$, $c$ satisfy the equation \n$$a^n+b^n=c^n$$\nfor any integer value of $n$ greater than 2.

    \n\n

    For this problem we are only considering the case $n=3$. For certain values of $p$, it is possible to solve the congruence equation:\n$$a^3+b^3 \\equiv c^3 \\pmod{p}$$

    \n\n

    For a prime $p$, we define $F(p)$ as the number of integer solutions to this equation for $1 \\le a,b,c < p$.

    \n\n

    You are given $F(5) = 12$ and $F(7) = 0$.

    \n\n

    Find the sum of $F(p)$ over all primes $p$ less than $6\\,000\\,000$.

    ", "url": "https://projecteuler.net/problem=753", "answer": "4714126766770661630"} {"id": 754, "problem": "The Gauss Factorial of a number $n$ is defined as the product of all positive numbers $\\leq n$ that are relatively prime to $n$. For example $g(10)=1\\times 3\\times 7\\times 9 = 189$.\n\nAlso we define\n$$\\displaystyle G(n) = \\prod_{i=1}^{n}g(i)$$\n\nYou are given $G(10) = 23044331520000$.\n\nFind $G(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    The Gauss Factorial of a number $n$ is defined as the product of all positive numbers $\\leq n$ that are relatively prime to $n$. For example $g(10)=1\\times 3\\times 7\\times 9 = 189$.

    \n

    Also we define\n$$\\displaystyle G(n) = \\prod_{i=1}^{n}g(i)$$

    \n

    You are given $G(10) = 23044331520000$.

    \n\n

    Find $G(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=754", "answer": "785845900"} {"id": 755, "problem": "Consider the Fibonacci sequence $\\{1,2,3,5,8,13,21,\\ldots\\}$.\n\nWe let $f(n)$ be the number of ways of representing an integer $n\\ge 0$ as the sum of different Fibonacci numbers.\n\nFor example, $16 = 3+13 = 1+2+13 = 3+5+8 = 1+2+5+8$ and hence $f(16) = 4$.\nBy convention $f(0) = 1$.\n\nFurther we define\n$$S(n) = \\sum_{k=0}^n f(k).$$\nYou are given $S(100) = 415$ and $S(10^4) = 312807$.\n\nFind $\\displaystyle S(10^{13})$.", "raw_html": "

    \nConsider the Fibonacci sequence $\\{1,2,3,5,8,13,21,\\ldots\\}$.\n

    \n

    \nWe let $f(n)$ be the number of ways of representing an integer $n\\ge 0$ as the sum of different Fibonacci numbers.
    \nFor example, $16 = 3+13 = 1+2+13 = 3+5+8 = 1+2+5+8$ and hence $f(16) = 4$. \nBy convention $f(0) = 1$.\n

    \n

    \nFurther we define\n$$S(n) = \\sum_{k=0}^n f(k).$$\nYou are given $S(100) = 415$ and $S(10^4) = 312807$.\n

    \n

    \nFind $\\displaystyle S(10^{13})$.\n

    ", "url": "https://projecteuler.net/problem=755", "answer": "2877071595975576960"} {"id": 756, "problem": "Consider a function $f(k)$ defined for all positive integers $k>0$. Let $S$ be the sum of the first $n$ values of $f$. That is,\n$$S=f(1)+f(2)+f(3)+\\cdots+f(n)=\\sum_{k=1}^n f(k).$$\n\nIn this problem, we employ randomness to approximate this sum. That is, we choose a random, uniformly distributed, $m$-tuple of positive integers $(X_1,X_2,X_3,\\cdots,X_m)$ such that $0=X_0 \\lt X_1 \\lt X_2 \\lt \\cdots \\lt X_m \\leq n$ and calculate a modified sum $S^*$ as follows.\n$$S^* = \\sum_{i=1}^m f(X_i)(X_i-X_{i-1})$$\n\nWe now define the error of this approximation to be $\\Delta=S-S^*$.\n\nLet $\\mathbb{E}(\\Delta|f(k),n,m)$ be the expected value of the error given the function $f(k)$, the number of terms $n$ in the sum and the length of random sample $m$.\n\nFor example, $\\mathbb{E}(\\Delta|k,100,50) = 2525/1326 \\approx 1.904223$ and $\\mathbb{E}(\\Delta|\\varphi(k),10^4,10^2)\\approx 5842.849907$, where $\\varphi(k)$ is Euler's totient function.\n\nFind $\\mathbb{E}(\\Delta|\\varphi(k),12345678,12345)$ rounded to six places after the decimal point.", "raw_html": "

    Consider a function $f(k)$ defined for all positive integers $k>0$. Let $S$ be the sum of the first $n$ values of $f$. That is,\n$$S=f(1)+f(2)+f(3)+\\cdots+f(n)=\\sum_{k=1}^n f(k).$$

    \n\n

    In this problem, we employ randomness to approximate this sum. That is, we choose a random, uniformly distributed, $m$-tuple of positive integers $(X_1,X_2,X_3,\\cdots,X_m)$ such that $0=X_0 \\lt X_1 \\lt X_2 \\lt \\cdots \\lt X_m \\leq n$ and calculate a modified sum $S^*$ as follows.\n$$S^* = \\sum_{i=1}^m f(X_i)(X_i-X_{i-1})$$

    \n\n

    We now define the error of this approximation to be $\\Delta=S-S^*$.

    \n\n

    Let $\\mathbb{E}(\\Delta|f(k),n,m)$ be the expected value of the error given the function $f(k)$, the number of terms $n$ in the sum and the length of random sample $m$.

    \n\n

    For example, $\\mathbb{E}(\\Delta|k,100,50) = 2525/1326 \\approx 1.904223$ and $\\mathbb{E}(\\Delta|\\varphi(k),10^4,10^2)\\approx 5842.849907$, where $\\varphi(k)$ is Euler's totient function.

    \n\n

    Find $\\mathbb{E}(\\Delta|\\varphi(k),12345678,12345)$ rounded to six places after the decimal point.

    ", "url": "https://projecteuler.net/problem=756", "answer": "607238.610661"} {"id": 757, "problem": "A positive integer $N$ is stealthy, if there exist positive integers $a$, $b$, $c$, $d$ such that $ab = cd = N$ and $a+b = c+d+1$.\n\nFor example, $36 = 4\\times 9 = 6\\times 6$ is stealthy.\n\nYou are also given that there are 2851 stealthy numbers not exceeding $10^6$.\n\nHow many stealthy numbers are there that don't exceed $10^{14}$?", "raw_html": "

    \nA positive integer $N$ is stealthy, if there exist positive integers $a$, $b$, $c$, $d$ such that $ab = cd = N$ and $a+b = c+d+1$.
    \nFor example, $36 = 4\\times 9 = 6\\times 6$ is stealthy.\n

    \n

    \nYou are also given that there are 2851 stealthy numbers not exceeding $10^6$.\n

    \n

    \nHow many stealthy numbers are there that don't exceed $10^{14}$?\n

    ", "url": "https://projecteuler.net/problem=757", "answer": "75737353"} {"id": 758, "problem": "There are 3 buckets labelled $S$ (small) of 3 litres, $M$ (medium) of 5 litres and $L$ (large) of 8 litres.\n\nInitially $S$ and $M$ are full of water and $L$ is empty.\nBy pouring water between the buckets exactly one litre of water can be measured.\n\nSince there is no other way to measure, once a pouring starts it cannot stop until either the source bucket is empty or the destination bucket is full.\n\nAt least four pourings are needed to get one litre:\n\n$(3,5,0)\\xrightarrow{M\\to L} (3,0,5) \\xrightarrow{S\\to M} (0,3,5) \\xrightarrow{L\\to S}(3,3,2)\n\\xrightarrow{S\\to M}(1,5,2)$\n\nAfter these operations, there is exactly one litre in bucket $S$.\n\nIn general the sizes of the buckets $S, M, L$ are $a$, $b$, $a + b$ litres, respectively. Initially $S$ and $M$ are full and $L$ is empty. If the above rule of pouring still applies and $a$ and $b$ are two coprime positive integers with $a\\leq b$ then it is always possible to measure one litre in finitely many steps.\n\nLet $P(a,b)$ be the minimal number of pourings needed to get one litre. Thus $P(3,5)=4$.\n\nAlso, $P(7, 31)=20$ and $P(1234, 4321)=2780$.\n\nFind the sum of $P(2^{p^5}-1, 2^{q^5}-1)$ for all pairs of prime numbers $p,q$ such that $p < q < 1000$.\n\nGive your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nThere are 3 buckets labelled $S$ (small) of 3 litres, $M$ (medium) of 5 litres and $L$ (large) of 8 litres.
    \nInitially $S$ and $M$ are full of water and $L$ is empty.\nBy pouring water between the buckets exactly one litre of water can be measured.
    \nSince there is no other way to measure, once a pouring starts it cannot stop until either the source bucket is empty or the destination bucket is full.
    \nAt least four pourings are needed to get one litre:\n

    \n
    \n$(3,5,0)\\xrightarrow{M\\to L} (3,0,5) \\xrightarrow{S\\to M} (0,3,5) \\xrightarrow{L\\to S}(3,3,2)\n\\xrightarrow{S\\to M}(1,5,2)$
    \n

    \nAfter these operations, there is exactly one litre in bucket $S$.\n

    \n

    \nIn general the sizes of the buckets $S, M, L$ are $a$, $b$, $a + b$ litres, respectively. Initially $S$ and $M$ are full and $L$ is empty. If the above rule of pouring still applies and $a$ and $b$ are two coprime positive integers with $a\\leq b$ then it is always possible to measure one litre in finitely many steps.\n

    \n

    \nLet $P(a,b)$ be the minimal number of pourings needed to get one litre. Thus $P(3,5)=4$.
    \nAlso, $P(7, 31)=20$ and $P(1234, 4321)=2780$.\n

    \n

    \nFind the sum of $P(2^{p^5}-1, 2^{q^5}-1)$ for all pairs of prime numbers $p,q$ such that $p < q < 1000$.
    \nGive your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=758", "answer": "331196954"} {"id": 759, "problem": "The function $f$ is defined for all positive integers as follows:\n\n$$\\begin{align*}\nf(1) &= 1\\\\\nf(2n) &= 2f(n)\\\\\nf(2n+1) &= 2n+1 + 2f(n)+\\tfrac 1n f(n)\n\\end{align*}$$\nIt can be proven that $f(n)$ is integer for all values of $n$.\n\nThe function $S(n)$ is defined as $S(n) = \\displaystyle \\sum_{i=1}^n f(i) ^2$.\n\nFor example, $S(10)=1530$ and $S(10^2)=4798445$.\n\nFind $S(10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    The function $f$ is defined for all positive integers as follows:

    \n$$\\begin{align*}\nf(1) &= 1\\\\\nf(2n) &= 2f(n)\\\\\nf(2n+1) &= 2n+1 + 2f(n)+\\tfrac 1n f(n)\n\\end{align*}$$\n

    It can be proven that $f(n)$ is integer for all values of $n$.

    \n\n

    The function $S(n)$ is defined as $S(n) = \\displaystyle \\sum_{i=1}^n f(i) ^2$.

    \n

    For example, $S(10)=1530$ and $S(10^2)=4798445$.

    \n\n

    Find $S(10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=759", "answer": "282771304"} {"id": 760, "problem": "Define\n$$\\displaystyle g(m,n) = (m\\oplus n)+(m\\vee n)+(m\\wedge n)$$\nwhere $\\oplus, \\vee, \\wedge$ are the bitwise XOR, OR and AND operator respectively.\n\nAlso set\n$$\\displaystyle G(N) = \\sum_{n=0}^N\\sum_{k=0}^n g(k,n-k)$$\n\nFor example, $G(10) = 754$ and $G(10^2) = 583766$.\n\nFind $G(10^{18})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    Define\n$$\\displaystyle g(m,n) = (m\\oplus n)+(m\\vee n)+(m\\wedge n)$$\nwhere $\\oplus, \\vee, \\wedge$ are the bitwise XOR, OR and AND operator respectively.

    \n

    Also set\n$$\\displaystyle G(N) = \\sum_{n=0}^N\\sum_{k=0}^n g(k,n-k)$$

    \n

    For example, $G(10) = 754$ and $G(10^2) = 583766$.

    \n\n

    Find $G(10^{18})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=760", "answer": "172747503"} {"id": 761, "problem": "Two friends, a runner and a swimmer, are playing a sporting game: The swimmer is swimming within a circular pool while the runner moves along the pool edge.\nWhile the runner tries to catch the swimmer at the very moment that the swimmer leaves the pool, the swimmer tries to reach the edge before the runner arrives there. They start the game with the swimmer located in the middle of the pool, while the runner is located anywhere at the edge of the pool.\n\nWe assume that the swimmer can move with any velocity up to $1$ in any direction and the runner can move with any velocity up to $v$ in either direction around the edge of the pool. Moreover we assume that both players can react immediately to any change of movement of their opponent.\n\nAssuming optimal strategy of both players, it can be shown that the swimmer can always win by escaping the pool at some point at the edge before the runner gets there, if $v$ is less than the critical speed $V_{\\text{Circle}} \\approx 4.60333885$ and can never win if $v \\gt V_{\\text{Circle}}$.\n\nNow the two players play the game in a perfectly square pool. Again the swimmer starts in the middle of the pool, while the runner starts at the midpoint of one of the edges of the pool. It can be shown that the critical maximal speed of the runner below which the swimmer can always escape and above which the runner can always catch the swimmer when trying to leave the pool is $V_{\\text{Square}} \\approx 5.78859314$.\n\nAt last, both players decide to play the game in a pool in the form of regular hexagon. Giving the same conditions as above, with the swimmer starting in the middle of the pool and the runner at the midpoint of one of the edges of the pool, find the critical maximal speed $V_{\\text{Hexagon}}$ of the runner, below which the swimmer can always escape and above which the runner can always catch the swimmer.\nGive your answer rounded to 8 digits after the decimal point.", "raw_html": "

    Two friends, a runner and a swimmer, are playing a sporting game: The swimmer is swimming within a circular pool while the runner moves along the pool edge.\nWhile the runner tries to catch the swimmer at the very moment that the swimmer leaves the pool, the swimmer tries to reach the edge before the runner arrives there. They start the game with the swimmer located in the middle of the pool, while the runner is located anywhere at the edge of the pool.

    \n\n

    We assume that the swimmer can move with any velocity up to $1$ in any direction and the runner can move with any velocity up to $v$ in either direction around the edge of the pool. Moreover we assume that both players can react immediately to any change of movement of their opponent.

    \n\n

    Assuming optimal strategy of both players, it can be shown that the swimmer can always win by escaping the pool at some point at the edge before the runner gets there, if $v$ is less than the critical speed $V_{\\text{Circle}} \\approx 4.60333885$ and can never win if $v \\gt V_{\\text{Circle}}$.

    \n\n

    Now the two players play the game in a perfectly square pool. Again the swimmer starts in the middle of the pool, while the runner starts at the midpoint of one of the edges of the pool. It can be shown that the critical maximal speed of the runner below which the swimmer can always escape and above which the runner can always catch the swimmer when trying to leave the pool is $V_{\\text{Square}} \\approx 5.78859314$.

    \n\n

    At last, both players decide to play the game in a pool in the form of regular hexagon. Giving the same conditions as above, with the swimmer starting in the middle of the pool and the runner at the midpoint of one of the edges of the pool, find the critical maximal speed $V_{\\text{Hexagon}}$ of the runner, below which the swimmer can always escape and above which the runner can always catch the swimmer.\nGive your answer rounded to 8 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=761", "answer": "5.05505046"} {"id": 762, "problem": "Consider a two dimensional grid of squares. The grid has 4 rows but infinitely many columns.\n\nAn amoeba in square $(x, y)$ can divide itself into two amoebas to occupy the squares $(x+1,y)$ and $(x+1,(y+1) \\bmod 4)$, provided these squares are empty.\n\nThe following diagrams show two cases of an amoeba placed in square A of each grid. When it divides, it is replaced with two amoebas, one at each of the squares marked with B:\n\nOriginally there is only one amoeba in the square $(0, 0)$. After $N$ divisions there will be $N+1$ amoebas arranged in the grid. An arrangement may be reached in several different ways but it is only counted once. Let $C(N)$ be the number of different possible arrangements after $N$ divisions.\n\nFor example, $C(2) = 2$, $C(10) = 1301$, $C(20)=5895236$ and the last nine digits of $C(100)$ are $125923036$.\n\nFind $C(100\\,000)$, enter the last nine digits as your answer.", "raw_html": "

    Consider a two dimensional grid of squares. The grid has 4 rows but infinitely many columns.

    \n

    An amoeba in square $(x, y)$ can divide itself into two amoebas to occupy the squares $(x+1,y)$ and $(x+1,(y+1) \\bmod 4)$, provided these squares are empty.

    \n\n

    The following diagrams show two cases of an amoeba placed in square A of each grid. When it divides, it is replaced with two amoebas, one at each of the squares marked with B:

    \n
    \n\"\"\n\"\"\n
    \n\n

    Originally there is only one amoeba in the square $(0, 0)$. After $N$ divisions there will be $N+1$ amoebas arranged in the grid. An arrangement may be reached in several different ways but it is only counted once. Let $C(N)$ be the number of different possible arrangements after $N$ divisions.

    \n\n

    For example, $C(2) = 2$, $C(10) = 1301$, $C(20)=5895236$ and the last nine digits of $C(100)$ are $125923036$.

    \n\n

    Find $C(100\\,000)$, enter the last nine digits as your answer.

    ", "url": "https://projecteuler.net/problem=762", "answer": "285528863"} {"id": 763, "problem": "Consider a three dimensional grid of cubes. An amoeba in cube $(x, y, z)$ can divide itself into three amoebas to occupy the cubes $(x + 1, y, z)$, $(x, y + 1, z)$ and $(x, y, z + 1)$, provided these cubes are empty.\n\nOriginally there is only one amoeba in the cube $(0, 0, 0)$. After $N$ divisions there will be $2N+1$ amoebas arranged in the grid. An arrangement may be reached in several different ways but it is only counted once. Let $D(N)$ be the number of different possible arrangements after $N$ divisions.\n\nFor example, $D(2) = 3$, $D(10) = 44499$, $D(20)=9204559704$ and the last nine digits of $D(100)$ are $780166455$.\n\nFind $D(10\\,000)$, enter the last nine digits as your answer.", "raw_html": "

    \nConsider a three dimensional grid of cubes. An amoeba in cube $(x, y, z)$ can divide itself into three amoebas to occupy the cubes $(x + 1, y, z)$, $(x, y + 1, z)$ and $(x, y, z + 1)$, provided these cubes are empty.\n

    \n

    \nOriginally there is only one amoeba in the cube $(0, 0, 0)$. After $N$ divisions there will be $2N+1$ amoebas arranged in the grid. An arrangement may be reached in several different ways but it is only counted once. Let $D(N)$ be the number of different possible arrangements after $N$ divisions.\n

    \n

    \nFor example, $D(2) = 3$, $D(10) = 44499$, $D(20)=9204559704$ and the last nine digits of $D(100)$ are $780166455$.\n

    \n

    \nFind $D(10\\,000)$, enter the last nine digits as your answer.\n

    ", "url": "https://projecteuler.net/problem=763", "answer": "798443574"} {"id": 764, "problem": "Consider the following Diophantine equation:\n$$16x^2+y^4=z^2$$\nwhere $x$, $y$ and $z$ are positive integers.\n\nLet $S(N) = \\displaystyle{\\sum(x+y+z)}$ where the sum is over all solutions $(x,y,z)$ such that $1 \\leq x,y,z \\leq N$ and $\\gcd(x,y,z)=1$.\n\nFor $N=100$, there are only two such solutions: $(3,4,20)$ and $(10,3,41)$. So $S(10^2)=81$.\n\nYou are also given that $S(10^4)=112851$ (with $26$ solutions), and $S(10^7)\\equiv 248876211 \\pmod{10^9}$.\n\nFind $S(10^{16})$. Give your answer modulo $10^9$.", "raw_html": "

    \nConsider the following Diophantine equation:\n$$16x^2+y^4=z^2$$\nwhere $x$, $y$ and $z$ are positive integers.\n

    \n

    \nLet $S(N) = \\displaystyle{\\sum(x+y+z)}$ where the sum is over all solutions $(x,y,z)$ such that $1 \\leq x,y,z \\leq N$ and $\\gcd(x,y,z)=1$. \n

    \n

    \nFor $N=100$, there are only two such solutions: $(3,4,20)$ and $(10,3,41)$. So $S(10^2)=81$.\n

    \n

    \nYou are also given that $S(10^4)=112851$ (with $26$ solutions), and $S(10^7)\\equiv 248876211 \\pmod{10^9}$.\n

    \n

    \nFind $S(10^{16})$. Give your answer modulo $10^9$.\n

    ", "url": "https://projecteuler.net/problem=764", "answer": "255228881"} {"id": 765, "problem": "Starting with $1$ gram of gold you play a game. Each round you bet a certain amount of your gold: if you have $x$ grams you can bet $b$ grams for any $0 \\le b \\le x$. You then toss an unfair coin: with a probability of $0.6$ you double your bet (so you now have $x+b$), otherwise you lose your bet (so you now have $x-b$).\n\nChoosing your bets to maximize your probability of having at least a trillion ($10^{12}$) grams of gold after $1000$ rounds, what is the probability that you become a trillionaire?\n\nAll computations are assumed to be exact (no rounding), but give your answer rounded to $10$ digits behind the decimal point.", "raw_html": "

    \nStarting with $1$ gram of gold you play a game. Each round you bet a certain amount of your gold: if you have $x$ grams you can bet $b$ grams for any $0 \\le b \\le x$. You then toss an unfair coin: with a probability of $0.6$ you double your bet (so you now have $x+b$), otherwise you lose your bet (so you now have $x-b$).\n

    \n

    \nChoosing your bets to maximize your probability of having at least a trillion ($10^{12}$) grams of gold after $1000$ rounds, what is the probability that you become a trillionaire?\n

    \n

    \nAll computations are assumed to be exact (no rounding), but give your answer rounded to $10$ digits behind the decimal point.\n

    ", "url": "https://projecteuler.net/problem=765", "answer": "0.2429251641"} {"id": 766, "problem": "A sliding block puzzle is a puzzle where pieces are confined to a grid and by sliding the pieces a final configuration is reached. In this problem the pieces can only be slid in multiples of one unit in the directions up, down, left, right.\n\nA reachable configuration is any arrangement of the pieces that can be achieved by sliding the pieces from the initial configuration.\n\nTwo configurations are identical if the same shape pieces occupy the same position in the grid. So in the case below the red squares are indistinguishable. For this example the number of reachable configurations is $208$.\n\nFind the number of reachable configurations for the puzzle below. Note that the red L-shaped pieces are considered different from the green L-shaped pieces.", "raw_html": "

    A sliding block puzzle is a puzzle where pieces are confined to a grid and by sliding the pieces a final configuration is reached. In this problem the pieces can only be slid in multiples of one unit in the directions up, down, left, right.

    \n\n

    A reachable configuration is any arrangement of the pieces that can be achieved by sliding the pieces from the initial configuration.

    \n\n

    Two configurations are identical if the same shape pieces occupy the same position in the grid. So in the case below the red squares are indistinguishable. For this example the number of reachable configurations is $208$.

    \n
    \n\"\"
    \n\n\n

    Find the number of reachable configurations for the puzzle below. Note that the red L-shaped pieces are considered different from the green L-shaped pieces.\n\n\n

    \n\"\"
    ", "url": "https://projecteuler.net/problem=766", "answer": "2613742"} {"id": 767, "problem": "A window into a matrix is a contiguous sub matrix.\n\nConsider a $16\\times n$ matrix where every entry is either $0$ or $1$.\nLet $B(k,n)$ be the total number of these matrices such that the sum of the entries in every $2\\times k$ window is $k$.\n\nYou are given that $B(2,4) = 65550$ and $B(3,9) \\equiv 87273560 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $B(10^5,10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    A window into a matrix is a contiguous sub matrix.

    \n\n

    Consider a $16\\times n$ matrix where every entry is either $0$ or $1$.\nLet $B(k,n)$ be the total number of these matrices such that the sum of the entries in every $2\\times k$ window is $k$.

    \n\n

    You are given that $B(2,4) = 65550$ and $B(3,9) \\equiv 87273560 \\pmod{1\\,000\\,000\\,007}$.

    \n\n

    Find $B(10^5,10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=767", "answer": "783976175"} {"id": 768, "problem": "A certain type of chandelier contains a circular ring of $n$ evenly spaced candleholders.\n\nIf only one candle is fitted, then the chandelier will be imbalanced. However, if a second identical candle is placed in the opposite candleholder (assuming $n$ is even) then perfect balance will be achieved and the chandelier will hang level.\n\nLet $f(n,m)$ be the number of ways of arranging $m$ identical candles in distinct sockets of a chandelier with $n$ candleholders such that the chandelier is perfectly balanced.\n\nFor example, $f(4, 2) = 2$: assuming the chandelier's four candleholders are aligned with the compass points, the two valid arrangements are \"North & South\" and \"East & West\". Note that these are considered to be different arrangements even though they are related by rotation.\n\nYou are given that $f(12,4) = 15$ and $f(36, 6) = 876$.\n\nFind $f(360, 20)$.", "raw_html": "

    A certain type of chandelier contains a circular ring of $n$ evenly spaced candleholders.
    \nIf only one candle is fitted, then the chandelier will be imbalanced. However, if a second identical candle is placed in the opposite candleholder (assuming $n$ is even) then perfect balance will be achieved and the chandelier will hang level.

    \n\n

    Let $f(n,m)$ be the number of ways of arranging $m$ identical candles in distinct sockets of a chandelier with $n$ candleholders such that the chandelier is perfectly balanced.

    \n\n

    For example, $f(4, 2) = 2$: assuming the chandelier's four candleholders are aligned with the compass points, the two valid arrangements are \"North & South\" and \"East & West\". Note that these are considered to be different arrangements even though they are related by rotation.

    \n\n

    You are given that $f(12,4) = 15$ and $f(36, 6) = 876$.

    \n\n

    Find $f(360, 20)$.

    ", "url": "https://projecteuler.net/problem=768", "answer": "14655308696436060"} {"id": 769, "problem": "Consider the following binary quadratic form:\n\n$$\n\\begin{align}\nf(x,y)=x^2+5xy+3y^2\n\\end{align}\n$$\nA positive integer $q$ has a primitive representation if there exist positive integers $x$ and $y$ such that $q = f(x,y)$ and $\\gcd(x,y)=1$.\n\nWe are interested in primitive representations of perfect squares. For example:\n\n$17^2=f(1,9)$\n\n$87^2=f(13,40) = f(46,19)$\n\nDefine $C(N)$ as the total number of primitive representations of $z^2$ for $0 < z \\leq N$.\n\nMultiple representations are counted separately, so for example $z=87$ is counted twice.\n\nYou are given $C(10^3)=142$ and $C(10^{6})=142463$.\n\nFind $C(10^{14})$.", "raw_html": "

    Consider the following binary quadratic form:

    \n$$\n\\begin{align}\nf(x,y)=x^2+5xy+3y^2\n\\end{align}\n$$\n

    A positive integer $q$ has a primitive representation if there exist positive integers $x$ and $y$ such that $q = f(x,y)$ and $\\gcd(x,y)=1$.

    \n\n

    We are interested in primitive representations of perfect squares. For example:
    \n$17^2=f(1,9)$
    \n$87^2=f(13,40) = f(46,19)$

    \n\n

    Define $C(N)$ as the total number of primitive representations of $z^2$ for $0 < z \\leq N$.
    \nMultiple representations are counted separately, so for example $z=87$ is counted twice.

    \n\n

    You are given $C(10^3)=142$ and $C(10^{6})=142463$.

    \n\n

    Find $C(10^{14})$.

    ", "url": "https://projecteuler.net/problem=769", "answer": "14246712611506"} {"id": 770, "problem": "A and B play a game. A has originally $1$ gram of gold and B has an unlimited amount.\nEach round goes as follows:\n\n-\nA chooses and displays, $x$, a nonnegative real number no larger than the amount of gold that A has.\n\n-\nEither B chooses to TAKE. Then A gives B $x$ grams of gold.\n\n-\nOr B chooses to GIVE. Then B gives A $x$ grams of gold.\n\nB TAKEs $n$ times and GIVEs $n$ times after which the game finishes.\n\nDefine $g(X)$ to be the smallest value of $n$ so that A can guarantee to have at least $X$ grams of gold at the end of the game. You are given $g(1.7) = 10$.\n\nFind $g(1.9999)$.", "raw_html": "

    \nA and B play a game. A has originally $1$ gram of gold and B has an unlimited amount.\nEach round goes as follows:\n

    \n
      \n
    • \nA chooses and displays, $x$, a nonnegative real number no larger than the amount of gold that A has.
    • \n
    • \nEither B chooses to TAKE. Then A gives B $x$ grams of gold.
    • \n
    • \nOr B chooses to GIVE. Then B gives A $x$ grams of gold.
    • \n
    \n

    \nB TAKEs $n$ times and GIVEs $n$ times after which the game finishes.

    \n

    \nDefine $g(X)$ to be the smallest value of $n$ so that A can guarantee to have at least $X$ grams of gold at the end of the game. You are given $g(1.7) = 10$.\n

    \n

    \nFind $g(1.9999)$.\n

    ", "url": "https://projecteuler.net/problem=770", "answer": "127311223"} {"id": 771, "problem": "We define a pseudo-geometric sequence to be a finite sequence $a_0, a_1, \\dotsc, a_n$ of positive integers, satisfying the following conditions:\n\n- $n \\geq 4$, i.e. the sequence has at least $5$ terms.\n\n- $0 \\lt a_0 \\lt a_1 \\lt \\cdots \\lt a_n$, i.e. the sequence is strictly increasing.\n\n- $| a_i^2 - a_{i - 1}a_{i + 1} | \\le 2$ for $1 \\le i \\le n-1$.\n\nLet $G(N)$ be the number of different pseudo-geometric sequences whose terms do not exceed $N$.\n\nFor example, $G(6) = 4$, as the following $4$ sequences give a complete list:\n\n$1, 2, 3, 4, 5 \\qquad 1, 2, 3, 4, 6 \\qquad 2, 3, 4, 5, 6 \\qquad 1, 2, 3, 4, 5, 6$\n\nAlso, $G(10) = 26$, $G(100) = 4710$ and $G(1000) = 496805$.\n\nFind $G(10^{18})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nWe define a pseudo-geometric sequence to be a finite sequence $a_0, a_1, \\dotsc, a_n$ of positive integers, satisfying the following conditions:\n

      \n
    • $n \\geq 4$, i.e. the sequence has at least $5$ terms.
    • \n
    • $0 \\lt a_0 \\lt a_1 \\lt \\cdots \\lt a_n$, i.e. the sequence is strictly increasing.
    • \n
    • $| a_i^2 - a_{i - 1}a_{i + 1} | \\le 2$ for $1 \\le i \\le n-1$.
    • \n
    \n

    \nLet $G(N)$ be the number of different pseudo-geometric sequences whose terms do not exceed $N$.
    \nFor example, $G(6) = 4$, as the following $4$ sequences give a complete list:\n

    $1, 2, 3, 4, 5 \\qquad 1, 2, 3, 4, 6 \\qquad 2, 3, 4, 5, 6 \\qquad 1, 2, 3, 4, 5, 6$
    \n

    \nAlso, $G(10) = 26$, $G(100) = 4710$ and $G(1000) = 496805$.

    \n

    \nFind $G(10^{18})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=771", "answer": "398803409"} {"id": 772, "problem": "A $k$-bounded partition of a positive integer $N$ is a way of writing $N$ as a sum of positive integers not exceeding $k$.\n\nA balanceable partition is a partition that can be further divided into two parts of equal sums.\n\nFor example, $3 + 2 + 2 + 2 + 2 + 1$ is a balanceable $3$-bounded partition of $12$ since $3 + 2 + 1 = 2 + 2 + 2$. Conversely, $3 + 3 + 3 + 1$ is a $3$-bounded partition of $10$ which is not balanceable.\n\nLet $f(k)$ be the smallest positive integer $N$ all of whose $k$-bounded partitions are balanceable. For example, $f(3) = 12$ and $f(30) \\equiv 179092994 \\pmod {1\\,000\\,000\\,007}$.\n\nFind $f(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    A $k$-bounded partition of a positive integer $N$ is a way of writing $N$ as a sum of positive integers not exceeding $k$.

    \n\n

    A balanceable partition is a partition that can be further divided into two parts of equal sums.

    \n\n

    For example, $3 + 2 + 2 + 2 + 2 + 1$ is a balanceable $3$-bounded partition of $12$ since $3 + 2 + 1 = 2 + 2 + 2$. Conversely, $3 + 3 + 3 + 1$ is a $3$-bounded partition of $10$ which is not balanceable.

    \n\n

    Let $f(k)$ be the smallest positive integer $N$ all of whose $k$-bounded partitions are balanceable. For example, $f(3) = 12$ and $f(30) \\equiv 179092994 \\pmod {1\\,000\\,000\\,007}$.

    \n\n

    Find $f(10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=772", "answer": "83985379"} {"id": 773, "problem": "Let $S_k$ be the set containing $2$ and $5$ and the first $k$ primes that end in $7$. For example, $S_3 = \\{2,5,7,17,37\\}$.\n\nDefine a $k$-Ruff number to be one that is not divisible by any element in $S_k$.\n\nIf $N_k$ is the product of the numbers in $S_k$ then define $F(k)$ to be the sum of all $k$-Ruff numbers less than $N_k$ that have last digit $7$. You are given $F(3) = 76101452$.\n\nFind $F(97)$, give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nLet $S_k$ be the set containing $2$ and $5$ and the first $k$ primes that end in $7$. For example, $S_3 = \\{2,5,7,17,37\\}$.

    \n\n

    \nDefine a $k$-Ruff number to be one that is not divisible by any element in $S_k$.

    \n\n

    \nIf $N_k$ is the product of the numbers in $S_k$ then define $F(k)$ to be the sum of all $k$-Ruff numbers less than $N_k$ that have last digit $7$. You are given $F(3) = 76101452$.

    \n\n

    \nFind $F(97)$, give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=773", "answer": "556206950"} {"id": 774, "problem": "Let '$\\&$' denote the bitwise AND operation.\n\nFor example, $10\\,\\&\\, 12 = 1010_2\\,\\&\\, 1100_2 = 1000_2 = 8$.\n\nWe shall call a finite sequence of non-negative integers $(a_1, a_2, \\ldots, a_n)$ conjunctive if $a_i\\,\\&\\, a_{i+1} \\neq 0$ for all $i=1\\ldots n-1$.\n\nDefine $c(n,b)$ to be the number of conjunctive sequences of length $n$ in which all terms are $\\le b$.\n\nYou are given that $c(3,4)=18$, $c(10,6)=2496120$, and $c(100,200) \\equiv 268159379 \\pmod {998244353}$.\n\nFind $c(123,123456789)$. Give your answer modulo $998244353$.", "raw_html": "

    Let '$\\&$' denote the bitwise AND operation.
    \nFor example, $10\\,\\&\\, 12 = 1010_2\\,\\&\\, 1100_2 = 1000_2 = 8$.

    \n\n

    We shall call a finite sequence of non-negative integers $(a_1, a_2, \\ldots, a_n)$ conjunctive if $a_i\\,\\&\\, a_{i+1} \\neq 0$ for all $i=1\\ldots n-1$.

    \n\n

    Define $c(n,b)$ to be the number of conjunctive sequences of length $n$ in which all terms are $\\le b$.

    \n

    You are given that $c(3,4)=18$, $c(10,6)=2496120$, and $c(100,200) \\equiv 268159379 \\pmod {998244353}$.

    \n\n

    Find $c(123,123456789)$. Give your answer modulo $998244353$.

    ", "url": "https://projecteuler.net/problem=774", "answer": "459155763"} {"id": 775, "problem": "When wrapping several cubes in paper, it is more efficient to wrap them all together than to wrap each one individually. For example, with 10 cubes of unit edge length, it would take 30 units of paper to wrap them in the arrangement shown below, but 60 units to wrap them separately.\n\nDefine $g(n)$ to be the maximum amount of paper that can be saved by wrapping $n$ identical $1\\times 1\\times 1$ cubes in a compact arrangement, compared with wrapping them individually. We insist that the wrapping paper is in contact with the cubes at all points, without leaving a void.\n\nWith $10$ cubes, the arrangement illustrated above is optimal, so $g(10)=60-30=30$. With $18$ cubes, it can be shown that the optimal arrangement is as a $3\\times 3\\times 2$, using $42$ units of paper, whereas wrapping individually would use $108$ units of paper; hence $g(18) = 66$.\n\nDefine\n$$G(N) = \\sum_{n=1}^N g(n).$$\nYou are given that $G(18) = 530$, and $G(10^6) \\equiv 951640919 \\pmod {1\\,000\\,000\\,007}$.\n\nFind $G(10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    When wrapping several cubes in paper, it is more efficient to wrap them all together than to wrap each one individually. For example, with 10 cubes of unit edge length, it would take 30 units of paper to wrap them in the arrangement shown below, but 60 units to wrap them separately.

    \n\n
    \n\"\"
    \n\n\n

    Define $g(n)$ to be the maximum amount of paper that can be saved by wrapping $n$ identical $1\\times 1\\times 1$ cubes in a compact arrangement, compared with wrapping them individually. We insist that the wrapping paper is in contact with the cubes at all points, without leaving a void.

    \n\n

    With $10$ cubes, the arrangement illustrated above is optimal, so $g(10)=60-30=30$. With $18$ cubes, it can be shown that the optimal arrangement is as a $3\\times 3\\times 2$, using $42$ units of paper, whereas wrapping individually would use $108$ units of paper; hence $g(18) = 66$.

    \n\n

    Define\n$$G(N) = \\sum_{n=1}^N g(n).$$\nYou are given that $G(18) = 530$, and $G(10^6) \\equiv 951640919 \\pmod {1\\,000\\,000\\,007}$.

    \n\n

    Find $G(10^{16})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=775", "answer": "946791106"} {"id": 776, "problem": "For a positive integer $n$, $d(n)$ is defined to be the sum of the digits of $n$. For example, $d(12345)=15$.\n\nLet $\\displaystyle F(N)=\\sum_{n=1}^N \\frac n{d(n)}$.\n\nYou are given $F(10)=19$, $F(123)\\approx 1.187764610390\\mathrm e3$ and $F(12345)\\approx 4.855801996238\\mathrm e6$.\n\nFind $F(1234567890123456789)$. Write your answer in scientific notation rounded to twelve significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.", "raw_html": "

    \nFor a positive integer $n$, $d(n)$ is defined to be the sum of the digits of $n$. For example, $d(12345)=15$.\n

    \n

    \nLet $\\displaystyle F(N)=\\sum_{n=1}^N \\frac n{d(n)}$. \n

    \n

    \nYou are given $F(10)=19$, $F(123)\\approx 1.187764610390\\mathrm e3$ and $F(12345)\\approx 4.855801996238\\mathrm e6$.\n

    \n

    \nFind $F(1234567890123456789)$. Write your answer in scientific notation rounded to twelve significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.\n

    ", "url": "https://projecteuler.net/problem=776", "answer": "9.627509725002e33"} {"id": 777, "problem": "For coprime positive integers $a$ and $b$, let $C_{a,b}$ be the curve defined by:\n$$\n\\begin{align}\nx &= \\cos \\left(at\\right) \\\\\ny &= \\cos \\left(b\\left(t-\\frac{\\pi}{10}\\right)\\right)\n\\end{align}\n$$\nwhere $t$ varies between $0$ and $2\\pi$.\n\nFor example, the images below show $C_{2,5}$ (left) and $C_{7,4}$ (right):\n\nDefine $d(a,b) = \\sum (x^2 + y^2)$, where the sum is over all points (x, y) at which $C_{a,b}$ crosses itself.\n\nFor example, in the case of $C_{2,5}$ illustrated above, the curve crosses itself at two points: $(0.31, 0)$ and $(-0.81, 0)$, rounding coordinates to two decimal places, yielding $d(2, 5)=0.75$. Some other examples are $d(2,3)=4.5$, $d(7,4)=39.5$, $d(7,5)=52$, and $d(10,7)=23.25$.\n\nLet $s(m) = \\sum d(a,b)$, where this sum is over all pairs of coprime integers $a,b$ with $2\\le a\\le m$ and $2\\le b\\le m$.\n\nYou are given that $s(10) = 1602.5$ and $s(100) = 24256505$.\n\nFind $s(10^6)$. Give your answer in scientific notation rounded to $10$ significant digits; for example $s(100)$ would be given as 2.425650500e7.", "raw_html": "

    For coprime positive integers $a$ and $b$, let $C_{a,b}$ be the curve defined by:\n$$\n\\begin{align}\nx &= \\cos \\left(at\\right) \\\\\ny &= \\cos \\left(b\\left(t-\\frac{\\pi}{10}\\right)\\right)\n\\end{align}\n$$\nwhere $t$ varies between $0$ and $2\\pi$.

    \n\n

    For example, the images below show $C_{2,5}$ (left) and $C_{7,4}$ (right):

    \n
    \n\"\"\n
    \n

    Define $d(a,b) = \\sum (x^2 + y^2)$, where the sum is over all points (x, y) at which $C_{a,b}$ crosses itself.

    \n\n

    For example, in the case of $C_{2,5}$ illustrated above, the curve crosses itself at two points: $(0.31, 0)$ and $(-0.81, 0)$, rounding coordinates to two decimal places, yielding $d(2, 5)=0.75$. Some other examples are $d(2,3)=4.5$, $d(7,4)=39.5$, $d(7,5)=52$, and $d(10,7)=23.25$.

    \n\n

    Let $s(m) = \\sum d(a,b)$, where this sum is over all pairs of coprime integers $a,b$ with $2\\le a\\le m$ and $2\\le b\\le m$.
    \nYou are given that $s(10) = 1602.5$ and $s(100) = 24256505$.

    \n\n

    Find $s(10^6)$. Give your answer in scientific notation rounded to $10$ significant digits; for example $s(100)$ would be given as 2.425650500e7.

    ", "url": "https://projecteuler.net/problem=777", "answer": "2.533018434e23"} {"id": 778, "problem": "If $a,b$ are two nonnegative integers with decimal representations $a=(\\dots a_2a_1a_0)$ and $b=(\\dots b_2b_1b_0)$ respectively, then the freshman's product of $a$ and $b$, denoted $a\\boxtimes b$, is the integer $c$ with decimal representation $c=(\\dots c_2c_1c_0)$ such that $c_i$ is the last digit of $a_i\\cdot b_i$.\n\nFor example, $234 \\boxtimes 765 = 480$.\n\nLet $F(R,M)$ be the sum of $x_1 \\boxtimes \\dots \\boxtimes x_R$ for all sequences of integers $(x_1,\\dots,x_R)$ with $0\\leq x_i \\leq M$.\n\nFor example, $F(2, 7) = 204$, and $F(23, 76) \\equiv 5870548 \\pmod{ 1\\,000\\,000\\,009}$.\n\nFind $F(234567,765432)$. Give your answer modulo $1\\,000\\,000\\,009$.", "raw_html": "

    \nIf $a,b$ are two nonnegative integers with decimal representations $a=(\\dots a_2a_1a_0)$ and $b=(\\dots b_2b_1b_0)$ respectively, then the freshman's product of $a$ and $b$, denoted $a\\boxtimes b$, is the integer $c$ with decimal representation $c=(\\dots c_2c_1c_0)$ such that $c_i$ is the last digit of $a_i\\cdot b_i$.
    \nFor example, $234 \\boxtimes 765 = 480$.\n

    \n

    \nLet $F(R,M)$ be the sum of $x_1 \\boxtimes \\dots \\boxtimes x_R$ for all sequences of integers $(x_1,\\dots,x_R)$ with $0\\leq x_i \\leq M$.
    \nFor example, $F(2, 7) = 204$, and $F(23, 76) \\equiv 5870548 \\pmod{ 1\\,000\\,000\\,009}$.\n

    \n

    \nFind $F(234567,765432)$. Give your answer modulo $1\\,000\\,000\\,009$.\n

    ", "url": "https://projecteuler.net/problem=778", "answer": "146133880"} {"id": 779, "problem": "For a positive integer $n \\gt 1$, let $p(n)$ be the smallest prime dividing $n$, and let $\\alpha(n)$ be its $p$-adic order, i.e. the largest integer such that $p(n)^{\\alpha(n)}$ divides $n$.\n\nFor a positive integer $K$, define the function $f_K(n)$ by:\n$$f_K(n)=\\frac{\\alpha(n)-1}{(p(n))^K}.$$\n\nAlso define $\\overline{f_K}$ by:\n$$\\overline{f_K}=\\lim_{N \\to \\infty} \\frac{1}{N}\\sum_{n=2}^{N} f_K(n).$$\n\nIt can be verified that $\\overline{f_1} \\approx 0.282419756159$.\n\nFind $\\displaystyle \\sum_{K=1}^{\\infty}\\overline{f_K}$. Give your answer rounded to $12$ digits after the decimal point.", "raw_html": "

    \nFor a positive integer $n \\gt 1$, let $p(n)$ be the smallest prime dividing $n$, and let $\\alpha(n)$ be its $p$-adic order, i.e. the largest integer such that $p(n)^{\\alpha(n)}$ divides $n$.\n

    \n

    \nFor a positive integer $K$, define the function $f_K(n)$ by:\n$$f_K(n)=\\frac{\\alpha(n)-1}{(p(n))^K}.$$

    \n

    \nAlso define $\\overline{f_K}$ by:\n$$\\overline{f_K}=\\lim_{N \\to \\infty} \\frac{1}{N}\\sum_{n=2}^{N} f_K(n).$$

    \n

    \nIt can be verified that $\\overline{f_1} \\approx 0.282419756159$.\n

    \n

    \nFind $\\displaystyle \\sum_{K=1}^{\\infty}\\overline{f_K}$. Give your answer rounded to $12$ digits after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=779", "answer": "0.547326103833"} {"id": 780, "problem": "For positive real numbers $a,b$, an $a\\times b$ torus is a rectangle of width $a$ and height $b$, with left and right sides identified, as well as top and bottom sides identified. In other words, when tracing a path on the rectangle, reaching an edge results in \"wrapping round\" to the corresponding point on the opposite edge.\n\nA tiling of a torus is a way to dissect it into equilateral triangles of edge length 1. For example, the following three diagrams illustrate respectively a $1\\times \\frac{\\sqrt{3}}{2}$ torus with two triangles, a $\\sqrt{3}\\times 1$ torus with four triangles, and an approximately $2.8432\\times 2.1322$ torus with fourteen triangles:\n\nTwo tilings of an $a\\times b$ torus are called equivalent if it is possible to obtain one from the other by continuously moving all triangles so that no gaps appear and no triangles overlap at any stage during the movement. For example, the animation below shows an equivalence between two tilings:\n\nLet $F(n)$ be the total number of non-equivalent tilings of all possible tori with exactly $n$ triangles. For example, $F(6)=8$, with the eight non-equivalent tilings with six triangles listed below:\n\nLet $G(N)=\\sum_{n=1}^N F(n)$. You are given that $G(6)=14$, $G(100)=8090$, and $G(10^5)\\equiv 645124048 \\pmod{1\\,000\\,000\\,007}$.\n\nFind $G(10^9)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    For positive real numbers $a,b$, an $a\\times b$ torus is a rectangle of width $a$ and height $b$, with left and right sides identified, as well as top and bottom sides identified. In other words, when tracing a path on the rectangle, reaching an edge results in \"wrapping round\" to the corresponding point on the opposite edge.

    \n\n

    A tiling of a torus is a way to dissect it into equilateral triangles of edge length 1. For example, the following three diagrams illustrate respectively a $1\\times \\frac{\\sqrt{3}}{2}$ torus with two triangles, a $\\sqrt{3}\\times 1$ torus with four triangles, and an approximately $2.8432\\times 2.1322$ torus with fourteen triangles:

    \n
    \n\"\"\n\"\"\n\"\"\n
    \n\n

    Two tilings of an $a\\times b$ torus are called equivalent if it is possible to obtain one from the other by continuously moving all triangles so that no gaps appear and no triangles overlap at any stage during the movement. For example, the animation below shows an equivalence between two tilings:

    \n
    \n\"\"\n
    \n\n

    Let $F(n)$ be the total number of non-equivalent tilings of all possible tori with exactly $n$ triangles. For example, $F(6)=8$, with the eight non-equivalent tilings with six triangles listed below:

    \n
    \n\"\"\n
    \n\n

    Let $G(N)=\\sum_{n=1}^N F(n)$. You are given that $G(6)=14$, $G(100)=8090$, and $G(10^5)\\equiv 645124048 \\pmod{1\\,000\\,000\\,007}$.

    \n\n

    Find $G(10^9)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=780", "answer": "613979935"} {"id": 781, "problem": "Let $F(n)$ be the number of connected graphs with blue edges (directed) and red edges (undirected) containing:\n\n- two vertices of degree $1$, one with a single outgoing blue edge and the other with a single incoming blue edge.\n\n- $n$ vertices of degree $3$, each of which has an incoming blue edge, a different outgoing blue edge and a red edge.\n\nFor example, $F(4)=5$ because there are $5$ graphs with these properties:\n\nYou are also given $F(8)=319$.\n\nFind $F(50\\,000)$. Give your answer modulo $1\\,000\\,000\\,007$.\n\nNOTE: Feynman diagrams are a way of visualising the forces between elementary particles. Vertices represent interactions. The blue edges in our diagrams represent matter particles (e.g. electrons or positrons) with the arrow representing the flow of charge. The red edges (normally wavy lines) represent the force particles (e.g. photons). Feynman diagrams are used to predict the strength of particle interactions.", "raw_html": "

    Let $F(n)$ be the number of connected graphs with blue edges (directed) and red edges (undirected) containing:

    \n
      \n
    • two vertices of degree $1$, one with a single outgoing blue edge and the other with a single incoming blue edge.
    • \n
    • $n$ vertices of degree $3$, each of which has an incoming blue edge, a different outgoing blue edge and a red edge.
    • \n
    \n

    For example, $F(4)=5$ because there are $5$ graphs with these properties:

    \n
    \n\"\"\n
    \n\n

    You are also given $F(8)=319$.

    \n\n

    Find $F(50\\,000)$. Give your answer modulo $1\\,000\\,000\\,007$.

    \n\n

    NOTE: Feynman diagrams are a way of visualising the forces between elementary particles. Vertices represent interactions. The blue edges in our diagrams represent matter particles (e.g. electrons or positrons) with the arrow representing the flow of charge. The red edges (normally wavy lines) represent the force particles (e.g. photons). Feynman diagrams are used to predict the strength of particle interactions.

    ", "url": "https://projecteuler.net/problem=781", "answer": "162450870"} {"id": 782, "problem": "The complexity of an $n\\times n$ binary matrix is the number of distinct rows and columns.\n\nFor example, consider the $3\\times 3$ matrices\n$$\t\t\\mathbf{A} = \\begin{pmatrix} 1&0&1\\\\0&0&0\\\\1&0&1\\end{pmatrix}\t\\quad\n\\mathbf{B} = \\begin{pmatrix} 0&0&0\\\\0&0&0\\\\1&1&1\\end{pmatrix}\t$$\n$\\mathbf{A}$ has complexity $2$ because the set of rows and columns is $\\{000,101\\}$.\n$\\mathbf{B}$ has complexity $3$ because the set of rows and columns is $\\{000,001,111\\}$.\n\nFor $0 \\le k \\le n^2$, let $c(n, k)$ be the minimum complexity of an $n\\times n$ binary matrix with exactly $k$ ones.\n\nLet\n$$C(n) = \\sum_{k=0}^{n^2} c(n, k)$$\nFor example, $C(2) = c(2, 0) + c(2, 1) + c(2, 2) + c(2, 3) + c(2, 4) = 1 + 2 + 2 + 2 + 1 = 8$.\n\nYou are given $C(5) = 64$, $C(10) = 274$ and $C(20) = 1150$.\n\nFind $C(10^4)$.", "raw_html": "

    The complexity of an $n\\times n$ binary matrix is the number of distinct rows and columns.

    \n

    \nFor example, consider the $3\\times 3$ matrices\n$$\t\t\\mathbf{A} = \\begin{pmatrix} 1&0&1\\\\0&0&0\\\\1&0&1\\end{pmatrix}\t\\quad\n\t\t\\mathbf{B} = \\begin{pmatrix} 0&0&0\\\\0&0&0\\\\1&1&1\\end{pmatrix}\t$$\n$\\mathbf{A}$ has complexity $2$ because the set of rows and columns is $\\{000,101\\}$.\n$\\mathbf{B}$ has complexity $3$ because the set of rows and columns is $\\{000,001,111\\}$.

    \n

    \nFor $0 \\le k \\le n^2$, let $c(n, k)$ be the minimum complexity of an $n\\times n$ binary matrix with exactly $k$ ones.

    \n

    \nLet\n$$C(n) = \\sum_{k=0}^{n^2} c(n, k)$$\nFor example, $C(2) = c(2, 0) + c(2, 1) + c(2, 2) + c(2, 3) + c(2, 4) = 1 + 2 + 2 + 2 + 1 = 8$.
    \nYou are given $C(5) = 64$, $C(10) = 274$ and $C(20) = 1150$.

    \n

    \nFind $C(10^4)$.

    ", "url": "https://projecteuler.net/problem=782", "answer": "318313204"} {"id": 783, "problem": "Given $n$ and $k$ two positive integers we begin with an urn that contains $kn$ white balls. We then proceed through $n$ turns where on each turn $k$ black balls are added to the urn and then $2k$ random balls are removed from the urn.\n\nWe let $B_t(n,k)$ be the number of black balls that are removed on turn $t$.\n\nFurther define $E(n,k)$ as the expectation of $\\displaystyle \\sum_{t=1}^n B_t(n,k)^2$.\n\nYou are given $E(2,2) = 9.6$.\n\nFind $E(10^6,10)$. Round your answer to the nearest whole number.", "raw_html": "

    \nGiven $n$ and $k$ two positive integers we begin with an urn that contains $kn$ white balls. We then proceed through $n$ turns where on each turn $k$ black balls are added to the urn and then $2k$ random balls are removed from the urn.

    \n

    \nWe let $B_t(n,k)$ be the number of black balls that are removed on turn $t$.

    \n

    \nFurther define $E(n,k)$ as the expectation of $\\displaystyle \\sum_{t=1}^n B_t(n,k)^2$.

    \n

    \nYou are given $E(2,2) = 9.6$.

    \n

    \nFind $E(10^6,10)$. Round your answer to the nearest whole number.

    ", "url": "https://projecteuler.net/problem=783", "answer": "136666597"} {"id": 784, "problem": "Let's call a pair of positive integers $p$, $q$ ($p \\lt q$) reciprocal, if there is a positive integer $r\\lt p$ such that $r$ equals both the inverse of $p$ modulo $q$ and the inverse of $q$ modulo $p$.\n\nFor example, $(3,5)$ is one reciprocal pair for $r=2$.\n\nLet $F(N)$ be the total sum of $p+q$ for all reciprocal pairs $(p,q)$ where $p \\le N$.\n\n$F(5)=59$ due to these four reciprocal pairs $(3,5)$, $(4,11)$, $(5,7)$ and $(5,19)$.\n\nYou are also given $F(10^2) = 697317$.\n\nFind $F(2\\cdot 10^6)$.", "raw_html": "

    \nLet's call a pair of positive integers $p$, $q$ ($p \\lt q$) reciprocal, if there is a positive integer $r\\lt p$ such that $r$ equals both the inverse of $p$ modulo $q$ and the inverse of $q$ modulo $p$.

    \n\n

    \nFor example, $(3,5)$ is one reciprocal pair for $r=2$.
    \nLet $F(N)$ be the total sum of $p+q$ for all reciprocal pairs $(p,q)$ where $p \\le N$.

    \n\n

    \n$F(5)=59$ due to these four reciprocal pairs $(3,5)$, $(4,11)$, $(5,7)$ and $(5,19)$.
    \nYou are also given $F(10^2) = 697317$.

    \n\n

    \nFind $F(2\\cdot 10^6)$.

    ", "url": "https://projecteuler.net/problem=784", "answer": "5833303012576429231"} {"id": 785, "problem": "Consider the following Diophantine equation:\n$$15 (x^2 + y^2 + z^2) = 34 (xy + yz + zx)$$\nwhere $x$, $y$ and $z$ are positive integers.\n\nLet $S(N)$ be the sum of all solutions, $(x,y,z)$, of this equation such that, $1 \\le x \\le y \\le z \\le N$ and $\\gcd(x, y, z) = 1$.\n\nFor $N = 10^2$, there are three such solutions - $(1, 7, 16), (8, 9, 39), (11, 21, 72)$. So $S(10^2) = 184$.\n\nFind $S(10^9)$.", "raw_html": "

    \nConsider the following Diophantine equation:\n$$15 (x^2 + y^2 + z^2) = 34 (xy + yz + zx)$$\nwhere $x$, $y$ and $z$ are positive integers.\n

    \n

    \nLet $S(N)$ be the sum of all solutions, $(x,y,z)$, of this equation such that, $1 \\le x \\le y \\le z \\le N$ and $\\gcd(x, y, z) = 1$.\n

    \n

    \nFor $N = 10^2$, there are three such solutions - $(1, 7, 16), (8, 9, 39), (11, 21, 72)$. So $S(10^2) = 184$.\n

    \n

    \nFind $S(10^9)$.\n

    ", "url": "https://projecteuler.net/problem=785", "answer": "29526986315080920"} {"id": 786, "problem": "The following diagram shows a billiard table of a special quadrilateral shape.\nThe four angles $A, B, C, D$ are $120^\\circ, 90^\\circ, 60^\\circ, 90^\\circ$ respectively, and the lengths $AB$ and $AD$ are equal.\n\nThe diagram on the left shows the trace of an infinitesimally small billiard ball, departing from point $A$, bouncing twice on the edges of the table, and finally returning back to point $A$. The diagram on the right shows another such trace, but this time bouncing eight times:\n\nThe table has no friction and all bounces are perfect elastic collisions.\n\nNote that no bounce should happen on any of the corners, as the behaviour would be unpredictable.\n\nLet $B(N)$ be the number of possible traces of the ball, departing from point $A$, bouncing at most $N$ times on the edges and returning back to point $A$.\n\nFor example, $B(10) = 6$, $B(100) = 478$, $B(1000) = 45790$.\n\nFind $B(10^9)$.", "raw_html": "

    \nThe following diagram shows a billiard table of a special quadrilateral shape.\nThe four angles $A, B, C, D$ are $120^\\circ, 90^\\circ, 60^\\circ, 90^\\circ$ respectively, and the lengths $AB$ and $AD$ are equal.\n

    \n\n
    \n\"\"\n
    \n\n

    \nThe diagram on the left shows the trace of an infinitesimally small billiard ball, departing from point $A$, bouncing twice on the edges of the table, and finally returning back to point $A$. The diagram on the right shows another such trace, but this time bouncing eight times:\n

    \n\n
    \n\"\"\n
    \n\n

    \nThe table has no friction and all bounces are perfect elastic collisions.
    \nNote that no bounce should happen on any of the corners, as the behaviour would be unpredictable.\n

    \n\n

    \nLet $B(N)$ be the number of possible traces of the ball, departing from point $A$, bouncing at most $N$ times on the edges and returning back to point $A$.\n

    \n\n

    \nFor example, $B(10) = 6$, $B(100) = 478$, $B(1000) = 45790$.\n

    \n\n

    \nFind $B(10^9)$.\n

    ", "url": "https://projecteuler.net/problem=786", "answer": "45594532839912702"} {"id": 787, "problem": "Two players play a game with two piles of stones. They take alternating turns. If there are currently $a$ stones in the first pile and $b$ stones in the second, a turn consists of removing $c\\geq 0$ stones from the first pile and $d\\geq 0$ from the second in such a way that $ad-bc=\\pm1$. The winner is the player who first empties one of the piles.\n\nNote that the game is only playable if the sizes of the two piles are coprime.\n\nA game state $(a, b)$ is a winning position if the next player can guarantee a win with optimal play. Define $H(N)$ to be the number of winning positions $(a, b)$ with $\\gcd(a,b)=1$, $a > 0$, $b > 0$ and $a+b \\leq N$. Note the order matters, so for example $(2,1)$ and $(1,2)$ are distinct positions.\n\nYou are given $H(4)=5$ and $H(100)=2043$.\n\nFind $H(10^9)$.", "raw_html": "

    Two players play a game with two piles of stones. They take alternating turns. If there are currently $a$ stones in the first pile and $b$ stones in the second, a turn consists of removing $c\\geq 0$ stones from the first pile and $d\\geq 0$ from the second in such a way that $ad-bc=\\pm1$. The winner is the player who first empties one of the piles.

    \n\n

    Note that the game is only playable if the sizes of the two piles are coprime.

    \n\n

    A game state $(a, b)$ is a winning position if the next player can guarantee a win with optimal play. Define $H(N)$ to be the number of winning positions $(a, b)$ with $\\gcd(a,b)=1$, $a > 0$, $b > 0$ and $a+b \\leq N$. Note the order matters, so for example $(2,1)$ and $(1,2)$ are distinct positions.

    \n\n

    You are given $H(4)=5$ and $H(100)=2043$.

    \n\n

    Find $H(10^9)$.

    ", "url": "https://projecteuler.net/problem=787", "answer": "202642367520564145"} {"id": 788, "problem": "A dominating number is a positive integer that has more than half of its digits equal.\n\nFor example, $2022$ is a dominating number because three of its four digits are equal to $2$. But $2021$ is not a dominating number.\n\nLet $D(N)$ be how many dominating numbers are less than $10^N$.\nFor example, $D(4) = 603$ and $D(10) = 21893256$.\n\nFind $D(2022)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nA dominating number is a positive integer that has more than half of its digits equal.\n

    \n

    \nFor example, $2022$ is a dominating number because three of its four digits are equal to $2$. But $2021$ is not a dominating number.\n

    \n

    \nLet $D(N)$ be how many dominating numbers are less than $10^N$.\nFor example, $D(4) = 603$ and $D(10) = 21893256$.\n

    \n

    \nFind $D(2022)$. Give your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=788", "answer": "471745499"} {"id": 789, "problem": "Given an odd prime $p$, put the numbers $1,...,p-1$ into $\\frac{p-1}{2}$ pairs such that each number appears exactly once. Each pair $(a,b)$ has a cost of $ab \\bmod p$. For example, if $p=5$ the pair $(3,4)$ has a cost of $12 \\bmod 5 = 2$.\n\nThe total cost of a pairing is the sum of the costs of its pairs. We say that such pairing is optimal if its total cost is minimal for that $p$.\n\nFor example, if $p = 5$, then there is a unique optimal pairing: $(1, 2), (3, 4)$, with total cost of $2 + 2 = 4$.\n\nThe cost product of a pairing is the product of the costs of its pairs. For example, the cost product of the optimal pairing for $p = 5$ is $2 \\cdot 2 = 4$.\n\nIt turns out that all optimal pairings for $p = 2\\,000\\,000\\,011$ have the same cost product.\n\nFind the value of this product.", "raw_html": "

    Given an odd prime $p$, put the numbers $1,...,p-1$ into $\\frac{p-1}{2}$ pairs such that each number appears exactly once. Each pair $(a,b)$ has a cost of $ab \\bmod p$. For example, if $p=5$ the pair $(3,4)$ has a cost of $12 \\bmod 5 = 2$.

    \n\n

    The total cost of a pairing is the sum of the costs of its pairs. We say that such pairing is optimal if its total cost is minimal for that $p$.

    \n\n

    For example, if $p = 5$, then there is a unique optimal pairing: $(1, 2), (3, 4)$, with total cost of $2 + 2 = 4$.

    \n\n

    The cost product of a pairing is the product of the costs of its pairs. For example, the cost product of the optimal pairing for $p = 5$ is $2 \\cdot 2 = 4$.

    \n\n

    It turns out that all optimal pairings for $p = 2\\,000\\,000\\,011$ have the same cost product.

    \n\n

    Find the value of this product.

    ", "url": "https://projecteuler.net/problem=789", "answer": "13431419535872807040"} {"id": 790, "problem": "There is a grid of length and width $50515093$ points. A clock is placed on each grid point. The clocks are all analogue showing a single hour hand initially pointing at $12$.\n\n\n\nA sequence $S_t$ is created where:\n$$\n\\begin{align}\nS_0 &= 290797\\\\\nS_t &= S_{t-1}^2 \\bmod 50515093 &t>0\n\\end{align}\n$$\nThe four numbers $N_t = (S_{4t-4}, S_{4t-3}, S_{4t-2}, S_{4t-1})$ represent a range within the grid, with the first pair of numbers representing the x-bounds and the second pair representing the y-bounds. For example, if $N_t = (3,9,47,20)$, the range would be $3\\le x\\le 9$ and $20\\le y\\le47$, and would include $196$ clocks.\n\nFor each $t$ $(t>0)$, the clocks within the range represented by $N_t$ are moved to the next hour $12\\rightarrow 1\\rightarrow 2\\rightarrow \\cdots $.\n\nWe define $C(t)$ to be the sum of the hours that the clock hands are pointing to after timestep $t$.\n\nYou are given $C(0) = 30621295449583788$, $C(1) = 30613048345941659$, $C(10) = 21808930308198471$ and $C(100) = 16190667393984172$.\n\nFind $C(10^5)$.", "raw_html": "

    There is a grid of length and width $50515093$ points. A clock is placed on each grid point. The clocks are all analogue showing a single hour hand initially pointing at $12$.

    \n\n

    A sequence $S_t$ is created where:\n$$\n\\begin{align}\nS_0 &= 290797\\\\\nS_t &= S_{t-1}^2 \\bmod 50515093 &t>0\n\\end{align}\n$$\nThe four numbers $N_t = (S_{4t-4}, S_{4t-3}, S_{4t-2}, S_{4t-1})$ represent a range within the grid, with the first pair of numbers representing the x-bounds and the second pair representing the y-bounds. For example, if $N_t = (3,9,47,20)$, the range would be $3\\le x\\le 9$ and $20\\le y\\le47$, and would include $196$ clocks.

    \n\n

    For each $t$ $(t>0)$, the clocks within the range represented by $N_t$ are moved to the next hour $12\\rightarrow 1\\rightarrow 2\\rightarrow \\cdots $.

    \n\n

    We define $C(t)$ to be the sum of the hours that the clock hands are pointing to after timestep $t$.
    \nYou are given $C(0) = 30621295449583788$, $C(1) = 30613048345941659$, $C(10) = 21808930308198471$ and $C(100) = 16190667393984172$.

    \n\n

    Find $C(10^5)$.

    ", "url": "https://projecteuler.net/problem=790", "answer": "16585056588495119"} {"id": 791, "problem": "Denote the average of $k$ numbers $x_1, ..., x_k$ by $\\bar{x} = \\frac{1}{k} \\sum_i x_i$. Their variance is defined as $\\frac{1}{k} \\sum_i \\left( x_i - \\bar{x} \\right) ^ 2$.\n\nLet $S(n)$ be the sum of all quadruples of integers $(a,b,c,d)$ satisfying $1 \\leq a \\leq b \\leq c \\leq d \\leq n$ such that their average is exactly twice their variance.\n\nFor $n=5$, there are $5$ such quadruples, namely: $(1, 1, 1, 3), (1, 1, 3, 3), (1, 2, 3, 4), (1, 3, 4, 4), (2, 2, 3, 5)$.\n\nHence $S(5)=48$. You are also given $S(10^3)=37048340$.\n\nFind $S(10^8)$. Give your answer modulo $433494437$.", "raw_html": "

    Denote the average of $k$ numbers $x_1, ..., x_k$ by $\\bar{x} = \\frac{1}{k} \\sum_i x_i$. Their variance is defined as $\\frac{1}{k} \\sum_i \\left( x_i - \\bar{x} \\right) ^ 2$.

    \n\n

    Let $S(n)$ be the sum of all quadruples of integers $(a,b,c,d)$ satisfying $1 \\leq a \\leq b \\leq c \\leq d \\leq n$ such that their average is exactly twice their variance.

    \n\n

    For $n=5$, there are $5$ such quadruples, namely: $(1, 1, 1, 3), (1, 1, 3, 3), (1, 2, 3, 4), (1, 3, 4, 4), (2, 2, 3, 5)$.

    \n\n

    Hence $S(5)=48$. You are also given $S(10^3)=37048340$.

    \n\n

    Find $S(10^8)$. Give your answer modulo $433494437$.

    ", "url": "https://projecteuler.net/problem=791", "answer": "404890862"} {"id": 792, "problem": "We define $\\nu_2(n)$ to be the largest integer $r$ such that $2^r$ divides $n$. For example, $\\nu_2(24) = 3$.\n\nDefine $\\displaystyle S(n) = \\sum_{k = 1}^n (-2)^k\\binom{2k}k$ and $u(n) = \\nu_2\\Big(3S(n)+4\\Big)$.\n\nFor example, when $n = 4$ then $S(4) = 980$ and $3S(4) + 4 = 2944 = 2^7 \\cdot 23$, hence $u(4) = 7$.\n\nYou are also given $u(20) = 24$.\n\nAlso define $\\displaystyle U(N) = \\sum_{n = 1}^N u(n^3)$. You are given $U(5) = 241$.\n\nFind $U(10^4)$.", "raw_html": "

    \nWe define $\\nu_2(n)$ to be the largest integer $r$ such that $2^r$ divides $n$. For example, $\\nu_2(24) = 3$.\n

    \n\n

    \nDefine $\\displaystyle S(n) = \\sum_{k = 1}^n (-2)^k\\binom{2k}k$ and $u(n) = \\nu_2\\Big(3S(n)+4\\Big)$.\n

    \n\n

    \nFor example, when $n = 4$ then $S(4) = 980$ and $3S(4) + 4 = 2944 = 2^7 \\cdot 23$, hence $u(4) = 7$.
    \nYou are also given $u(20) = 24$.\n

    \n\n

    \nAlso define $\\displaystyle U(N) = \\sum_{n = 1}^N u(n^3)$. You are given $U(5) = 241$.\n

    \n\n

    \nFind $U(10^4)$.\n

    ", "url": "https://projecteuler.net/problem=792", "answer": "2500500025183626"} {"id": 793, "problem": "Let $S_i$ be an integer sequence produced with the following pseudo-random number generator:\n\n- $S_0 = 290797$\n\n- $S_{i+1} = S_i ^2 \\bmod 50515093$\n\nLet $M(n)$ be the median of the pairwise products $ S_i S_j $ for $0 \\le i \\lt j \\lt n$.\n\nYou are given $M(3) = 3878983057768$ and $M(103) = 492700616748525$.\n\nFind $M(1\\,000\\,003)$.", "raw_html": "

    \nLet $S_i$ be an integer sequence produced with the following pseudo-random number generator:\n

    \n
      \n
    • $S_0 = 290797$
    • \n
    • $S_{i+1} = S_i ^2 \\bmod 50515093$
    • \n
    \n

    \nLet $M(n)$ be the median of the pairwise products $ S_i S_j $ for $0 \\le i \\lt j \\lt n$.\n

    \n

    \nYou are given $M(3) = 3878983057768$ and $M(103) = 492700616748525$.\n

    \n

    \nFind $M(1\\,000\\,003)$.\n

    ", "url": "https://projecteuler.net/problem=793", "answer": "475808650131120"} {"id": 794, "problem": "This problem uses half open interval notation where $[a,b)$ represents $a \\le x \\lt b$.\n\nA real number, $x_1$, is chosen in the interval $[0,1)$.\n\nA second real number, $x_2$, is chosen such that each of $[0,\\frac{1}{2})$ and $[\\frac{1}{2},1)$ contains exactly one of $(x_1, x_2)$.\n\nContinue such that on the $n$-th step a real number, $x_n$, is chosen so that each of the intervals $[\\frac{k-1}{n}, \\frac{k}{n})$ for $k \\in \\{1, \\dots, n\\}$ contains exactly one of $(x_1, x_2, \\dots, x_n)$.\n\nDefine $F(n)$ to be the minimal value of the sum $x_1 + x_2 + \\cdots + x_n$ of a tuple $(x_1, x_2, \\dots, x_n)$ chosen by such a procedure. For example, $F(4) = 1.5$ obtained with $(x_1, x_2, x_3, x_4) = (0, 0.75, 0.5, 0.25)$.\n\nSurprisingly, no more than $17$ points can be chosen by this procedure.\n\nFind $F(17)$ and give your answer rounded to $12$ decimal places.", "raw_html": "

    This problem uses half open interval notation where $[a,b)$ represents $a \\le x \\lt b$.

    \n\n

    A real number, $x_1$, is chosen in the interval $[0,1)$.
    \nA second real number, $x_2$, is chosen such that each of $[0,\\frac{1}{2})$ and $[\\frac{1}{2},1)$ contains exactly one of $(x_1, x_2)$.
    \nContinue such that on the $n$-th step a real number, $x_n$, is chosen so that each of the intervals $[\\frac{k-1}{n}, \\frac{k}{n})$ for $k \\in \\{1, \\dots, n\\}$ contains exactly one of $(x_1, x_2, \\dots, x_n)$.

    \n\n

    Define $F(n)$ to be the minimal value of the sum $x_1 + x_2 + \\cdots + x_n$ of a tuple $(x_1, x_2, \\dots, x_n)$ chosen by such a procedure. For example, $F(4) = 1.5$ obtained with $(x_1, x_2, x_3, x_4) = (0, 0.75, 0.5, 0.25)$.

    \n\n

    Surprisingly, no more than $17$ points can be chosen by this procedure.

    \n\n

    Find $F(17)$ and give your answer rounded to $12$ decimal places.

    ", "url": "https://projecteuler.net/problem=794", "answer": "8.146681749623"} {"id": 795, "problem": "For a positive integer $n$, the function $g(n)$ is defined as\n\n$$\\displaystyle g(n)=\\sum_{i=1}^{n} (-1)^i \\gcd \\left(n,i^2\\right).$$\n\nFor example, $g(4) = -\\gcd \\left(4,1^2\\right) + \\gcd \\left(4,2^2\\right) - \\gcd \\left(4,3^2\\right) + \\gcd \\left(4,4^2\\right) = -1+4-1+4=6$.\n\nYou are also given $g(1234)=1233$.\n\nLet $\\displaystyle G(N) = \\sum_{n=1}^N g(n)$. You are given $G(1234) = 2194708$.\n\nFind $G(12345678)$.", "raw_html": "

    \nFor a positive integer $n$, the function $g(n)$ is defined as\n

    \n$$\\displaystyle g(n)=\\sum_{i=1}^{n} (-1)^i \\gcd \\left(n,i^2\\right).$$\n

    \nFor example, $g(4) = -\\gcd \\left(4,1^2\\right) + \\gcd \\left(4,2^2\\right) - \\gcd \\left(4,3^2\\right) + \\gcd \\left(4,4^2\\right) = -1+4-1+4=6$.
    \nYou are also given $g(1234)=1233$.\n

    \n

    \nLet $\\displaystyle G(N) = \\sum_{n=1}^N g(n)$. You are given $G(1234) = 2194708$.\n

    \n

    \nFind $G(12345678)$.\n

    ", "url": "https://projecteuler.net/problem=795", "answer": "955892601606483"} {"id": 796, "problem": "A standard $52$ card deck comprises thirteen ranks in four suits. However, modern decks have two additional Jokers, which neither have a suit nor a rank, for a total of $54$ cards. If we shuffle such a deck and draw cards without replacement, then we would need, on average, approximately $29.05361725$ cards so that we have at least one card for each rank.\n\nNow, assume you have $10$ such decks, each with a different back design. We shuffle all $10 \\times 54$ cards together and draw cards without replacement. What is the expected number of cards needed so every suit, rank and deck design have at least one card?\n\nGive your answer rounded to eight places after the decimal point.", "raw_html": "

    A standard $52$ card deck comprises thirteen ranks in four suits. However, modern decks have two additional Jokers, which neither have a suit nor a rank, for a total of $54$ cards. If we shuffle such a deck and draw cards without replacement, then we would need, on average, approximately $29.05361725$ cards so that we have at least one card for each rank.

    \n\n

    Now, assume you have $10$ such decks, each with a different back design. We shuffle all $10 \\times 54$ cards together and draw cards without replacement. What is the expected number of cards needed so every suit, rank and deck design have at least one card?

    \n\n

    Give your answer rounded to eight places after the decimal point.

    ", "url": "https://projecteuler.net/problem=796", "answer": "43.20649061"} {"id": 797, "problem": "A monic polynomial is a single-variable polynomial in which the coefficient of highest degree is equal to $1$.\n\nDefine $\\mathcal{F}$ to be the set of all monic polynomials with integer coefficients (including the constant polynomial $p(x)=1$). A polynomial $p(x)\\in\\mathcal{F}$ is cyclogenic if there exists $q(x)\\in\\mathcal{F}$ and a positive integer $n$ such that $p(x)q(x)=x^n-1$. If $n$ is the smallest such positive integer then $p(x)$ is $n$-cyclogenic.\n\nDefine $P_n(x)$ to be the sum of all $n$-cyclogenic polynomials. For example, there exist ten 6-cyclogenic polynomials (which divide $x^6-1$ and no smaller $x^k-1$):\n\n$$\\begin{align*}\n&x^6-1&&x^4+x^3-x-1&&x^3+2x^2+2x+1&&x^2-x+1\\\\\n&x^5+x^4+x^3+x^2+x+1&&x^4-x^3+x-1&&x^3-2x^2+2x-1\\\\\n&x^5-x^4+x^3-x^2+x-1&&x^4+x^2+1&&x^3+1\\end{align*}$$\ngiving\n\n$$P_6(x)=x^6+2x^5+3x^4+5x^3+2x^2+5x.$$\nAlso define\n\n$$Q_N(x)=\\sum_{n=1}^N P_n(x).$$\nIt's given that\n$Q_{10}(x)=x^{10}+3x^9+3x^8+7x^7+8x^6+14x^5+11x^4+18x^3+12x^2+23x$ and $Q_{10}(2) = 5598$.\n\nFind $Q_{10^7}(2)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    A monic polynomial is a single-variable polynomial in which the coefficient of highest degree is equal to $1$.

    \n\n

    Define $\\mathcal{F}$ to be the set of all monic polynomials with integer coefficients (including the constant polynomial $p(x)=1$). A polynomial $p(x)\\in\\mathcal{F}$ is cyclogenic if there exists $q(x)\\in\\mathcal{F}$ and a positive integer $n$ such that $p(x)q(x)=x^n-1$. If $n$ is the smallest such positive integer then $p(x)$ is $n$-cyclogenic.

    \n\n

    Define $P_n(x)$ to be the sum of all $n$-cyclogenic polynomials. For example, there exist ten 6-cyclogenic polynomials (which divide $x^6-1$ and no smaller $x^k-1$):

    \n$$\\begin{align*}\n&x^6-1&&x^4+x^3-x-1&&x^3+2x^2+2x+1&&x^2-x+1\\\\\n&x^5+x^4+x^3+x^2+x+1&&x^4-x^3+x-1&&x^3-2x^2+2x-1\\\\\n&x^5-x^4+x^3-x^2+x-1&&x^4+x^2+1&&x^3+1\\end{align*}$$\n

    giving

    \n$$P_6(x)=x^6+2x^5+3x^4+5x^3+2x^2+5x.$$\n

    Also define

    \n$$Q_N(x)=\\sum_{n=1}^N P_n(x).$$\n

    It's given that\n$Q_{10}(x)=x^{10}+3x^9+3x^8+7x^7+8x^6+14x^5+11x^4+18x^3+12x^2+23x$ and $Q_{10}(2) = 5598$.

    \n\n

    Find $Q_{10^7}(2)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=797", "answer": "47722272"} {"id": 798, "problem": "Two players play a game with a deck of cards which contains $s$ suits with each suit containing $n$ cards numbered from $1$ to $n$.\n\nBefore the game starts, a set of cards (which may be empty) is picked from the deck and placed face-up on the table, with no overlap. These are called the visible cards.\n\nThe players then make moves in turn.\n\nA move consists of choosing a card X from the rest of the deck and placing it face-up on top of a visible card Y, subject to the following restrictions:\n\n- X and Y must be the same suit;\n\n- the value of X must be larger than the value of Y.\n\nThe card X then covers the card Y and replaces Y as a visible card.\n\nThe player unable to make a valid move loses and play stops.\n\nLet $C(n, s)$ be the number of different initial sets of cards for which the first player will lose given best play for both players.\n\nFor example, $C(3, 2) = 26$ and $C(13, 4) \\equiv 540318329 \\pmod {1\\,000\\,000\\,007}$.\n\nFind $C(10^7, 10^7)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nTwo players play a game with a deck of cards which contains $s$ suits with each suit containing $n$ cards numbered from $1$ to $n$.

    \n\n

    \nBefore the game starts, a set of cards (which may be empty) is picked from the deck and placed face-up on the table, with no overlap. These are called the visible cards.

    \n\n

    \nThe players then make moves in turn.
    \nA move consists of choosing a card X from the rest of the deck and placing it face-up on top of a visible card Y, subject to the following restrictions:

    \n
      \n
    • X and Y must be the same suit;
    • \n
    • the value of X must be larger than the value of Y.
    • \n
    \n

    \nThe card X then covers the card Y and replaces Y as a visible card.
    \nThe player unable to make a valid move loses and play stops.

    \n\n

    \nLet $C(n, s)$ be the number of different initial sets of cards for which the first player will lose given best play for both players.

    \n\n

    \nFor example, $C(3, 2) = 26$ and $C(13, 4) \\equiv 540318329 \\pmod {1\\,000\\,000\\,007}$.

    \n\n

    \nFind $C(10^7, 10^7)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=798", "answer": "132996198"} {"id": 799, "problem": "Pentagonal numbers are generated by the formula: $P_n = \\tfrac 12n(3n-1)$ giving the sequence:\n\n$$1,5,12,22,35, 51,70,92,\\ldots $$\n\nSome pentagonal numbers can be expressed as the sum of two other pentagonal numbers.\n\nFor example:\n\n$$P_8 = 92 = 22 + 70 = P_4 + P_7$$\n\n$3577$ is the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in two different ways\n\n$$\n\\begin{align}\nP_{49} = 3577 & = 3432 + 145 = P_{48} + P_{10} \\\\\n& = 3290 + 287 = P_{47}+P_{14}\n\\end{align}\n$$\n\n$107602$ is the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in three different ways.\n\nFind the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in over $100$ different ways.", "raw_html": "

    \nPentagonal numbers are generated by the formula: $P_n = \\tfrac 12n(3n-1)$ giving the sequence:\n

    \n$$1,5,12,22,35, 51,70,92,\\ldots $$\n

    \nSome pentagonal numbers can be expressed as the sum of two other pentagonal numbers.
    \nFor example:\n

    \n$$P_8 = 92 = 22 + 70 = P_4 + P_7$$\n

    \n$3577$ is the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in two different ways\n

    \n$$\n\\begin{align}\nP_{49} = 3577 & = 3432 + 145 = P_{48} + P_{10} \\\\\n & = 3290 + 287 = P_{47}+P_{14}\n\\end{align}\n$$\n

    \n$107602$ is the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in three different ways.\n

    \n

    \nFind the smallest pentagonal number that can be expressed as the sum of two pentagonal numbers in over $100$ different ways.\n

    ", "url": "https://projecteuler.net/problem=799", "answer": "1096910149053902"} {"id": 800, "problem": "An integer of the form $p^q q^p$ with prime numbers $p \\neq q$ is called a hybrid-integer.\n\nFor example, $800 = 2^5 5^2$ is a hybrid-integer.\n\nWe define $C(n)$ to be the number of hybrid-integers less than or equal to $n$.\n\nYou are given $C(800) = 2$ and $C(800^{800}) = 10790$.\n\nFind $C(800800^{800800})$.", "raw_html": "

    \nAn integer of the form $p^q q^p$ with prime numbers $p \\neq q$ is called a hybrid-integer.
    \nFor example, $800 = 2^5 5^2$ is a hybrid-integer.\n

    \n

    \nWe define $C(n)$ to be the number of hybrid-integers less than or equal to $n$.
    \nYou are given $C(800) = 2$ and $C(800^{800}) = 10790$.\n

    \n

    \nFind $C(800800^{800800})$.\n

    ", "url": "https://projecteuler.net/problem=800", "answer": "1412403576"} {"id": 801, "problem": "The positive integral solutions of the equation $x^y=y^x$ are $(2,4)$, $(4,2)$ and $(k,k)$ for all $k > 0$.\n\nFor a given positive integer $n$, let $f(n)$ be the number of integral values $0 < x,y \\leq n^2-n$ such that\n$$x^y\\equiv y^x \\pmod n.$$\nFor example, $f(5)=104$ and $f(97)=1614336$.\n\nLet $S(M,N)=\\sum f(p)$ where the sum is taken over all primes $p$ satisfying $M\\le p\\le N$.\n\nYou are given $S(1,10^2)=7381000$ and $S(1,10^5) \\equiv 701331986 \\pmod{993353399}$.\n\nFind $S(10^{16}, 10^{16}+10^6)$. Give your answer modulo $993353399$.", "raw_html": "

    The positive integral solutions of the equation $x^y=y^x$ are $(2,4)$, $(4,2)$ and $(k,k)$ for all $k > 0$.

    \n\n

    For a given positive integer $n$, let $f(n)$ be the number of integral values $0 < x,y \\leq n^2-n$ such that\n$$x^y\\equiv y^x \\pmod n.$$\nFor example, $f(5)=104$ and $f(97)=1614336$.

    \n\n

    Let $S(M,N)=\\sum f(p)$ where the sum is taken over all primes $p$ satisfying $M\\le p\\le N$.

    \n\n

    You are given $S(1,10^2)=7381000$ and $S(1,10^5) \\equiv 701331986 \\pmod{993353399}$.

    \n\n

    Find $S(10^{16}, 10^{16}+10^6)$. Give your answer modulo $993353399$.

    ", "url": "https://projecteuler.net/problem=801", "answer": "638129754"} {"id": 802, "problem": "Let $\\Bbb R^2$ be the set of pairs of real numbers $(x, y)$. Let $\\pi = 3.14159\\cdots\\ $.\n\nConsider the function $f$ from $\\Bbb R^2$ to $\\Bbb R^2$ defined by $f(x, y) = (x^2 - x - y^2, 2xy - y + \\pi)$, and its $n$-th iterated composition $f^{(n)}(x, y) = f(f(\\cdots f(x, y)\\cdots))$. For example $f^{(3)}(x, y) = f(f(f(x, y)))$. A pair $(x, y)$ is said to have period $n$ if $n$ is the smallest positive integer such that $f^{(n)}(x, y) = (x, y)$.\n\nLet $P(n)$ denote the sum of $x$-coordinates of all points having period not exceeding $n$.\nInterestingly, $P(n)$ is always an integer. For example, $P(1) = 2$, $P(2) = 2$, $P(3) = 4$.\n\nFind $P(10^7)$ and give your answer modulo $1\\,020\\,340\\,567$.", "raw_html": "

    Let $\\Bbb R^2$ be the set of pairs of real numbers $(x, y)$. Let $\\pi = 3.14159\\cdots\\ $.

    \n\n

    Consider the function $f$ from $\\Bbb R^2$ to $\\Bbb R^2$ defined by $f(x, y) = (x^2 - x - y^2, 2xy - y + \\pi)$, and its $n$-th iterated composition $f^{(n)}(x, y) = f(f(\\cdots f(x, y)\\cdots))$. For example $f^{(3)}(x, y) = f(f(f(x, y)))$. A pair $(x, y)$ is said to have period $n$ if $n$ is the smallest positive integer such that $f^{(n)}(x, y) = (x, y)$.

    \n\n

    Let $P(n)$ denote the sum of $x$-coordinates of all points having period not exceeding $n$.\nInterestingly, $P(n)$ is always an integer. For example, $P(1) = 2$, $P(2) = 2$, $P(3) = 4$.

    \n\n

    Find $P(10^7)$ and give your answer modulo $1\\,020\\,340\\,567$.

    ", "url": "https://projecteuler.net/problem=802", "answer": "973873727"} {"id": 803, "problem": "Rand48 is a pseudorandom number generator used by some programming languages. It generates a sequence from any given integer $0 \\le a_0 < 2^{48}$ using the rule $a_n = (25214903917 \\cdot a_{n - 1} + 11) \\bmod 2^{48}$.\n\nLet $b_n = \\lfloor a_n / 2^{16} \\rfloor \\bmod 52$.\nThe sequence $b_0, b_1, \\dots$ is translated to an infinite string $c = c_0c_1\\dots$ via the rule:\n\n$0 \\rightarrow$ a, $1\\rightarrow$ b, $\\dots$, $25 \\rightarrow$ z, $26 \\rightarrow$ A, $27 \\rightarrow$ B, $\\dots$, $51 \\rightarrow$ Z.\n\nFor example, if we choose $a_0 = 123456$, then the string $c$ starts with: \"bQYicNGCY$\\dots$\".\n\nMoreover, starting from index $100$, we encounter the substring \"RxqLBfWzv\" for the first time.\n\nAlternatively, if $c$ starts with \"EULERcats$\\dots$\", then $a_0$ must be $78580612777175$.\n\nNow suppose that the string $c$ starts with \"PuzzleOne$\\dots$\".\n\nFind the starting index of the first occurrence of the substring \"LuckyText\" in $c$.", "raw_html": "

    \nRand48 is a pseudorandom number generator used by some programming languages. It generates a sequence from any given integer $0 \\le a_0 < 2^{48}$ using the rule $a_n = (25214903917 \\cdot a_{n - 1} + 11) \\bmod 2^{48}$.\n

    \n

    \nLet $b_n = \\lfloor a_n / 2^{16} \\rfloor \\bmod 52$.\nThe sequence $b_0, b_1, \\dots$ is translated to an infinite string $c = c_0c_1\\dots$ via the rule:
    \n$0 \\rightarrow$ a, $1\\rightarrow$ b, $\\dots$, $25 \\rightarrow$ z, $26 \\rightarrow$ A, $27 \\rightarrow$ B, $\\dots$, $51 \\rightarrow$ Z.\n

    \n

    \nFor example, if we choose $a_0 = 123456$, then the string $c$ starts with: \"bQYicNGCY$\\dots$\".
    \nMoreover, starting from index $100$, we encounter the substring \"RxqLBfWzv\" for the first time.\n

    \n

    \nAlternatively, if $c$ starts with \"EULERcats$\\dots$\", then $a_0$ must be $78580612777175$.\n

    \n

    \nNow suppose that the string $c$ starts with \"PuzzleOne$\\dots$\".
    \nFind the starting index of the first occurrence of the substring \"LuckyText\" in $c$.\n

    ", "url": "https://projecteuler.net/problem=803", "answer": "9300900470636"} {"id": 804, "problem": "Let $g(n)$ denote the number of ways a positive integer $n$ can be represented in the form: $$x^2+xy+41y^2$$ where $x$ and $y$ are integers. For example, $g(53)=4$ due to $(x,y) \\in \\{(-4,1),(-3,-1),(3,1),(4,-1)\\}$.\n\nDefine $\\displaystyle T(N)=\\sum_{n=1}^{N}g(n)$. You are given $T(10^3)=474$ and $T(10^6)=492128$.\n\nFind $T(10^{16})$.", "raw_html": "

    Let $g(n)$ denote the number of ways a positive integer $n$ can be represented in the form: $$x^2+xy+41y^2$$ where $x$ and $y$ are integers. For example, $g(53)=4$ due to $(x,y) \\in \\{(-4,1),(-3,-1),(3,1),(4,-1)\\}$.

    \n\n

    Define $\\displaystyle T(N)=\\sum_{n=1}^{N}g(n)$. You are given $T(10^3)=474$ and $T(10^6)=492128$.

    \n\n

    Find $T(10^{16})$.

    ", "url": "https://projecteuler.net/problem=804", "answer": "4921370551019052"} {"id": 805, "problem": "For a positive integer $n$, let $s(n)$ be the integer obtained by shifting the leftmost digit of the decimal representation of $n$ to the rightmost position.\n\nFor example, $s(142857)=428571$ and $s(10)=1$.\n\nFor a positive rational number $r$, we define $N(r)$ as the smallest positive integer $n$ such that $s(n)=r\\cdot n$.\n\nIf no such integer exists, then $N(r)$ is defined as zero.\n\nFor example, $N(3)=142857$, $N(\\tfrac 1{10})=10$ and $N(2) = 0$.\n\nLet $T(M)$ be the sum of $N(u^3/v^3)$ where $(u,v)$ ranges over all ordered pairs of coprime positive integers not exceeding $M$.\n\nFor example, $T(3)\\equiv 262429173 \\pmod {1\\,000\\,000\\,007}$.\n\nFind $T(200)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nFor a positive integer $n$, let $s(n)$ be the integer obtained by shifting the leftmost digit of the decimal representation of $n$ to the rightmost position.
    \nFor example, $s(142857)=428571$ and $s(10)=1$.

    \n\n

    \nFor a positive rational number $r$, we define $N(r)$ as the smallest positive integer $n$ such that $s(n)=r\\cdot n$.
    \nIf no such integer exists, then $N(r)$ is defined as zero.
    \nFor example, $N(3)=142857$, $N(\\tfrac 1{10})=10$ and $N(2) = 0$.

    \n

    \nLet $T(M)$ be the sum of $N(u^3/v^3)$ where $(u,v)$ ranges over all ordered pairs of coprime positive integers not exceeding $M$.
    \nFor example, $T(3)\\equiv 262429173 \\pmod {1\\,000\\,000\\,007}$.

    \n\n

    \nFind $T(200)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=805", "answer": "119719335"} {"id": 806, "problem": "This problem combines the game of Nim with the Towers of Hanoi. For a brief introduction to the rules of these games, please refer to Problem 301 and Problem 497, respectively.\n\nThe unique shortest solution to the Towers of Hanoi problem with $n$ disks and $3$ pegs requires $2^n-1$ moves. Number the positions in the solution from index 0 (starting position, all disks on the first peg) to index $2^n-1$ (final position, all disks on the third peg).\n\nEach of these $2^n$ positions can be considered as the starting configuration for a game of Nim, in which two players take turns to select a peg and remove any positive number of disks from it. The winner is the player who removes the last disk.\n\nWe define $f(n)$ to be the sum of the indices of those positions for which, when considered as a Nim game, the first player will lose (assuming an optimal strategy from both players).\n\nFor $n=4$, the indices of losing positions in the shortest solution are 3,6,9 and 12. So we have $f(4) = 30$.\n\nYou are given that $f(10) = 67518$.\n\nFind $f(10^5)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    This problem combines the game of Nim with the Towers of Hanoi. For a brief introduction to the rules of these games, please refer to Problem 301 and Problem 497, respectively.

    \n\n

    The unique shortest solution to the Towers of Hanoi problem with $n$ disks and $3$ pegs requires $2^n-1$ moves. Number the positions in the solution from index 0 (starting position, all disks on the first peg) to index $2^n-1$ (final position, all disks on the third peg).

    \n\n

    Each of these $2^n$ positions can be considered as the starting configuration for a game of Nim, in which two players take turns to select a peg and remove any positive number of disks from it. The winner is the player who removes the last disk.

    \n\n

    We define $f(n)$ to be the sum of the indices of those positions for which, when considered as a Nim game, the first player will lose (assuming an optimal strategy from both players).

    \n\n

    For $n=4$, the indices of losing positions in the shortest solution are 3,6,9 and 12. So we have $f(4) = 30$.

    \n\n

    You are given that $f(10) = 67518$.

    \n\n

    Find $f(10^5)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=806", "answer": "94394343"} {"id": 807, "problem": "Given a circle $C$ and an integer $n > 1$, we perform the following operations.\n\nIn step $0$, we choose two uniformly random points $R_0$ and $B_0$ on $C$.\n\nIn step $i$ ($1 \\leq i < n$), we first choose a uniformly random point $R_i$ on $C$ and connect the points $R_{i - 1}$ and $R_i$ with a red rope; then choose a uniformly random point $B_i$ on $C$ and connect the points $B_{i - 1}$ and $B_i$ with a blue rope.\n\nIn step $n$, we first connect the points $R_{n - 1}$ and $R_0$ with a red rope; then connect the points $B_{n - 1}$ and $B_0$ with a blue rope.\n\nEach rope is straight between its two end points, and lies above all previous ropes.\n\nAfter step $n$, we get a loop of red ropes, and a loop of blue ropes.\n\nSometimes the two loops can be separated, as in the left figure below; sometimes they are \"linked\", hence cannot be separated, as in the middle and right figures below.\n\nLet $P(n)$ be the probability that the two loops can be separated.\n\nFor example, $P(3) = \\frac{11}{20}$ and $P(5) \\approx 0.4304177690$.\n\nFind $P(80)$, rounded to $10$ digits after decimal point.", "raw_html": "

    Given a circle $C$ and an integer $n > 1$, we perform the following operations.

    \n\n

    In step $0$, we choose two uniformly random points $R_0$ and $B_0$ on $C$.
    \nIn step $i$ ($1 \\leq i < n$), we first choose a uniformly random point $R_i$ on $C$ and connect the points $R_{i - 1}$ and $R_i$ with a red rope; then choose a uniformly random point $B_i$ on $C$ and connect the points $B_{i - 1}$ and $B_i$ with a blue rope.
    \nIn step $n$, we first connect the points $R_{n - 1}$ and $R_0$ with a red rope; then connect the points $B_{n - 1}$ and $B_0$ with a blue rope.
    \nEach rope is straight between its two end points, and lies above all previous ropes.

    \n\n

    After step $n$, we get a loop of red ropes, and a loop of blue ropes.
    \nSometimes the two loops can be separated, as in the left figure below; sometimes they are \"linked\", hence cannot be separated, as in the middle and right figures below.

    \n\n
    \n\"\"\n
    \n\n

    Let $P(n)$ be the probability that the two loops can be separated.
    \nFor example, $P(3) = \\frac{11}{20}$ and $P(5) \\approx 0.4304177690$.

    \n\n

    Find $P(80)$, rounded to $10$ digits after decimal point.

    ", "url": "https://projecteuler.net/problem=807", "answer": "0.1091523673"} {"id": 808, "problem": "Both $169$ and $961$ are the square of a prime. $169$ is the reverse of $961$.\n\nWe call a number a reversible prime square if:\n\n- It is not a palindrome, and\n\n- It is the square of a prime, and\n\n- Its reverse is also the square of a prime.\n\n$169$ and $961$ are not palindromes, so both are reversible prime squares.\n\nFind the sum of the first $50$ reversible prime squares.", "raw_html": "

    \nBoth $169$ and $961$ are the square of a prime. $169$ is the reverse of $961$.\n

    \n

    \nWe call a number a reversible prime square if:

    \n
      \n
    1. It is not a palindrome, and
    2. \n
    3. It is the square of a prime, and
    4. \n
    5. Its reverse is also the square of a prime.
    6. \n
    \n

    \n$169$ and $961$ are not palindromes, so both are reversible prime squares.\n

    \n

    \nFind the sum of the first $50$ reversible prime squares.\n

    ", "url": "https://projecteuler.net/problem=808", "answer": "3807504276997394"} {"id": 809, "problem": "The following is a function defined for all positive rational values of $x$.\n\n$$\tf(x)=\\begin{cases} x &x\\text{ is integral}\\\\\nf(\\frac 1{1-x})\t&x \\lt 1\\\\\nf\\Big(\\frac 1{\\lceil x\\rceil -x}-1+f(x-1)\\Big)\t&\\text{otherwise}\\end{cases}\t$$\n\nFor example, $f(3/2)=3$, $f(1/6) = 65533$ and $f(13/10) = 7625597484985$.\n\nFind $f(22/7)$. Give your answer modulo $10^{15}$.", "raw_html": "

    \nThe following is a function defined for all positive rational values of $x$.\n

    \n$$\tf(x)=\\begin{cases} x &x\\text{ is integral}\\\\\n\t\t\t\t\tf(\\frac 1{1-x})\t&x \\lt 1\\\\\n\t\t\t\t\tf\\Big(\\frac 1{\\lceil x\\rceil -x}-1+f(x-1)\\Big)\t&\\text{otherwise}\\end{cases}\t$$\n

    \nFor example, $f(3/2)=3$, $f(1/6) = 65533$ and $f(13/10) = 7625597484985$.\n

    \n

    \nFind $f(22/7)$. Give your answer modulo $10^{15}$.\n

    ", "url": "https://projecteuler.net/problem=809", "answer": "75353432948733"} {"id": 810, "problem": "We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.\n\nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.\n\nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n\n$$\n\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}\n$$\n\nAn XOR-prime is an integer $n$ greater than $1$ that is not an XOR-product of two integers greater than $1$. The above example shows that $9$ is not an XOR-prime. Similarly, $5 = 3 \\otimes 3$ is not an XOR-prime. The first few XOR-primes are $2, 3, 7, 11, 13, ...$ and the 10th XOR-prime is $41$.\n\nFind the $5\\,000\\,000$th XOR-prime.", "raw_html": "

    We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.

    \n\n

    Define the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.

    \n\n

    For example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:

    \n$$\n\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}\n$$\n\n

    An XOR-prime is an integer $n$ greater than $1$ that is not an XOR-product of two integers greater than $1$. The above example shows that $9$ is not an XOR-prime. Similarly, $5 = 3 \\otimes 3$ is not an XOR-prime. The first few XOR-primes are $2, 3, 7, 11, 13, ...$ and the 10th XOR-prime is $41$.

    \n\n

    Find the $5\\,000\\,000$th XOR-prime.

    ", "url": "https://projecteuler.net/problem=810", "answer": "124136381"} {"id": 811, "problem": "Let $b(n)$ be the largest power of 2 that divides $n$. For example $b(24) = 8$.\n\nDefine the recursive function:\n$$\\begin{align*}\n\\begin{split}\nA(0) &= 1\\\\\nA(2n) &= 3A(n) + 5A\\big(2n - b(n)\\big) \\qquad n \\gt 0\\\\\nA(2n+1) &= A(n)\n\\end{split}\n\\end{align*}$$\nand let $H(t,r) = A\\big((2^t+1)^r\\big)$.\n\nYou are given $H(3,2) = A(81) = 636056$.\n\nFind $H(10^{14}+31,62)$. Give your answer modulo $1\\,000\\,062\\,031$.", "raw_html": "

    \nLet $b(n)$ be the largest power of 2 that divides $n$. For example $b(24) = 8$.

    \n

    \nDefine the recursive function:\n$$\\begin{align*}\n\\begin{split}\nA(0) &= 1\\\\\nA(2n) &= 3A(n) + 5A\\big(2n - b(n)\\big) \\qquad n \\gt 0\\\\\nA(2n+1) &= A(n)\n\\end{split}\n\\end{align*}$$\nand let $H(t,r) = A\\big((2^t+1)^r\\big)$.

    \n

    \nYou are given $H(3,2) = A(81) = 636056$.

    \n

    \nFind $H(10^{14}+31,62)$. Give your answer modulo $1\\,000\\,062\\,031$.

    ", "url": "https://projecteuler.net/problem=811", "answer": "327287526"} {"id": 812, "problem": "A dynamical polynomial is a monicleading coefficient is $1$ polynomial $f(x)$ with integer coefficients such that $f(x)$ divides $f(x^2-2)$.\n\nFor example, $f(x) = x^2 - x - 2$ is a dynamical polynomial because $f(x^2-2) = x^4-5x^2+4 = (x^2 + x -2)f(x)$.\n\nLet $S(n)$ be the number of dynamical polynomials of degree $n$.\n\nFor example, $S(2)=6$, as there are six dynamical polynomials of degree $2$:\n\n$$ x^2-4x+4 \\quad,\\quad x^2-x-2 \\quad,\\quad x^2-4 \\quad,\\quad x^2-1 \\quad,\\quad x^2+x-1 \\quad,\\quad x^2+2x+1 $$\nAlso, $S(5)=58$ and $S(20)=122087$.\n\nFind $S(10\\,000)$. Give your answer modulo $998244353$.", "raw_html": "

    A dynamical polynomial is a monicleading coefficient is $1$ polynomial $f(x)$ with integer coefficients such that $f(x)$ divides $f(x^2-2)$.

    \n\n

    For example, $f(x) = x^2 - x - 2$ is a dynamical polynomial because $f(x^2-2) = x^4-5x^2+4 = (x^2 + x -2)f(x)$.

    \n\n

    Let $S(n)$ be the number of dynamical polynomials of degree $n$.
    \nFor example, $S(2)=6$, as there are six dynamical polynomials of degree $2$:

    \n$$ x^2-4x+4 \\quad,\\quad x^2-x-2 \\quad,\\quad x^2-4 \\quad,\\quad x^2-1 \\quad,\\quad x^2+x-1 \\quad,\\quad x^2+2x+1 $$\n

    Also, $S(5)=58$ and $S(20)=122087$.

    \n\n

    Find $S(10\\,000)$. Give your answer modulo $998244353$.

    ", "url": "https://projecteuler.net/problem=812", "answer": "986262698"} {"id": 813, "problem": "We use $x\\oplus y$ to be the bitwise XOR of $x$ and $y$.\n\nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.\n\nFor example, $11 \\otimes 11 = 69$, or in base $2$, $1011_2 \\otimes 1011_2 = 1000101_2$:\n\n$$\n\\begin{align*}\n\\phantom{\\otimes 1111} 1011_2 \\\\\n\\otimes \\phantom{1111} 1011_2 \\\\\n\\hline\n\\phantom{\\otimes 1111} 1011_2 \\\\\n\\phantom{\\otimes 111} 1011_2 \\phantom{9} \\\\\n\\oplus \\phantom{1} 1011_2 \\phantom{999} \\\\\n\\hline\n\\phantom{\\otimes 11} 1000101_2 \\\\\n\\end{align*}\n$$\nFurther we define $P(n) = 11^{\\otimes n} = \\overbrace{11\\otimes 11\\otimes \\ldots \\otimes 11}^n$. For example $P(2)=69$.\n\nFind $P(8^{12}\\cdot 12^8)$. Give your answer modulo $10^9+7$.", "raw_html": "

    We use $x\\oplus y$ to be the bitwise XOR of $x$ and $y$.

    \n\n

    Define the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.

    \n\n

    For example, $11 \\otimes 11 = 69$, or in base $2$, $1011_2 \\otimes 1011_2 = 1000101_2$:

    \n$$\n\\begin{align*}\n\\phantom{\\otimes 1111} 1011_2 \\\\\n\\otimes \\phantom{1111} 1011_2 \\\\\n\\hline\n\\phantom{\\otimes 1111} 1011_2 \\\\\n\\phantom{\\otimes 111} 1011_2 \\phantom{9} \\\\\n\\oplus \\phantom{1} 1011_2 \\phantom{999} \\\\\n\\hline\n\\phantom{\\otimes 11} 1000101_2 \\\\\n\\end{align*}\n$$\nFurther we define $P(n) = 11^{\\otimes n} = \\overbrace{11\\otimes 11\\otimes \\ldots \\otimes 11}^n$. For example $P(2)=69$.\n\n

    Find $P(8^{12}\\cdot 12^8)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=813", "answer": "14063639"} {"id": 814, "problem": "$4n$ people stand in a circle with their heads down. When the bell rings they all raise their heads and either look at the person immediately to their left, the person immediately to their right or the person diametrically opposite. If two people find themselves looking at each other they both scream.\n\nDefine $S(n)$ to be the number of ways that exactly half of the people scream. You are given $S(1) = 48$ and $S(10) \\equiv 420121075 \\mod{998244353}$.\n\nFind $S(10^3)$. Enter your answer modulo $998244353$.", "raw_html": "

    \n$4n$ people stand in a circle with their heads down. When the bell rings they all raise their heads and either look at the person immediately to their left, the person immediately to their right or the person diametrically opposite. If two people find themselves looking at each other they both scream.

    \n\n

    \nDefine $S(n)$ to be the number of ways that exactly half of the people scream. You are given $S(1) = 48$ and $S(10) \\equiv 420121075 \\mod{998244353}$.

    \n\n

    \nFind $S(10^3)$. Enter your answer modulo $998244353$.

    ", "url": "https://projecteuler.net/problem=814", "answer": "307159326"} {"id": 815, "problem": "A pack of cards contains $4n$ cards with four identical cards of each value. The pack is shuffled and cards are dealt one at a time and placed in piles of equal value. If the card has the same value as any pile it is placed in that pile. If there is no pile of that value then it begins a new pile. When a pile has four cards of the same value it is removed.\n\nThroughout the process the maximum number of non empty piles is recorded. Let $E(n)$ be its expected value. You are given $E(2) = 1.97142857$ rounded to 8 decimal places.\n\nFind $E(60)$. Give your answer rounded to 8 digits after the decimal point.", "raw_html": "

    \nA pack of cards contains $4n$ cards with four identical cards of each value. The pack is shuffled and cards are dealt one at a time and placed in piles of equal value. If the card has the same value as any pile it is placed in that pile. If there is no pile of that value then it begins a new pile. When a pile has four cards of the same value it is removed.

    \n\n

    \nThroughout the process the maximum number of non empty piles is recorded. Let $E(n)$ be its expected value. You are given $E(2) = 1.97142857$ rounded to 8 decimal places.

    \n\n

    \nFind $E(60)$. Give your answer rounded to 8 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=815", "answer": "54.12691621"} {"id": 816, "problem": "We create an array of points $P_n$ in a two dimensional plane using the following random number generator:\n\n$s_0=290797$\n\n$s_{n+1}={s_n}^2 \\bmod 50515093$\n\n\n\n$P_n=(s_{2n},s_{2n+1})$\n\nLet $d(k)$ be the shortest distance of any two (distinct) points among $P_0, \\cdots, P_{k - 1}$.\n\nE.g. $d(14)=546446.466846479$.\n\nFind $d(2000000)$. Give your answer rounded to $9$ places after the decimal point.", "raw_html": "

    We create an array of points $P_n$ in a two dimensional plane using the following random number generator:
    \n$s_0=290797$
    \n$s_{n+1}={s_n}^2 \\bmod 50515093$\n

    \n$P_n=(s_{2n},s_{2n+1})$

    \n

    \nLet $d(k)$ be the shortest distance of any two (distinct) points among $P_0, \\cdots, P_{k - 1}$.
    \nE.g. $d(14)=546446.466846479$.\n

    \n

    \nFind $d(2000000)$. Give your answer rounded to $9$ places after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=816", "answer": "20.880613018"} {"id": 817, "problem": "Define $m = M(n, d)$ to be the smallest positive integer such that when $m^2$ is written in base $n$ it includes the base $n$ digit $d$. For example, $M(10,7) = 24$ because if all the squares are written out in base 10 the first time the digit 7 occurs is in $24^2 = 576$. $M(11,10) = 19$ as $19^2 = 361=2A9_{11}$.\n\nFind $\\displaystyle \\sum_{d = 1}^{10^5}M(p, p - d)$ where $p = 10^9 + 7$.", "raw_html": "

    \nDefine $m = M(n, d)$ to be the smallest positive integer such that when $m^2$ is written in base $n$ it includes the base $n$ digit $d$. For example, $M(10,7) = 24$ because if all the squares are written out in base 10 the first time the digit 7 occurs is in $24^2 = 576$. $M(11,10) = 19$ as $19^2 = 361=2A9_{11}$.

    \n\n

    \nFind $\\displaystyle \\sum_{d = 1}^{10^5}M(p, p - d)$ where $p = 10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=817", "answer": "93158936107011"} {"id": 818, "problem": "The SET® card game is played with a pack of $81$ distinct cards. Each card has four features (Shape, Color, Number, Shading). Each feature has three different variants (e.g. Color can be red, purple, green).\n\nA SET consists of three different cards such that each feature is either the same on each card or different on each card.\n\nFor a collection $C_n$ of $n$ cards, let $S(C_n)$ denote the number of SETs in $C_n$. Then define $F(n) = \\sum\\limits_{C_n} S(C_n)^4$ where $C_n$ ranges through all collections of $n$ cards (among the $81$ cards).\nYou are given $F(3) = 1080$ and $F(6) = 159690960$.\n\nFind $F(12)$.\n\n$\\scriptsize{\\text{SET is a registered trademark of Cannei, LLC. All rights reserved.\nUsed with permission from PlayMonster, LLC.}}$", "raw_html": "

    \nThe SET® card game is played with a pack of $81$ distinct cards. Each card has four features (Shape, Color, Number, Shading). Each feature has three different variants (e.g. Color can be red, purple, green).

    \n\n

    \nA SET consists of three different cards such that each feature is either the same on each card or different on each card.

    \n\n

    \nFor a collection $C_n$ of $n$ cards, let $S(C_n)$ denote the number of SETs in $C_n$. Then define $F(n) = \\sum\\limits_{C_n} S(C_n)^4$ where $C_n$ ranges through all collections of $n$ cards (among the $81$ cards).\nYou are given $F(3) = 1080$ and $F(6) = 159690960$.

    \n\n

    \nFind $F(12)$.

    \n\n

    \n$\\scriptsize{\\text{SET is a registered trademark of Cannei, LLC. All rights reserved. \nUsed with permission from PlayMonster, LLC.}}$

    ", "url": "https://projecteuler.net/problem=818", "answer": "11871909492066000"} {"id": 819, "problem": "Given an $n$-tuple of numbers another $n$-tuple is created where each element of the new $n$-tuple is chosen randomly from the numbers in the previous $n$-tuple. For example, given $(2,2,3)$ the probability that $2$ occurs in the first position in the next 3-tuple is $2/3$. The probability of getting all $2$'s would be $8/27$ while the probability of getting the same 3-tuple (in any order) would be $4/9$.\n\nLet $E(n)$ be the expected number of steps starting with $(1,2,\\ldots,n)$ and ending with all numbers being the same.\n\nYou are given $E(3) = 27/7$ and $E(5) = 468125/60701 \\approx 7.711982$ rounded to 6 digits after the decimal place.\n\nFind $E(10^3)$. Give the answer rounded to 6 digits after the decimal place.", "raw_html": "

    Given an $n$-tuple of numbers another $n$-tuple is created where each element of the new $n$-tuple is chosen randomly from the numbers in the previous $n$-tuple. For example, given $(2,2,3)$ the probability that $2$ occurs in the first position in the next 3-tuple is $2/3$. The probability of getting all $2$'s would be $8/27$ while the probability of getting the same 3-tuple (in any order) would be $4/9$.

    \n\n

    Let $E(n)$ be the expected number of steps starting with $(1,2,\\ldots,n)$ and ending with all numbers being the same.

    \n\n

    You are given $E(3) = 27/7$ and $E(5) = 468125/60701 \\approx 7.711982$ rounded to 6 digits after the decimal place.

    \n\n

    Find $E(10^3)$. Give the answer rounded to 6 digits after the decimal place.

    ", "url": "https://projecteuler.net/problem=819", "answer": "1995.975556"} {"id": 820, "problem": "Let $d_n(x)$ be the $n$th decimal digit of the fractional part of $x$, or $0$ if the fractional part has fewer than $n$ digits.\n\nFor example:\n\n- $d_7 \\mathopen{}\\left( 1 \\right)\\mathclose{} = d_7 \\mathopen{}\\left( \\frac 1 2 \\right)\\mathclose{} = d_7 \\mathopen{}\\left( \\frac 1 4 \\right)\\mathclose{} = d_7 \\mathopen{}\\left( \\frac 1 5 \\right)\\mathclose{} = 0$\n\n- $d_7 \\mathopen{}\\left( \\frac 1 3 \\right)\\mathclose{} = 3$ since $\\frac 1 3 =$ 0.3333333333...\n\n- $d_7 \\mathopen{}\\left( \\frac 1 6 \\right)\\mathclose{} = 6$ since $\\frac 1 6 =$ 0.1666666666...\n\n- $d_7 \\mathopen{}\\left( \\frac 1 7 \\right)\\mathclose{} = 1$ since $\\frac 1 7 =$ 0.1428571428...\n\nLet $\\displaystyle S(n) = \\sum_{k=1}^n d_n \\mathopen{}\\left( \\frac 1 k \\right)\\mathclose{}$.\n\nYou are given:\n\n- $S(7) = 0 + 0 + 3 + 0 + 0 + 6 + 1 = 10$\n\n- $S(100) = 418$\n\nFind $S(10^7)$.", "raw_html": "

    Let $d_n(x)$ be the $n$th decimal digit of the fractional part of $x$, or $0$ if the fractional part has fewer than $n$ digits.

    \n

    For example:

    \n
      \n
    • $d_7 \\mathopen{}\\left( 1 \\right)\\mathclose{} = d_7 \\mathopen{}\\left( \\frac 1 2 \\right)\\mathclose{} = d_7 \\mathopen{}\\left( \\frac 1 4 \\right)\\mathclose{} = d_7 \\mathopen{}\\left( \\frac 1 5 \\right)\\mathclose{} = 0$
    • \n
    • $d_7 \\mathopen{}\\left( \\frac 1 3 \\right)\\mathclose{} = 3$ since $\\frac 1 3 =$ 0.3333333333...
    • \n
    • $d_7 \\mathopen{}\\left( \\frac 1 6 \\right)\\mathclose{} = 6$ since $\\frac 1 6 =$ 0.1666666666...
    • \n
    • $d_7 \\mathopen{}\\left( \\frac 1 7 \\right)\\mathclose{} = 1$ since $\\frac 1 7 =$ 0.1428571428...
    • \n
    \n

    Let $\\displaystyle S(n) = \\sum_{k=1}^n d_n \\mathopen{}\\left( \\frac 1 k \\right)\\mathclose{}$.

    \n

    You are given:

    \n
      \n
    • $S(7) = 0 + 0 + 3 + 0 + 0 + 6 + 1 = 10$
    • \n
    • $S(100) = 418$
    • \n
    \n

    Find $S(10^7)$.

    ", "url": "https://projecteuler.net/problem=820", "answer": "44967734"} {"id": 821, "problem": "A set, $S$, of integers is called 123-separable if $S$, $2S$ and $3S$ are disjoint. Here $2S$ and $3S$ are obtained by multiplying all the elements in $S$ by $2$ and $3$ respectively.\n\nDefine $F(n)$ to be the maximum number of elements of\n$$(S\\cup 2S \\cup 3S)\\cap \\{1,2,3,\\ldots,n\\}$$\nwhere $S$ ranges over all 123-separable sets.\n\nFor example, $F(6) = 5$ can be achieved with either $S = \\{1,4,5\\}$ or $S = \\{1,5,6\\}$.\n\nYou are also given $F(20) = 19$.\n\nFind $F(10^{16})$.", "raw_html": "

    \nA set, $S$, of integers is called 123-separable if $S$, $2S$ and $3S$ are disjoint. Here $2S$ and $3S$ are obtained by multiplying all the elements in $S$ by $2$ and $3$ respectively.

    \n\n

    \nDefine $F(n)$ to be the maximum number of elements of\n$$(S\\cup 2S \\cup 3S)\\cap \\{1,2,3,\\ldots,n\\}$$\nwhere $S$ ranges over all 123-separable sets.

    \n\n

    \nFor example, $F(6) = 5$ can be achieved with either $S = \\{1,4,5\\}$ or $S = \\{1,5,6\\}$.
    \nYou are also given $F(20) = 19$.

    \n\n

    \nFind $F(10^{16})$.

    ", "url": "https://projecteuler.net/problem=821", "answer": "9219661511328178"} {"id": 822, "problem": "A list initially contains the numbers $2, 3, \\dots, n$.\n\nAt each round, the smallest number in the list is replaced by its square. If there is more than one such number, then only one of them is replaced.\n\nFor example, below are the first three rounds for $n = 5$:\n$$[2, 3, 4, 5] \\xrightarrow{(1)} [4, 3, 4, 5] \\xrightarrow{(2)} [4, 9, 4, 5] \\xrightarrow{(3)} [16, 9, 4, 5].$$\n\nLet $S(n, m)$ be the sum of all numbers in the list after $m$ rounds.\n\nFor example, $S(5, 3) = 16 + 9 + 4 + 5 = 34$. Also $S(10, 100) \\equiv 845339386 \\pmod{1234567891}$.\n\nFind $S(10^4, 10^{16})$. Give your answer modulo $1234567891$.", "raw_html": "

    \nA list initially contains the numbers $2, 3, \\dots, n$.
    \nAt each round, the smallest number in the list is replaced by its square. If there is more than one such number, then only one of them is replaced.\n

    \n

    \nFor example, below are the first three rounds for $n = 5$:\n$$[2, 3, 4, 5] \\xrightarrow{(1)} [4, 3, 4, 5] \\xrightarrow{(2)} [4, 9, 4, 5] \\xrightarrow{(3)} [16, 9, 4, 5].$$\n

    \n

    \nLet $S(n, m)$ be the sum of all numbers in the list after $m$ rounds.

    \nFor example, $S(5, 3) = 16 + 9 + 4 + 5 = 34$. Also $S(10, 100) \\equiv 845339386 \\pmod{1234567891}$.\n

    \n

    \nFind $S(10^4, 10^{16})$. Give your answer modulo $1234567891$.\n

    ", "url": "https://projecteuler.net/problem=822", "answer": "950591530"} {"id": 823, "problem": "A list initially contains the numbers $2, 3, \\dots, n$.\n\nAt each round, every number in the list is divided by its smallest prime factor. Then the product of these smallest prime factors is added to the list as a new number. Finally, all numbers that become $1$ are removed from the list.\n\nFor example, below are the first three rounds for $n = 5$:\n$$[2, 3, 4, 5] \\xrightarrow{(1)} [2, 60] \\xrightarrow{(2)} [30, 4] \\xrightarrow{(3)} [15, 2, 4].$$\nLet $S(n, m)$ be the sum of all numbers in the list after $m$ rounds.\n\nFor example, $S(5, 3) = 15 + 2 + 4 = 21$. Also $S(10, 100) = 257$.\n\nFind $S(10^4, 10^{16})$. Give your answer modulo $1234567891$.", "raw_html": "

    A list initially contains the numbers $2, 3, \\dots, n$.
    \nAt each round, every number in the list is divided by its smallest prime factor. Then the product of these smallest prime factors is added to the list as a new number. Finally, all numbers that become $1$ are removed from the list.

    \n\n

    For example, below are the first three rounds for $n = 5$:\n$$[2, 3, 4, 5] \\xrightarrow{(1)} [2, 60] \\xrightarrow{(2)} [30, 4] \\xrightarrow{(3)} [15, 2, 4].$$\nLet $S(n, m)$ be the sum of all numbers in the list after $m$ rounds.
    \nFor example, $S(5, 3) = 15 + 2 + 4 = 21$. Also $S(10, 100) = 257$.

    \n\n

    Find $S(10^4, 10^{16})$. Give your answer modulo $1234567891$.

    ", "url": "https://projecteuler.net/problem=823", "answer": "865849519"} {"id": 824, "problem": "A Slider is a chess piece that can move one square left or right.\n\nThis problem uses a cylindrical chess board where the left hand edge of the board is connected to the right hand edge. This means that a Slider that is on the left hand edge of the chess board can move to the right hand edge of the same row and vice versa.\n\nLet $L(N,K)$ be the number of ways $K$ non-attacking Sliders can be placed on an $N \\times N$ cylindrical chess-board.\n\nFor example, $L(2,2)=4$ and $L(6,12)=4204761$.\n\nFind $L(10^9,10^{15}) \\bmod \\left(10^7+19\\right)^2$.", "raw_html": "

    A Slider is a chess piece that can move one square left or right.

    \n\n

    This problem uses a cylindrical chess board where the left hand edge of the board is connected to the right hand edge. This means that a Slider that is on the left hand edge of the chess board can move to the right hand edge of the same row and vice versa.

    \n\n

    Let $L(N,K)$ be the number of ways $K$ non-attacking Sliders can be placed on an $N \\times N$ cylindrical chess-board.

    \n\n

    For example, $L(2,2)=4$ and $L(6,12)=4204761$.

    \n\n

    Find $L(10^9,10^{15}) \\bmod \\left(10^7+19\\right)^2$.

    ", "url": "https://projecteuler.net/problem=824", "answer": "26532152736197"} {"id": 825, "problem": "Two cars are on a circular track of total length $2n$, facing the same direction, initially distance $n$ apart.\n\nThey move in turn. At each turn, the moving car will advance a distance of $1$, $2$ or $3$, with equal probabilities.\n\nThe chase ends when the moving car reaches or goes beyond the position of the other car. The moving car is declared the winner.\n\nLet $S(n)$ be the difference between the winning probabilities of the two cars.\n\nFor example, when $n = 2$, the winning probabilities of the two cars are $\\frac 9 {11}$ and $\\frac 2 {11}$, and thus $S(2) = \\frac 7 {11}$.\n\nLet $\\displaystyle T(N) = \\sum_{n = 2}^N S(n)$.\n\nYou are given that $T(10) = 2.38235282$ rounded to 8 digits after the decimal point.\n\nFind $T(10^{14})$, rounded to 8 digits after the decimal point.", "raw_html": "

    Two cars are on a circular track of total length $2n$, facing the same direction, initially distance $n$ apart.
    \nThey move in turn. At each turn, the moving car will advance a distance of $1$, $2$ or $3$, with equal probabilities.
    \nThe chase ends when the moving car reaches or goes beyond the position of the other car. The moving car is declared the winner.

    \n\n

    Let $S(n)$ be the difference between the winning probabilities of the two cars.
    \nFor example, when $n = 2$, the winning probabilities of the two cars are $\\frac 9 {11}$ and $\\frac 2 {11}$, and thus $S(2) = \\frac 7 {11}$.

    \n\n

    Let $\\displaystyle T(N) = \\sum_{n = 2}^N S(n)$.

    \n\n

    You are given that $T(10) = 2.38235282$ rounded to 8 digits after the decimal point.

    \n\n

    Find $T(10^{14})$, rounded to 8 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=825", "answer": "32.34481054"} {"id": 826, "problem": "Consider a wire of length 1 unit between two posts. Every morning $n$ birds land on it randomly with every point on the wire equally likely to host a bird. The interval from each bird to its closest neighbour is then painted.\n\nDefine $F(n)$ to be the expected length of the wire that is painted. You are given $F(3) = 0.5$.\n\nFind the average of $F(n)$ where $n$ ranges through all odd prime less than a million. Give your answer rounded to 10 places after the decimal point.", "raw_html": "

    Consider a wire of length 1 unit between two posts. Every morning $n$ birds land on it randomly with every point on the wire equally likely to host a bird. The interval from each bird to its closest neighbour is then painted.

    \n\n

    Define $F(n)$ to be the expected length of the wire that is painted. You are given $F(3) = 0.5$.

    \n\n

    Find the average of $F(n)$ where $n$ ranges through all odd prime less than a million. Give your answer rounded to 10 places after the decimal point.

    ", "url": "https://projecteuler.net/problem=826", "answer": "0.3889014797"} {"id": 827, "problem": "Define $Q(n)$ to be the smallest number that occurs in exactly $n$ Pythagorean triples $(a,b,c)$ where $a \\lt b \\lt c$.\n\nFor example, $15$ is the smallest number occurring in exactly $5$ Pythagorean triples:\n$$(9,12,\\mathbf{15})\\quad (8,\\mathbf{15},17)\\quad (\\mathbf{15},20,25)\\quad (\\mathbf{15},36,39)\\quad (\\mathbf{15},112,113)$$\nand so $Q(5) = 15$.\n\nYou are also given $Q(10)=48$ and $Q(10^3)=8064000$.\n\nFind $\\displaystyle \\sum_{k=1}^{18} Q(10^k)$. Give your answer modulo $409120391$.", "raw_html": "

    \nDefine $Q(n)$ to be the smallest number that occurs in exactly $n$ Pythagorean triples $(a,b,c)$ where $a \\lt b \\lt c$.

    \n\n

    \nFor example, $15$ is the smallest number occurring in exactly $5$ Pythagorean triples:\n$$(9,12,\\mathbf{15})\\quad (8,\\mathbf{15},17)\\quad (\\mathbf{15},20,25)\\quad (\\mathbf{15},36,39)\\quad (\\mathbf{15},112,113)$$\nand so $Q(5) = 15$.

    \n\n

    \nYou are also given $Q(10)=48$ and $Q(10^3)=8064000$.

    \n\n

    \nFind $\\displaystyle \\sum_{k=1}^{18} Q(10^k)$. Give your answer modulo $409120391$.

    ", "url": "https://projecteuler.net/problem=827", "answer": "397289979"} {"id": 828, "problem": "It is a common recreational problem to make a target number using a selection of other numbers. In this problem you will be given six numbers and a target number.\n\nFor example, given the six numbers $2$, $3$, $4$, $6$, $7$, $25$, and a target of $211$, one possible solution is:\n\n$$211 = (3+6)\\times 25 − (4\\times7)\\div 2$$\nThis uses all six numbers. However, it is not necessary to do so. Another solution that does not use the $7$ is:\n\n$$211 = (25−2)\\times (6+3) + 4$$\n\nDefine the score of a solution to be the sum of the numbers used. In the above example problem, the two given solutions have scores $47$ and $40$ respectively. It turns out that this problem has no solutions with score less than $40$.\n\nWhen combining numbers, the following rules must be observed:\n\n- Each available number may be used at most once.\n\n- Only the four basic arithmetic operations are permitted: $+$, $-$, $\\times$, $\\div$.\n\n- All intermediate values must be positive integers, so for example $(3\\div 2)$ is never permitted as a subexpression (even if the final answer is an integer).\n\nThe attached file number-challenges.txt contains 200 problems, one per line in the format:\n\n211:2,3,4,6,7,25\nwhere the number before the colon is the target and the remaining comma-separated numbers are those available to be used.\n\nNumbering the problems 1, 2, ..., 200, we let $s_n$ be the minimum score of the solution to the $n$th problem. For example, $s_1=40$, as the first problem in the file is the example given above. Note that not all problems have a solution; in such cases we take $s_n=0$.\n\nFind $\\displaystyle\\sum_{n=1}^{200} 3^n s_n$. Give your answer modulo $1005075251$.", "raw_html": "

    It is a common recreational problem to make a target number using a selection of other numbers. In this problem you will be given six numbers and a target number.

    \n\n

    For example, given the six numbers $2$, $3$, $4$, $6$, $7$, $25$, and a target of $211$, one possible solution is:

    \n$$211 = (3+6)\\times 25 − (4\\times7)\\div 2$$\n

    This uses all six numbers. However, it is not necessary to do so. Another solution that does not use the $7$ is:

    \n$$211 = (25−2)\\times (6+3) + 4$$\n\n

    Define the score of a solution to be the sum of the numbers used. In the above example problem, the two given solutions have scores $47$ and $40$ respectively. It turns out that this problem has no solutions with score less than $40$.

    \n\n

    When combining numbers, the following rules must be observed:

    \n
      \n
    • Each available number may be used at most once.
    • \n
    • Only the four basic arithmetic operations are permitted: $+$, $-$, $\\times$, $\\div$.
    • \n
    • All intermediate values must be positive integers, so for example $(3\\div 2)$ is never permitted as a subexpression (even if the final answer is an integer).
    • \n
    \n\n

    The attached file number-challenges.txt contains 200 problems, one per line in the format:

    \n
    211:2,3,4,6,7,25
    \n

    where the number before the colon is the target and the remaining comma-separated numbers are those available to be used.

    \n\n

    Numbering the problems 1, 2, ..., 200, we let $s_n$ be the minimum score of the solution to the $n$th problem. For example, $s_1=40$, as the first problem in the file is the example given above. Note that not all problems have a solution; in such cases we take $s_n=0$.

    \n\n

    Find $\\displaystyle\\sum_{n=1}^{200} 3^n s_n$. Give your answer modulo $1005075251$.

    ", "url": "https://projecteuler.net/problem=828", "answer": "148693670"} {"id": 829, "problem": "Given any integer $n \\gt 1$ a binary factor tree $T(n)$ is defined to be:\n\n- A tree with the single node $n$ when $n$ is prime.\n\n- A binary tree that has root node $n$, left subtree $T(a)$ and right subtree $T(b)$, when $n$ is not prime. Here $a$ and $b$ are positive integers such that $n = ab$, $a\\le b$ and $b-a$ is the smallest.\n\nFor example $T(20)$:\n\nWe define $M(n)$ to be the smallest number that has a factor tree identical in shape to the factor tree for $n!!$, the double factorial of $n$.\n\nFor example, consider $9!! = 9\\times 7\\times 5\\times 3\\times 1 = 945$. The factor tree for $945$ is shown below together with the factor tree for $72$ which is the smallest number that has a factor tree of the same shape. Hence $M(9) = 72$.\n\nFind $\\displaystyle\\sum_{n=2}^{31} M(n)$.", "raw_html": "

    Given any integer $n \\gt 1$ a binary factor tree $T(n)$ is defined to be:

    \n
      \n
    • A tree with the single node $n$ when $n$ is prime.
    • \n
    • A binary tree that has root node $n$, left subtree $T(a)$ and right subtree $T(b)$, when $n$ is not prime. Here $a$ and $b$ are positive integers such that $n = ab$, $a\\le b$ and $b-a$ is the smallest.
    • \n
    \n

    For example $T(20)$:

    \n\"0829_example1.jpg\"\n\n

    We define $M(n)$ to be the smallest number that has a factor tree identical in shape to the factor tree for $n!!$, the double factorial of $n$.

    \n\n

    For example, consider $9!! = 9\\times 7\\times 5\\times 3\\times 1 = 945$. The factor tree for $945$ is shown below together with the factor tree for $72$ which is the smallest number that has a factor tree of the same shape. Hence $M(9) = 72$.

    \n\"0829_example2.jpg\"\n\n

    Find $\\displaystyle\\sum_{n=2}^{31} M(n)$.

    ", "url": "https://projecteuler.net/problem=829", "answer": "41768797657018024"} {"id": 830, "problem": "Let $\\displaystyle S(n)=\\sum\\limits_{k=0}^{n}\\binom{n}{k}k^n$.\n\nYou are given, $S(10)=142469423360$.\n\nFind $S(10^{18})$. Submit your answer modulo $83^3 89^3 97^3$.", "raw_html": "

    \nLet $\\displaystyle S(n)=\\sum\\limits_{k=0}^{n}\\binom{n}{k}k^n$.

    \n\n

    \nYou are given, $S(10)=142469423360$.

    \n\n

    \nFind $S(10^{18})$. Submit your answer modulo $83^3 89^3 97^3$.

    ", "url": "https://projecteuler.net/problem=830", "answer": "254179446930484376"} {"id": 831, "problem": "Let $g(m)$ be the integer defined by the following double sum of products of binomial coefficients:\n\n$$\\sum_{j=0}^m\\sum_{i = 0}^j (-1)^{j-i}\\binom mj \\binom ji \\binom{j+5+6i}{j+5}.$$\n\nYou are given that $g(10) = 127278262644918$.\nIts first (most significant) five digits are $12727$.\n\nFind the first ten digits of $g(142857)$ when written in base $7$.", "raw_html": "

    Let $g(m)$ be the integer defined by the following double sum of products of binomial coefficients:

    \n

    \n$$\\sum_{j=0}^m\\sum_{i = 0}^j (-1)^{j-i}\\binom mj \\binom ji \\binom{j+5+6i}{j+5}.$$\n

    \n

    \nYou are given that $g(10) = 127278262644918$.
    Its first (most significant) five digits are $12727$.
    \n\nFind the first ten digits of $g(142857)$ when written in base $7$.\n

    ", "url": "https://projecteuler.net/problem=831", "answer": "5226432553"} {"id": 832, "problem": "In this problem $\\oplus$ is used to represent the bitwise exclusive or of two numbers.\n\nStarting with blank paper repeatedly do the following:\n\n- Write down the smallest positive integer $a$ which is currently not on the paper;\n\n- Find the smallest positive integer $b$ such that neither $b$ nor $(a \\oplus b)$ is currently on the paper. Then write down both $b$ and $(a \\oplus b)$.\n\nAfter the first round $\\{1,2,3\\}$ will be written on the paper. In the second round $a=4$ and because $(4 \\oplus 5)$, $(4 \\oplus 6)$ and $(4 \\oplus 7)$ are all already written $b$ must be $8$.\n\nAfter $n$ rounds there will be $3n$ numbers on the paper. Their sum is denoted by $M(n)$.\n\nFor example, $M(10) = 642$ and $M(1000) = 5432148$.\n\nFind $M(10^{18})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nIn this problem $\\oplus$ is used to represent the bitwise exclusive or of two numbers.
    \nStarting with blank paper repeatedly do the following:

    \n\n
      \n
    1. Write down the smallest positive integer $a$ which is currently not on the paper;
    2. \n\n
    3. Find the smallest positive integer $b$ such that neither $b$ nor $(a \\oplus b)$ is currently on the paper. Then write down both $b$ and $(a \\oplus b)$.
    4. \n
    \n\n

    \nAfter the first round $\\{1,2,3\\}$ will be written on the paper. In the second round $a=4$ and because $(4 \\oplus 5)$, $(4 \\oplus 6)$ and $(4 \\oplus 7)$ are all already written $b$ must be $8$.

    \n\n

    \nAfter $n$ rounds there will be $3n$ numbers on the paper. Their sum is denoted by $M(n)$.
    \nFor example, $M(10) = 642$ and $M(1000) = 5432148$.

    \n\n

    \nFind $M(10^{18})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=832", "answer": "552839586"} {"id": 833, "problem": "Triangle numbers $T_k$ are integers of the form $\\frac{k(k+1)} 2$.\n\nA few triangle numbers happen to be perfect squares like $T_1=1$ and $T_8=36$, but more can be found when considering the product of two triangle numbers. For example, $T_2 \\cdot T_{24}=3 \\cdot 300=30^2$.\n\nLet $S(n)$ be the sum of $c$ for all integers triples $(a, b, c)$ with $0Triangle numbers $T_k$ are integers of the form $\\frac{k(k+1)} 2$.
    \nA few triangle numbers happen to be perfect squares like $T_1=1$ and $T_8=36$, but more can be found when considering the product of two triangle numbers. For example, $T_2 \\cdot T_{24}=3 \\cdot 300=30^2$.

    \n\n

    Let $S(n)$ be the sum of $c$ for all integers triples $(a, b, c)$ with $0<c \\le n$, $c^2=T_a \\cdot T_b$ and $0<a<b$.\nFor example, $S(100)= \\sqrt{T_1 T_8}+\\sqrt{T_2 T_{24}}+\\sqrt{T_1 T_{49}}+\\sqrt{T_3 T_{48}}=6+30+35+84=155$.

    \n

    \nYou are given $S(10^5)=1479802$ and $S(10^9)=241614948794$.

    \n

    \nFind $S(10^{35})$. Give your answer modulo $136101521$.

    ", "url": "https://projecteuler.net/problem=833", "answer": "43884302"} {"id": 834, "problem": "A sequence is created by starting with a positive integer $n$ and incrementing by $(n+m)$ at the $m^{th}$ step.\nIf $n=10$, the resulting sequence will be $21,33,46,60,75,91,108,126,\\ldots$.\n\nLet $S(n)$ be the set of indices $m$, for which the $m^{th}$ term in the sequence is divisible by $(n+m)$.\n\nFor example, $S(10)=\\{5,8,20,35,80\\}$.\n\nDefine $T(n)$ to be the sum of the indices in $S(n)$. For example, $T(10) = 148$ and $T(10^2)=21828$.\n\nLet $\\displaystyle U(N)=\\sum_{n=3}^{N}T(n)$. You are given, $U(10^2)=612572$.\n\nFind $U(1234567)$.", "raw_html": "

    \nA sequence is created by starting with a positive integer $n$ and incrementing by $(n+m)$ at the $m^{th}$ step. \nIf $n=10$, the resulting sequence will be $21,33,46,60,75,91,108,126,\\ldots$.

    \n\n

    \nLet $S(n)$ be the set of indices $m$, for which the $m^{th}$ term in the sequence is divisible by $(n+m)$.
    \nFor example, $S(10)=\\{5,8,20,35,80\\}$.

    \n\n

    \nDefine $T(n)$ to be the sum of the indices in $S(n)$. For example, $T(10) = 148$ and $T(10^2)=21828$.

    \n\n

    \nLet $\\displaystyle U(N)=\\sum_{n=3}^{N}T(n)$. You are given, $U(10^2)=612572$.

    \n\n

    \nFind $U(1234567)$.

    ", "url": "https://projecteuler.net/problem=834", "answer": "1254404167198752370"} {"id": 835, "problem": "A Pythagorean triangle is called supernatural if two of its three sides are consecutive\nintegers.\n\nLet $S(N)$ be the sum of the perimeters of all distinct supernatural triangles with perimeters less than or equal to $N$.\n\nFor example, $S(100) = 258$ and $S(10000) = 172004$.\n\nFind $S(10^{10^{10}})$. Give your answer modulo $1234567891$.", "raw_html": "

    \nA Pythagorean triangle is called supernatural if two of its three sides are consecutive \n integers.\n

    \n

    \nLet $S(N)$ be the sum of the perimeters of all distinct supernatural triangles with perimeters less than or equal to $N$.
    \nFor example, $S(100) = 258$ and $S(10000) = 172004$.\n

    \n

    \nFind $S(10^{10^{10}})$. Give your answer modulo $1234567891$.\n

    ", "url": "https://projecteuler.net/problem=835", "answer": "1050923942"} {"id": 836, "problem": "Let $A$ be an affine plane over a radically integral local field $F$ with residual characteristic $p$.\n\nWe consider an open oriented line section $U$ of $A$ with normalized Haar measure $m$.\n\nDefine $f(m, p)$ as the maximal possible discriminant of the jacobian associated to the orthogonal kernel embedding of $U$ into $A$.\n\nFind $f(20230401, 57)$. Give as your answer the concatenation of the first letters of each bolded word.", "raw_html": "

    Let $A$ be an affine plane over a radically integral local field $F$ with residual characteristic $p$.

    \n\n

    We consider an open oriented line section $U$ of $A$ with normalized Haar measure $m$.

    \n\n

    Define $f(m, p)$ as the maximal possible discriminant of the jacobian associated to the orthogonal kernel embedding of $U$ into $A$.

    \n\n

    Find $f(20230401, 57)$. Give as your answer the concatenation of the first letters of each bolded word.

    ", "url": "https://projecteuler.net/problem=836", "answer": "aprilfoolsjoke"} {"id": 837, "problem": "Amidakuji (Japanese: 阿弥陀籤) is a method for producing a random permutation of a set of objects.\n\nIn the beginning, a number of parallel vertical lines are drawn, one for each object. Then a specified number of horizontal rungs are added, each lower than any previous rungs. Each rung is drawn as a line segment spanning a randomly select pair of adjacent vertical lines.\n\nFor example, the following diagram depicts an Amidakuji with three objects ($A$, $B$, $C$) and six rungs:\n\nThe coloured lines in the diagram illustrate how to form the permutation. For each object, starting from the top of its vertical line, trace downwards but follow any rung encountered along the way, and record which vertical we end up on. In this example, the resulting permutation happens to be the identity: $A\\mapsto A$, $B\\mapsto B$, $C\\mapsto C$.\n\nLet $a(m, n)$ be the number of different three-object Amidakujis that have $m$ rungs between $A$ and $B$, and $n$ rungs between $B$ and $C$, and whose outcome is the identity permutation. For example, $a(3, 3) = 2$, because the Amidakuji shown above and its mirror image are the only ones with the required property.\n\nYou are also given that $a(123, 321) \\equiv 172633303 \\pmod{1234567891}$.\n\nFind $a(123456789, 987654321)$. Give your answer modulo $1234567891$.", "raw_html": "

    \nAmidakuji (Japanese: 阿弥陀籤) is a method for producing a random permutation of a set of objects.

    \n\n

    \nIn the beginning, a number of parallel vertical lines are drawn, one for each object. Then a specified number of horizontal rungs are added, each lower than any previous rungs. Each rung is drawn as a line segment spanning a randomly select pair of adjacent vertical lines.

    \n\n

    \nFor example, the following diagram depicts an Amidakuji with three objects ($A$, $B$, $C$) and six rungs:

    \n
    \n\"0837_amidakuji.png\"\n
    \n\n

    \nThe coloured lines in the diagram illustrate how to form the permutation. For each object, starting from the top of its vertical line, trace downwards but follow any rung encountered along the way, and record which vertical we end up on. In this example, the resulting permutation happens to be the identity: $A\\mapsto A$, $B\\mapsto B$, $C\\mapsto C$.

    \n\n

    \nLet $a(m, n)$ be the number of different three-object Amidakujis that have $m$ rungs between $A$ and $B$, and $n$ rungs between $B$ and $C$, and whose outcome is the identity permutation. For example, $a(3, 3) = 2$, because the Amidakuji shown above and its mirror image are the only ones with the required property.

    \n\n

    \nYou are also given that $a(123, 321) \\equiv 172633303 \\pmod{1234567891}$.

    \n\n

    \nFind $a(123456789, 987654321)$. Give your answer modulo $1234567891$.

    ", "url": "https://projecteuler.net/problem=837", "answer": "428074856"} {"id": 838, "problem": "Let $f(N)$ be the smallest positive integer that is not coprime to any positive integer $n \\le N$ whose least significant digit is $3$.\n\nFor example $f(40)$ equals to $897 = 3 \\cdot 13 \\cdot 23$ since it is not coprime to any of $3,13,23,33$. By taking the natural logarithm (log to base $e$) we obtain $\\ln f(40) = \\ln 897 \\approx 6.799056$ when rounded to six digits after the decimal point.\n\nYou are also given $\\ln f(2800) \\approx 715.019337$.\n\nFind $f(10^6)$. Enter its natural logarithm rounded to six digits after the decimal point.", "raw_html": "

    Let $f(N)$ be the smallest positive integer that is not coprime to any positive integer $n \\le N$ whose least significant digit is $3$.

    \n\n

    For example $f(40)$ equals to $897 = 3 \\cdot 13 \\cdot 23$ since it is not coprime to any of $3,13,23,33$. By taking the natural logarithm (log to base $e$) we obtain $\\ln f(40) = \\ln 897 \\approx 6.799056$ when rounded to six digits after the decimal point.

    \n\n

    You are also given $\\ln f(2800) \\approx 715.019337$.

    \n\n

    Find $f(10^6)$. Enter its natural logarithm rounded to six digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=838", "answer": "250591.442792"} {"id": 839, "problem": "The sequence $S_n$ is defined by $S_0 = 290797$ and $S_n = S_{n - 1}^2 \\bmod 50515093$ for $n > 0$.\n\nThere are $N$ bowls indexed $0,1,\\dots ,N-1$. Initially there are $S_n$ beans in bowl $n$.\n\nAt each step, the smallest index $n$ is found such that bowl $n$ has strictly more beans than bowl $n+1$. Then one bean is moved from bowl $n$ to bowl $n+1$.\n\nLet $B(N)$ be the number of steps needed to sort the bowls into non-descending order.\n\nFor example, $B(5) = 0$, $B(6) = 14263289$ and $B(100)=3284417556$.\n\nFind $B(10^7)$.", "raw_html": "

    \nThe sequence $S_n$ is defined by $S_0 = 290797$ and $S_n = S_{n - 1}^2 \\bmod 50515093$ for $n > 0$.

    \n\n

    There are $N$ bowls indexed $0,1,\\dots ,N-1$. Initially there are $S_n$ beans in bowl $n$.

    \n\n

    \nAt each step, the smallest index $n$ is found such that bowl $n$ has strictly more beans than bowl $n+1$. Then one bean is moved from bowl $n$ to bowl $n+1$.

    \n\n

    \nLet $B(N)$ be the number of steps needed to sort the bowls into non-descending order.
    \nFor example, $B(5) = 0$, $B(6) = 14263289$ and $B(100)=3284417556$.

    \n\n

    \nFind $B(10^7)$.

    ", "url": "https://projecteuler.net/problem=839", "answer": "150893234438294408"} {"id": 840, "problem": "A partition of $n$ is a set of positive integers for which the sum equals $n$.\n\nThe partitions of 5 are:\n\n$\\{5\\},\\{1,4\\},\\{2,3\\},\\{1,1,3\\},\\{1,2,2\\},\\{1,1,1,2\\}$ and $\\{1,1,1,1,1\\}$.\n\nFurther we define the function $D(p)$ as:\n\n$$\n\\begin{align}\n\\begin{split}\nD(1) &= 1 \\\\\nD(p) &= 1, \\text{ for any prime } p \\\\\nD(pq) &= D(p)q + pD(q), \\text{ for any positive integers } p,q \\gt 1.\n\\end{split}\n\\end{align}\n$$\n\nNow let $\\{a_1, a_2,\\ldots,a_k\\}$ be a partition of $n$.\n\nWe assign to this particular partition the value:\n$$P=\\prod_{j=1}^{k}D(a_j). $$\n\n$G(n)$ is the sum of $P$ for all partitions of $n$.\n\nWe can verify that $G(10) = 164$.\n\nWe also define:\n$$S(N)=\\sum_{n=1}^{N}G(n).$$\nYou are given $S(10)=396$.\n\nFind $S(5\\times 10^4) \\mod 999676999$.", "raw_html": "

    A partition of $n$ is a set of positive integers for which the sum equals $n$.
    \nThe partitions of 5 are:
    \n$\\{5\\},\\{1,4\\},\\{2,3\\},\\{1,1,3\\},\\{1,2,2\\},\\{1,1,1,2\\}$ and $\\{1,1,1,1,1\\}$.\n

    \n

    \nFurther we define the function $D(p)$ as:
    \n$$\n\\begin{align}\n\\begin{split}\nD(1) &= 1 \\\\\nD(p) &= 1, \\text{ for any prime } p \\\\\nD(pq) &= D(p)q + pD(q), \\text{ for any positive integers } p,q \\gt 1.\n\\end{split}\n\\end{align}\n$$\n

    \n

    \nNow let $\\{a_1, a_2,\\ldots,a_k\\}$ be a partition of $n$.
    \nWe assign to this particular partition the value:
    $$P=\\prod_{j=1}^{k}D(a_j). $$\n

    \n

    \n$G(n)$ is the sum of $P$ for all partitions of $n$.
    \nWe can verify that $G(10) = 164$.\n

    \nWe also define:\n$$S(N)=\\sum_{n=1}^{N}G(n).$$\nYou are given $S(10)=396$.
    \nFind $S(5\\times 10^4) \\mod 999676999$.", "url": "https://projecteuler.net/problem=840", "answer": "194396971"} {"id": 841, "problem": "The regular star polygon $\\{p/q\\}$, for coprime integers $p,q$ with $p \\gt 2q \\gt 0$, is a polygon formed from $p$ edges of equal length and equal internal angles, such that tracing the complete polygon wraps $q$ times around the centre. For example, $\\{8/3\\}$ is illustrated below:\n\nThe edges of a regular star polygon intersect one another, dividing the interior into several regions. Define the alternating shading of a regular star polygon to be a selection of such regions to shade, such that every piece of every edge has a shaded region on one side and an unshaded region on the other, with the exterior of the polygon unshaded. For example, the above image shows the alternating shading (in green) of $\\{8/3\\}$.\n\nLet $A(p, q)$ be the area of the alternating shading of $\\{p/q\\}$, assuming that its inradius is $1$. (The inradius of a regular polygon, star or otherwise, is the distance from its centre to the midpoint of any of its edges.) For example, in the diagram above, it can be shown that central shaded octagon has area $8(\\sqrt{2}-1)$ and each point's shaded kite has area $2(\\sqrt{2}-1)$, giving $A(8,3) = 24(\\sqrt{2}-1) \\approx 9.9411254970$.\n\nYou are also given that $A(130021, 50008)\\approx 10.9210371479$, rounded to $10$ digits after the decimal point.\n\nFind $\\sum_{n=3}^{34} A(F_{n+1},F_{n-1})$, where $F_j$ is the Fibonacci sequence with $F_1=F_2=1$ (so $A(F_{5+1},F_{5-1}) = A(8,3)$). Give your answer rounded to $10$ digits after the decimal point.", "raw_html": "

    The regular star polygon $\\{p/q\\}$, for coprime integers $p,q$ with $p \\gt 2q \\gt 0$, is a polygon formed from $p$ edges of equal length and equal internal angles, such that tracing the complete polygon wraps $q$ times around the centre. For example, $\\{8/3\\}$ is illustrated below:

    \n
    \"{8/3}\"
    \n\n

    The edges of a regular star polygon intersect one another, dividing the interior into several regions. Define the alternating shading of a regular star polygon to be a selection of such regions to shade, such that every piece of every edge has a shaded region on one side and an unshaded region on the other, with the exterior of the polygon unshaded. For example, the above image shows the alternating shading (in green) of $\\{8/3\\}$.

    \n\n

    Let $A(p, q)$ be the area of the alternating shading of $\\{p/q\\}$, assuming that its inradius is $1$. (The inradius of a regular polygon, star or otherwise, is the distance from its centre to the midpoint of any of its edges.) For example, in the diagram above, it can be shown that central shaded octagon has area $8(\\sqrt{2}-1)$ and each point's shaded kite has area $2(\\sqrt{2}-1)$, giving $A(8,3) = 24(\\sqrt{2}-1) \\approx 9.9411254970$.

    \n\n

    You are also given that $A(130021, 50008)\\approx 10.9210371479$, rounded to $10$ digits after the decimal point.

    \n\n

    Find $\\sum_{n=3}^{34} A(F_{n+1},F_{n-1})$, where $F_j$ is the Fibonacci sequence with $F_1=F_2=1$ (so $A(F_{5+1},F_{5-1}) = A(8,3)$). Give your answer rounded to $10$ digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=841", "answer": "381.7860132854"} {"id": 842, "problem": "Given $n$ equally spaced points on a circle, we define an $n$-star polygon as an $n$-gon having those $n$ points as vertices. Two $n$-star polygons differing by a rotation/reflection are considered different.\n\nFor example, there are twelve $5$-star polygons shown below.\n\nFor an $n$-star polygon $S$, let $I(S)$ be the number of its self intersection points.\n\nLet $T(n)$ be the sum of $I(S)$ over all $n$-star polygons $S$.\n\nFor the example above $T(5) = 20$ because in total there are $20$ self intersection points.\n\nSome star polygons may have intersection points made from more than two lines. These are only counted once. For example, $S$, shown below is one of the sixty $6$-star polygons. This one has $I(S) = 4$.\n\nYou are also given that $T(8) = 14640$.\n\nFind $\\displaystyle \\sum_{n = 3}^{60}T(n)$. Give your answer modulo $(10^9 + 7)$.", "raw_html": "

    \nGiven $n$ equally spaced points on a circle, we define an $n$-star polygon as an $n$-gon having those $n$ points as vertices. Two $n$-star polygons differing by a rotation/reflection are considered different.

    \n\n

    \nFor example, there are twelve $5$-star polygons shown below.

    \n\"0842_5-agons.jpg\"\n

    \nFor an $n$-star polygon $S$, let $I(S)$ be the number of its self intersection points.
    \nLet $T(n)$ be the sum of $I(S)$ over all $n$-star polygons $S$.
    \nFor the example above $T(5) = 20$ because in total there are $20$ self intersection points.

    \n\n

    \nSome star polygons may have intersection points made from more than two lines. These are only counted once. For example, $S$, shown below is one of the sixty $6$-star polygons. This one has $I(S) = 4$.

    \n\"0842_6-agon.jpg\"\n

    \nYou are also given that $T(8) = 14640$.

    \n\n

    \nFind $\\displaystyle \\sum_{n = 3}^{60}T(n)$. Give your answer modulo $(10^9 + 7)$.

    ", "url": "https://projecteuler.net/problem=842", "answer": "885226002"} {"id": 843, "problem": "This problem involves an iterative procedure that begins with a circle of $n\\ge 3$ integers. At each step every number is simultaneously replaced with the absolute difference of its two neighbours.\n\nFor any initial values, the procedure eventually becomes periodic.\n\nLet $S(N)$ be the sum of all possible periods for $3\\le n \\leq N$. For example, $S(6) = 6$, because the possible periods for $3\\le n \\leq 6$ are $1, 2, 3$. Specifically, $n=3$ and $n=4$ can each have period $1$ only, while $n=5$ can have period $1$ or $3$, and $n=6$ can have period $1$ or $2$.\n\nYou are also given $S(30) = 20381$.\n\nFind $S(100)$.", "raw_html": "

    \nThis problem involves an iterative procedure that begins with a circle of $n\\ge 3$ integers. At each step every number is simultaneously replaced with the absolute difference of its two neighbours.

    \n\n

    \nFor any initial values, the procedure eventually becomes periodic.

    \n\n

    \nLet $S(N)$ be the sum of all possible periods for $3\\le n \\leq N$. For example, $S(6) = 6$, because the possible periods for $3\\le n \\leq 6$ are $1, 2, 3$. Specifically, $n=3$ and $n=4$ can each have period $1$ only, while $n=5$ can have period $1$ or $3$, and $n=6$ can have period $1$ or $2$.

    \n\n

    \nYou are also given $S(30) = 20381$.

    \n\n

    \nFind $S(100)$.

    ", "url": "https://projecteuler.net/problem=843", "answer": "2816775424692"} {"id": 844, "problem": "Consider positive integer solutions to\n\n$a^2+b^2+c^2 = 3abc$\nFor example, $(1,5,13)$ is a solution. We define a 3-Markov number to be any part of a solution, so $1$, $5$ and $13$ are all 3-Markov numbers. Adding distinct 3-Markov numbers $\\le 10^3$ would give $2797$.\n\nNow we define a $k$-Markov number to be a positive integer that is part of a solution to:\n\n$\\displaystyle \\sum_{i=1}^{k}x_i^2=k\\prod_{i=1}^{k}x_i,\\quad x_i\\text{ are positive integers}$\n\nLet $M_k(N)$ be the sum of $k$-Markov numbers $\\le N$. Hence $M_3(10^{3})=2797$, also $M_8(10^8) = 131493335$.\n\nDefine $\\displaystyle S(K,N)=\\sum_{k=3}^{K}M_k(N)$. You are given $S(4, 10^2)=229$ and $S(10, 10^8)=2383369980$.\n\nFind $S(10^{18}, 10^{18})$. Give your answer modulo $1\\,405\\,695\\,061$.", "raw_html": "

    Consider positive integer solutions to

    \n
    $a^2+b^2+c^2 = 3abc$
    \n

    For example, $(1,5,13)$ is a solution. We define a 3-Markov number to be any part of a solution, so $1$, $5$ and $13$ are all 3-Markov numbers. Adding distinct 3-Markov numbers $\\le 10^3$ would give $2797$.

    \n\n

    Now we define a $k$-Markov number to be a positive integer that is part of a solution to:

    \n
    $\\displaystyle \\sum_{i=1}^{k}x_i^2=k\\prod_{i=1}^{k}x_i,\\quad x_i\\text{ are positive integers}$
    \n\n

    Let $M_k(N)$ be the sum of $k$-Markov numbers $\\le N$. Hence $M_3(10^{3})=2797$, also $M_8(10^8) = 131493335$.

    \n\n

    Define $\\displaystyle S(K,N)=\\sum_{k=3}^{K}M_k(N)$. You are given $S(4, 10^2)=229$ and $S(10, 10^8)=2383369980$.

    \n\n

    Find $S(10^{18}, 10^{18})$. Give your answer modulo $1\\,405\\,695\\,061$.

    ", "url": "https://projecteuler.net/problem=844", "answer": "101805206"} {"id": 845, "problem": "Let $D(n)$ be the $n$-th positive integer that has the sum of its digits a prime.\n\nFor example, $D(61) = 157$ and $D(10^8) = 403539364$.\n\nFind $D(10^{16})$.", "raw_html": "

    \nLet $D(n)$ be the $n$-th positive integer that has the sum of its digits a prime.
    \nFor example, $D(61) = 157$ and $D(10^8) = 403539364$.

    \n\n

    \nFind $D(10^{16})$.

    ", "url": "https://projecteuler.net/problem=845", "answer": "45009328011709400"} {"id": 846, "problem": "A bracelet is made by connecting at least three numbered beads in a circle. Each bead can only display $1$, $2$, or any number of the form $p^k$ or $2p^k$ for odd prime $p$.\n\nIn addition a magic bracelet must satisfy the following two conditions:\n\n- no two beads display the same number\n\n- the product of the numbers of any two adjacent beads is of the form $x^2+1$\n\nDefine the potency of a magic bracelet to be the sum of numbers on its beads.\n\nThe example is a magic bracelet with five beads which has a potency of 155.\n\nLet $F(N)$ be the sum of the potency of each magic bracelet which can be formed using positive integers not exceeding $N$, where rotations and reflections of an arrangement are considered equivalent. You are given $F(20)=258$ and $F(10^2)=538768$.\n\nFind $F(10^6)$.", "raw_html": "

    \nA bracelet is made by connecting at least three numbered beads in a circle. Each bead can only display $1$, $2$, or any number of the form $p^k$ or $2p^k$ for odd prime $p$.

    \n\n

    \nIn addition a magic bracelet must satisfy the following two conditions:

    \n
      \n
    • no two beads display the same number
    • \n
    • the product of the numbers of any two adjacent beads is of the form $x^2+1$
    • \n
    \n\n
    \n\"0846_diagram.jpg\"\n
    \n\n

    \nDefine the potency of a magic bracelet to be the sum of numbers on its beads.

    \n

    \nThe example is a magic bracelet with five beads which has a potency of 155.

    \n\n

    \nLet $F(N)$ be the sum of the potency of each magic bracelet which can be formed using positive integers not exceeding $N$, where rotations and reflections of an arrangement are considered equivalent. You are given $F(20)=258$ and $F(10^2)=538768$.

    \n\n

    \nFind $F(10^6)$.

    ", "url": "https://projecteuler.net/problem=846", "answer": "9851175623"} {"id": 847, "problem": "Jack has three plates in front of him. The giant has $N$ beans that he distributes to the three plates. All the beans look the same, but one of them is a magic bean. Jack doesn't know which one it is, but the giant knows.\n\nJack can ask the giant questions of the form: \"Does this subset of the beans contain the magic bean?\" In each question Jack may choose any subset of beans from a single plate, and the giant will respond truthfully.\n\nIf the three plates contain $a$, $b$ and $c$ beans respectively, we let $h(a, b, c)$ be the minimal number of questions Jack needs to ask in order to guarantee he locates the magic bean. For example, $h(1, 2, 3) = 3$ and $h(2, 3, 3) = 4$.\n\nLet $H(N)$ be the sum of $h(a, b, c)$ over all triples of non-negative integers $a$, $b$, $c$ with $1 \\leq a + b + c \\leq N$.\n\nYou are given: $H(6) = 203$ and $H(20) = 7718$.\n\nA repunit, $R_n$, is a number made up with $n$ digits all '1'. For example, $R_3 = 111$ and $H(R_3) = 1634144$.\n\nFind $H(R_{19})$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nJack has three plates in front of him. The giant has $N$ beans that he distributes to the three plates. All the beans look the same, but one of them is a magic bean. Jack doesn't know which one it is, but the giant knows.

    \n\n

    \nJack can ask the giant questions of the form: \"Does this subset of the beans contain the magic bean?\" In each question Jack may choose any subset of beans from a single plate, and the giant will respond truthfully.

    \n\n

    \nIf the three plates contain $a$, $b$ and $c$ beans respectively, we let $h(a, b, c)$ be the minimal number of questions Jack needs to ask in order to guarantee he locates the magic bean. For example, $h(1, 2, 3) = 3$ and $h(2, 3, 3) = 4$.

    \n\n

    \nLet $H(N)$ be the sum of $h(a, b, c)$ over all triples of non-negative integers $a$, $b$, $c$ with $1 \\leq a + b + c \\leq N$.
    \nYou are given: $H(6) = 203$ and $H(20) = 7718$.

    \n\n

    \nA repunit, $R_n$, is a number made up with $n$ digits all '1'. For example, $R_3 = 111$ and $H(R_3) = 1634144$.

    \n\n

    \nFind $H(R_{19})$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=847", "answer": "381868244"} {"id": 848, "problem": "Two players play a game. At the start of the game each player secretly chooses an integer; the first player from $1,...,n$ and the second player from $1,...,m$. Then they take alternate turns, starting with the first player. The player, whose turn it is, displays a set of numbers and the other player tells whether their secret number is in the set or not. The player to correctly guess a set with a single number is the winner and the game ends.\n\nLet $p(m,n)$ be the winning probability of the first player assuming both players play optimally. For example $p(1, n) = 1$ and $p(m, 1) = 1/m$.\n\nYou are also given $p(7,5) \\approx 0.51428571$.\n\nFind $\\displaystyle \\sum_{i=0}^{20}\\sum_{j=0}^{20} p(7^i, 5^j)$ and give your answer rounded to 8 digits after the decimal point.", "raw_html": "

    Two players play a game. At the start of the game each player secretly chooses an integer; the first player from $1,...,n$ and the second player from $1,...,m$. Then they take alternate turns, starting with the first player. The player, whose turn it is, displays a set of numbers and the other player tells whether their secret number is in the set or not. The player to correctly guess a set with a single number is the winner and the game ends.

    \n\n

    Let $p(m,n)$ be the winning probability of the first player assuming both players play optimally. For example $p(1, n) = 1$ and $p(m, 1) = 1/m$.

    \n\n

    You are also given $p(7,5) \\approx 0.51428571$.

    \n\n

    Find $\\displaystyle \\sum_{i=0}^{20}\\sum_{j=0}^{20} p(7^i, 5^j)$ and give your answer rounded to 8 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=848", "answer": "188.45503259"} {"id": 849, "problem": "In a tournament there are $n$ teams and each team plays each other team twice. A team gets two points for a win, one point for a draw and no points for a loss.\n\nWith two teams there are three possible outcomes for the total points. $(4,0)$ where a team wins twice, $(3,1)$ where a team wins and draws, and $(2,2)$ where either there are two draws or a team wins one game and loses the other. Here we do not distinguish the teams and so $(3,1)$ and $(1,3)$ are considered identical.\n\nLet $F(n)$ be the total number of possible final outcomes with $n$ teams, so that $F(2) = 3$.\n\nYou are also given $F(7) = 32923$.\n\nFind $F(100)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nIn a tournament there are $n$ teams and each team plays each other team twice. A team gets two points for a win, one point for a draw and no points for a loss.

    \n\n

    \nWith two teams there are three possible outcomes for the total points. $(4,0)$ where a team wins twice, $(3,1)$ where a team wins and draws, and $(2,2)$ where either there are two draws or a team wins one game and loses the other. Here we do not distinguish the teams and so $(3,1)$ and $(1,3)$ are considered identical.

    \n\n

    \nLet $F(n)$ be the total number of possible final outcomes with $n$ teams, so that $F(2) = 3$.
    \nYou are also given $F(7) = 32923$.

    \n

    \nFind $F(100)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=849", "answer": "936203459"} {"id": 850, "problem": "Any positive real number $x$ can be decomposed into integer and fractional parts $\\lfloor x \\rfloor + \\{x\\}$, where $\\lfloor x \\rfloor$ (the floor function) is an integer, and $0\\le \\{x\\} < 1$.\n\nFor positive integers $k$ and $n$, define the function\n$$\\begin{align}\nf_k(n) = \\sum_{i=1}^{n}\\left\\{ \\frac{i^k}{n} \\right\\}\n\\end{align}$$\nFor example, $f_5(10)=4.5$ and $f_7(1234)=616.5$.\n\nLet\n$$\\begin{align}\nS(N) = \\sum_{\\substack{k=1 \\\\ k\\text{ odd}}}^{N} \\sum_{n=1}^{N} f_k(n)\n\\end{align}$$\nYou are given that $S(10)=100.5$ and $S(10^3)=123687804$.\n\nFind $\\lfloor S(33557799775533) \\rfloor$. Give your answer modulo 977676779.", "raw_html": "

    Any positive real number $x$ can be decomposed into integer and fractional parts $\\lfloor x \\rfloor + \\{x\\}$, where $\\lfloor x \\rfloor$ (the floor function) is an integer, and $0\\le \\{x\\} < 1$.

    \n\n

    For positive integers $k$ and $n$, define the function\n$$\\begin{align}\nf_k(n) = \\sum_{i=1}^{n}\\left\\{ \\frac{i^k}{n} \\right\\}\n\\end{align}$$\nFor example, $f_5(10)=4.5$ and $f_7(1234)=616.5$.

    \n\n

    Let\n$$\\begin{align}\nS(N) = \\sum_{\\substack{k=1 \\\\ k\\text{ odd}}}^{N} \\sum_{n=1}^{N} f_k(n)\n\\end{align}$$\nYou are given that $S(10)=100.5$ and $S(10^3)=123687804$.

    \n\n

    Find $\\lfloor S(33557799775533) \\rfloor$. Give your answer modulo 977676779.

    ", "url": "https://projecteuler.net/problem=850", "answer": "878255725"} {"id": 851, "problem": "Let $n$ be a positive integer and let $E_n$ be the set of $n$-tuples of strictly positive integers.\n\nFor $u = (u_1, \\cdots, u_n)$ and $v = (v_1, \\cdots, v_n)$ two elements of $E_n$, we define:\n\n- the Sum Of Products of $u$ and $v$, denoted by $\\langle u, v\\rangle$, as the sum $\\displaystyle\\sum_{i = 1}^n u_i v_i$;\n\n- the Product Of Sums of $u$ and $v$, denoted by $u \\star v$, as the product $\\displaystyle\\prod_{i = 1}^n (u_i + v_i)$.\n\nLet $R_n(M)$ be the sum of $u \\star v$ over all ordered pairs $(u, v)$ in $E_n$ such that $\\langle u, v\\rangle = M$.\n\nFor example: $R_1(10) = 36$, $R_2(100) = 1873044$, $R_2(100!) \\equiv 446575636 \\bmod 10^9 + 7$.\n\nFind $R_6(10000!)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nLet $n$ be a positive integer and let $E_n$ be the set of $n$-tuples of strictly positive integers.

    \n\n

    \nFor $u = (u_1, \\cdots, u_n)$ and $v = (v_1, \\cdots, v_n)$ two elements of $E_n$, we define:

    \n\n
      \n
    • the Sum Of Products of $u$ and $v$, denoted by $\\langle u, v\\rangle$, as the sum $\\displaystyle\\sum_{i = 1}^n u_i v_i$;
    • \n
    • the Product Of Sums of $u$ and $v$, denoted by $u \\star v$, as the product $\\displaystyle\\prod_{i = 1}^n (u_i + v_i)$.
    \n\n

    \nLet $R_n(M)$ be the sum of $u \\star v$ over all ordered pairs $(u, v)$ in $E_n$ such that $\\langle u, v\\rangle = M$.
    \nFor example: $R_1(10) = 36$, $R_2(100) = 1873044$, $R_2(100!) \\equiv 446575636 \\bmod 10^9 + 7$.

    \n\n

    \nFind $R_6(10000!)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=851", "answer": "726358482"} {"id": 852, "problem": "This game has a box of $N$ unfair coins and $N$ fair coins. Fair coins have probability 50% of landing heads while unfair coins have probability 75% of landing heads.\n\nThe player begins with a score of 0 which may become negative during play.\n\nAt each round the player randomly picks a coin from the box and guesses its type: fair or unfair. Before guessing they may toss the coin any number of times; however, each toss subtracts 1 from their score. The decision to stop tossing and make a guess can be made at any time. After guessing the player's score is increased by 20 if they are right and decreased by 50 if they are wrong. Then the coin type is revealed to the player and the coin is discarded.\n\nAfter $2N$ rounds the box will be empty and the game is over. Let $S(N)$ be the expected score of the player at the end of the game assuming that they play optimally in order to maximize their expected score.\n\nYou are given $S(1) = 20.558591$ rounded to 6 digits after the decimal point.\n\nFind $S(50)$. Give your answer rounded to 6 digits after the decimal point.", "raw_html": "

    This game has a box of $N$ unfair coins and $N$ fair coins. Fair coins have probability 50% of landing heads while unfair coins have probability 75% of landing heads.

    \n\n

    The player begins with a score of 0 which may become negative during play.

    \n\n

    At each round the player randomly picks a coin from the box and guesses its type: fair or unfair. Before guessing they may toss the coin any number of times; however, each toss subtracts 1 from their score. The decision to stop tossing and make a guess can be made at any time. After guessing the player's score is increased by 20 if they are right and decreased by 50 if they are wrong. Then the coin type is revealed to the player and the coin is discarded.

    \n\n

    After $2N$ rounds the box will be empty and the game is over. Let $S(N)$ be the expected score of the player at the end of the game assuming that they play optimally in order to maximize their expected score.

    \n\n

    You are given $S(1) = 20.558591$ rounded to 6 digits after the decimal point.

    \n\n

    Find $S(50)$. Give your answer rounded to 6 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=852", "answer": "130.313496"} {"id": 853, "problem": "For every positive integer $n$ the Fibonacci sequence modulo\n$n$ is periodic. The period depends on the value of $n$.\nThis period is called the Pisano period for $n$, often shortened to $\\pi(n)$.\n\nThere are three values of $n$ for which\n$\\pi(n)$ equals $18$: $19$, $38$ and $76$. The sum of those smaller than $50$ is $57$.\n\nFind the sum of the values of $n$ smaller than $1\\,000\\,000\\,000$ for which $\\pi(n)$ equals $120$.", "raw_html": "

    \nFor every positive integer $n$ the Fibonacci sequence modulo \n$n$ is periodic. The period depends on the value of $n$.\nThis period is called the Pisano period for $n$, often shortened to $\\pi(n)$.

    \n

    \nThere are three values of $n$ for which \n$\\pi(n)$ equals $18$: $19$, $38$ and $76$. The sum of those smaller than $50$ is $57$.\n

    \n

    \nFind the sum of the values of $n$ smaller than $1\\,000\\,000\\,000$ for which $\\pi(n)$ equals $120$.\n

    ", "url": "https://projecteuler.net/problem=853", "answer": "44511058204"} {"id": 854, "problem": "For every positive integer $n$ the Fibonacci sequence modulo $n$ is periodic. The period depends on the value of $n$.\nThis period is called the Pisano period for $n$, often shortened to $\\pi(n)$.\n\nDefine $M(p)$ as the largest integer $n$ such that $\\pi(n) = p$, and define $M(p) = 1$ if there is no such $n$.\n\nFor example, there are three values of $n$ for which $\\pi(n)$ equals $18$: $19, 38, 76$. Therefore $M(18) = 76$.\n\nLet the product function $P(n)$ be: $$P(n)=\\prod_{p = 1}^{n}M(p).$$\nYou are given: $P(10)=264$.\n\nFind $P(1\\,000\\,000)\\bmod 1\\,234\\,567\\,891$.", "raw_html": "

    \nFor every positive integer $n$ the Fibonacci sequence modulo $n$ is periodic. The period depends on the value of $n$.\nThis period is called the Pisano period for $n$, often shortened to $\\pi(n)$.

    \n\n

    \nDefine $M(p)$ as the largest integer $n$ such that $\\pi(n) = p$, and define $M(p) = 1$ if there is no such $n$.
    \nFor example, there are three values of $n$ for which $\\pi(n)$ equals $18$: $19, 38, 76$. Therefore $M(18) = 76$.

    \n\n

    \nLet the product function $P(n)$ be: $$P(n)=\\prod_{p = 1}^{n}M(p).$$\nYou are given: $P(10)=264$.

    \n\n

    \nFind $P(1\\,000\\,000)\\bmod 1\\,234\\,567\\,891$.

    ", "url": "https://projecteuler.net/problem=854", "answer": "29894398"} {"id": 855, "problem": "Given two positive integers $a,b$, Alex and Bianca play a game in $ab$ rounds. They begin with a square piece of paper of side length $1$.\n\nIn each round Alex divides the current rectangular piece of paper into $a \\times b$ pieces using $a-1$ horizontal cuts and $b-1$ vertical ones. The cuts do not need to be evenly spaced. Moreover, a piece can have zero width/height when a cut coincides with another cut or the edge of the paper. The pieces are then numbered $1, 2, ..., ab$ starting from the left top corner, moving from left to right and starting from the left of the next row when a row is finished.\n\nThen Bianca chooses one of the pieces for the game to continue on. However, Bianca must not choose a piece with a number she has already chosen during the game.\n\nBianca wants to minimize the area of the final piece of paper while Alex wants to maximize it. Let $S(a,b)$ be the area of the final piece assuming optimal play.\n\nFor example, $S(2,2) = 1/36$ and $S(2, 3) = 1/1800 \\approx 5.5555555556\\mathrm {e}{-4}$.\n\nFind $S(5,8)$. Give your answer in scientific notation rounded to ten significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.", "raw_html": "

    Given two positive integers $a,b$, Alex and Bianca play a game in $ab$ rounds. They begin with a square piece of paper of side length $1$.

    \n\n

    In each round Alex divides the current rectangular piece of paper into $a \\times b$ pieces using $a-1$ horizontal cuts and $b-1$ vertical ones. The cuts do not need to be evenly spaced. Moreover, a piece can have zero width/height when a cut coincides with another cut or the edge of the paper. The pieces are then numbered $1, 2, ..., ab$ starting from the left top corner, moving from left to right and starting from the left of the next row when a row is finished.

    \n\n

    Then Bianca chooses one of the pieces for the game to continue on. However, Bianca must not choose a piece with a number she has already chosen during the game.

    \n\n

    Bianca wants to minimize the area of the final piece of paper while Alex wants to maximize it. Let $S(a,b)$ be the area of the final piece assuming optimal play.

    \n\n

    For example, $S(2,2) = 1/36$ and $S(2, 3) = 1/1800 \\approx 5.5555555556\\mathrm {e}{-4}$.

    \n\n

    Find $S(5,8)$. Give your answer in scientific notation rounded to ten significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.

    ", "url": "https://projecteuler.net/problem=855", "answer": "6.8827571976e-57"} {"id": 856, "problem": "A standard 52-card deck comprises 13 ranks in four suits. A pair is a set of two cards of the same rank.\n\nCards are drawn, without replacement, from a well shuffled 52-card deck waiting for consecutive cards that form a pair. For example, the probability of finding a pair in the first two draws is $\\frac{1}{17}$.\n\nCards are drawn until either such a pair is found or the pack is exhausted waiting for one. In the latter case we say that all 52 cards were drawn.\n\nFind the expected number of cards that were drawn. Give your answer rounded to eight places after the decimal point.", "raw_html": "

    A standard 52-card deck comprises 13 ranks in four suits. A pair is a set of two cards of the same rank.

    \n\n

    Cards are drawn, without replacement, from a well shuffled 52-card deck waiting for consecutive cards that form a pair. For example, the probability of finding a pair in the first two draws is $\\frac{1}{17}$.

    \n\n

    Cards are drawn until either such a pair is found or the pack is exhausted waiting for one. In the latter case we say that all 52 cards were drawn.

    \n\n

    Find the expected number of cards that were drawn. Give your answer rounded to eight places after the decimal point.

    ", "url": "https://projecteuler.net/problem=856", "answer": "17.09661501"} {"id": 857, "problem": "A graph is made up of vertices and coloured edges.\nBetween every two distinct vertices there must be exactly one of the following:\n\n- A red directed edge one way, and a blue directed edge the other way\n\n- A green undirected edge\n\n- A brown undirected edge\n\nSuch a graph is called beautiful if\n\n- A cycle of edges contains a red edge if and only if it also contains a blue edge\n\n- No triangle of edges is made up of entirely green or entirely brown edges\n\nBelow are four distinct examples of beautiful graphs on three vertices:\n\nBelow are four examples of graphs that are not beautiful:\n\nLet $G(n)$ be the number of beautiful graphs on the labelled vertices: $1,2,\\ldots,n$.\nYou are given $G(3)=24$, $G(4)=186$ and $G(15)=12472315010483328$.\n\nFind $G(10^7)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nA graph is made up of vertices and coloured edges. \nBetween every two distinct vertices there must be exactly one of the following:

    \n\n
      \n
    • A red directed edge one way, and a blue directed edge the other way
    • \n
    • A green undirected edge
    • \n
    • A brown undirected edge
    • \n
    \n\nSuch a graph is called beautiful if \n\n
      \n
    • A cycle of edges contains a red edge if and only if it also contains a blue edge
    • \n
    • No triangle of edges is made up of entirely green or entirely brown edges
    • \n
    \n\n

    \nBelow are four distinct examples of beautiful graphs on three vertices:\n

    \n\"0857_GoodGraphs.jpg\"\n\n

    \nBelow are four examples of graphs that are not beautiful:

    \n\"0857_BadGraphs.jpg\"\n\n

    \nLet $G(n)$ be the number of beautiful graphs on the labelled vertices: $1,2,\\ldots,n$.\nYou are given $G(3)=24$, $G(4)=186$ and $G(15)=12472315010483328$.

    \n\n

    \nFind $G(10^7)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=857", "answer": "966332096"} {"id": 858, "problem": "Define $G(N) = \\sum_S \\operatorname{lcm}(S)$ where $S$ ranges through all subsets of $\\{1, \\dots, N\\}$ and $\\operatorname{lcm}$ denotes the lowest common multiple. Note that the $\\operatorname{lcm}$ of the empty set is $1$.\n\nYou are given $G(5) = 528$ and $G(20) = 8463108648960$.\n\nFind $G(800)$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    \nDefine $G(N) = \\sum_S \\operatorname{lcm}(S)$ where $S$ ranges through all subsets of $\\{1, \\dots, N\\}$ and $\\operatorname{lcm}$ denotes the lowest common multiple. Note that the $\\operatorname{lcm}$ of the empty set is $1$.

    \n\n

    \nYou are given $G(5) = 528$ and $G(20) = 8463108648960$.

    \n\n

    \nFind $G(800)$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=858", "answer": "973077199"} {"id": 859, "problem": "Odd and Even are playing a game with $N$ cookies.\n\nThe game begins with the $N$ cookies divided into one or more piles, not necessarily of the same size. They then make moves in turn, starting with Odd.\n\nOdd's turn: Odd may choose any pile with an odd number of cookies, eat one and divide the remaining (if any) into two equal piles.\n\nEven's turn: Even may choose any pile with an even number of cookies, eat two of them and divide the remaining (if any) into two equal piles.\n\nThe player that does not have a valid move loses the game.\n\nLet $C(N)$ be the number of ways that $N$ cookies can be divided so that Even has a winning strategy.\n\nFor example, $C(5) = 2$ because there are two winning configurations for Even: a single pile containing all five cookies; three piles containing one, two and two cookies.\n\nYou are also given $C(16) = 64$.\n\nFind $C(300)$.", "raw_html": "

    \nOdd and Even are playing a game with $N$ cookies.

    \n\n

    \nThe game begins with the $N$ cookies divided into one or more piles, not necessarily of the same size. They then make moves in turn, starting with Odd.
    \nOdd's turn: Odd may choose any pile with an odd number of cookies, eat one and divide the remaining (if any) into two equal piles.
    \nEven's turn: Even may choose any pile with an even number of cookies, eat two of them and divide the remaining (if any) into two equal piles.
    \nThe player that does not have a valid move loses the game.

    \n\n

    \nLet $C(N)$ be the number of ways that $N$ cookies can be divided so that Even has a winning strategy.
    \nFor example, $C(5) = 2$ because there are two winning configurations for Even: a single pile containing all five cookies; three piles containing one, two and two cookies.
    \nYou are also given $C(16) = 64$.

    \n\n

    \nFind $C(300)$.

    ", "url": "https://projecteuler.net/problem=859", "answer": "1527162658488196"} {"id": 860, "problem": "Gary and Sally play a game using gold and silver coins arranged into a number of vertical stacks, alternating turns. On Gary's turn he chooses a gold coin and removes it from the game along with any other coins sitting on top. Sally does the same on her turn by removing a silver coin. The first player unable to make a move loses.\n\nAn arrangement is called fair if the person moving first, whether it be Gary or Sally, will lose the game if both play optimally.\n\nDefine $F(n)$ to be the number of fair arrangements of $n$ stacks, all of size $2$. Different orderings of the stacks are to be counted separately, so $F(2) = 4$ due to the following four arrangements:\n\nYou are also given $F(10) = 63594$.\n\nFind $F(9898)$. Give your answer modulo $989898989$", "raw_html": "

    \nGary and Sally play a game using gold and silver coins arranged into a number of vertical stacks, alternating turns. On Gary's turn he chooses a gold coin and removes it from the game along with any other coins sitting on top. Sally does the same on her turn by removing a silver coin. The first player unable to make a move loses.

    \n\n

    \nAn arrangement is called fair if the person moving first, whether it be Gary or Sally, will lose the game if both play optimally.

    \n\n

    \nDefine $F(n)$ to be the number of fair arrangements of $n$ stacks, all of size $2$. Different orderings of the stacks are to be counted separately, so $F(2) = 4$ due to the following four arrangements:

    \n\n
    \n\"0860_diag3.jpg\"\n
    \n\n

    \nYou are also given $F(10) = 63594$.

    \n\n

    \nFind $F(9898)$. Give your answer modulo $989898989$

    ", "url": "https://projecteuler.net/problem=860", "answer": "958666903"} {"id": 861, "problem": "A unitary divisor of a positive integer $n$ is a divisor $d$ of $n$ such that $\\gcd\\left(d,\\frac{n}{d}\\right)=1$.\n\nA bi-unitary divisor of $n$ is a divisor $d$ for which $1$ is the only unitary divisor of $d$ that is also a unitary divisor of $\\frac{n}{d}$.\n\nFor example, $2$ is a bi-unitary divisor of $8$, because the unitary divisors of $2$ are $\\{1,2\\}$, and the unitary divisors of $8/2$ are $\\{1,4\\}$, with $1$ being the only unitary divisor in common.\n\nThe bi-unitary divisors of $240$ are $\\{1,2,3,5,6,8,10,15,16,24,30,40,48,80,120,240\\}$.\n\nLet $P(n)$ be the product of all bi-unitary divisors of $n$. Define $Q_k(N)$ as the number of positive integers $1 \\lt n \\leq N$ such that $P(n)=n^k$. For example, $Q_2\\left(10^2\\right)=51$ and $Q_6\\left(10^6\\right)=6189$.\n\nFind $\\sum_{k=2}^{10}Q_k\\left(10^{12}\\right)$.", "raw_html": "

    A unitary divisor of a positive integer $n$ is a divisor $d$ of $n$ such that $\\gcd\\left(d,\\frac{n}{d}\\right)=1$.

    \n\n

    A bi-unitary divisor of $n$ is a divisor $d$ for which $1$ is the only unitary divisor of $d$ that is also a unitary divisor of $\\frac{n}{d}$.

    \n\n

    For example, $2$ is a bi-unitary divisor of $8$, because the unitary divisors of $2$ are $\\{1,2\\}$, and the unitary divisors of $8/2$ are $\\{1,4\\}$, with $1$ being the only unitary divisor in common.

    \n\n

    The bi-unitary divisors of $240$ are $\\{1,2,3,5,6,8,10,15,16,24,30,40,48,80,120,240\\}$.

    \n\n

    Let $P(n)$ be the product of all bi-unitary divisors of $n$. Define $Q_k(N)$ as the number of positive integers $1 \\lt n \\leq N$ such that $P(n)=n^k$. For example, $Q_2\\left(10^2\\right)=51$ and $Q_6\\left(10^6\\right)=6189$.

    \n\n

    Find $\\sum_{k=2}^{10}Q_k\\left(10^{12}\\right)$.

    ", "url": "https://projecteuler.net/problem=861", "answer": "672623540591"} {"id": 862, "problem": "For a positive integer $n$ define $T(n)$ to be the number of strictly larger integers which can be formed by permuting the digits of $n$.\n\nLeading zeros are not allowed and so for $n = 2302$ the total list of permutations would be:\n\n$2023,2032,2203,2230,\\mathbf{2302},2320,3022,32 02,3220$\n\ngiving $T(2302)=4$.\n\nFurther define $S(k)$ to be the sum of $T(n)$ for all $k$-digit numbers $n$. You are given $S(3) = 1701$.\n\nFind $S(12)$.", "raw_html": "

    \nFor a positive integer $n$ define $T(n)$ to be the number of strictly larger integers which can be formed by permuting the digits of $n$.

    \n\n

    \nLeading zeros are not allowed and so for $n = 2302$ the total list of permutations would be:

    \n
    \n$2023,2032,2203,2230,\\mathbf{2302},2320,3022,32 02,3220$
    \n

    \ngiving $T(2302)=4$.

    \n\n

    \nFurther define $S(k)$ to be the sum of $T(n)$ for all $k$-digit numbers $n$. You are given $S(3) = 1701$.

    \n\n

    \nFind $S(12)$.

    ", "url": "https://projecteuler.net/problem=862", "answer": "6111397420935766740"} {"id": 863, "problem": "Using only a six-sided fair dice and a five-sided fair dice, we would like to emulate an $n$-sided fair dice.\n\nFor example, one way to emulate a 28-sided dice is to follow this procedure:\n\n- Roll both dice, obtaining integers $1\\le p\\le 6$ and $1\\le q\\le 5$.\n\n- Combine them using $r = 5(p-1) + q$ to obtain an integer $1\\le r\\le 30$.\n\n- If $r\\le 28$, return the value $r$ and stop.\n\n- Otherwise ($r$ being 29 or 30), roll both dice again, obtaining integers $1\\le s\\le 6$ and $1\\le t\\le 5$.\n\n- Compute $u = 30(r-29) + 5(s-1) + t$ to obtain an integer $1\\le u\\le 60$.\n\n- If $u>4$, return the value $((u-5)\\bmod 28) + 1$ and stop.\n\n- Otherwise (with $1\\le u\\le 4$), roll the six-sided dice twice, obtaining integers $1\\le v\\le 6$ and $1\\le w\\le 6$.\n\n- Compute $x = 36(u-1) + 6(v-1) + w$ to obtain an integer $1\\le x\\le 144$.\n\n- If $x>4$, return the value $((x-5)\\bmod 28) + 1$ and stop.\n\n- Otherwise (with $1\\le x\\le 4$), assign $u:=x$ and go back to step 7.\n\nThe expected number of dice rolls in following this procedure is 2.142476 (rounded to 6 decimal places). Note that rolling both dice at the same time is still counted as two dice rolls.\n\nThere exist other more complex procedures for emulating a 28-sided dice that entail a smaller average number of dice rolls. However, the above procedure has the attractive property that the sequence of dice rolled is predetermined: regardless of the outcome, it follows (D5,D6,D5,D6,D6,D6,D6,...), truncated wherever the process stops. In fact, amongst procedures for $n=28$ with this restriction, this one is optimal in the sense of minimising the expected number of rolls needed.\n\nDifferent values of $n$ will in general use different predetermined sequences. For example, for $n=8$, the sequence (D5,D5,D5,...) gives an optimal procedure, taking 2.083333... dice rolls on average.\n\nDefine $R(n)$ to be the expected number of dice rolls for an optimal procedure for emulating an $n$-sided dice using only a five-sided and a six-sided dice, considering only those procedures where the sequence of dice rolled is predetermined. So, $R(8) \\approx 2.083333$ and $R(28) \\approx 2.142476$.\n\nLet $S(n) = \\displaystyle\\sum_{k=2}^n R(k)$. You are given that $S(30) \\approx 56.054622$.\n\nFind $S(1000)$. Give your answer rounded to 6 decimal places.", "raw_html": "

    Using only a six-sided fair dice and a five-sided fair dice, we would like to emulate an $n$-sided fair dice.

    \n

    For example, one way to emulate a 28-sided dice is to follow this procedure:

    \n
      \n
    1. Roll both dice, obtaining integers $1\\le p\\le 6$ and $1\\le q\\le 5$.
    2. \n
    3. Combine them using $r = 5(p-1) + q$ to obtain an integer $1\\le r\\le 30$.
    4. \n
    5. If $r\\le 28$, return the value $r$ and stop.
    6. \n
    7. Otherwise ($r$ being 29 or 30), roll both dice again, obtaining integers $1\\le s\\le 6$ and $1\\le t\\le 5$.
    8. \n
    9. Compute $u = 30(r-29) + 5(s-1) + t$ to obtain an integer $1\\le u\\le 60$.
    10. \n
    11. If $u>4$, return the value $((u-5)\\bmod 28) + 1$ and stop.
    12. \n
    13. Otherwise (with $1\\le u\\le 4$), roll the six-sided dice twice, obtaining integers $1\\le v\\le 6$ and $1\\le w\\le 6$.
    14. \n
    15. Compute $x = 36(u-1) + 6(v-1) + w$ to obtain an integer $1\\le x\\le 144$.
    16. \n
    17. If $x>4$, return the value $((x-5)\\bmod 28) + 1$ and stop.
    18. \n
    19. Otherwise (with $1\\le x\\le 4$), assign $u:=x$ and go back to step 7.
    20. \n
    \n\n

    The expected number of dice rolls in following this procedure is 2.142476 (rounded to 6 decimal places). Note that rolling both dice at the same time is still counted as two dice rolls.

    \n\n

    There exist other more complex procedures for emulating a 28-sided dice that entail a smaller average number of dice rolls. However, the above procedure has the attractive property that the sequence of dice rolled is predetermined: regardless of the outcome, it follows (D5,D6,D5,D6,D6,D6,D6,...), truncated wherever the process stops. In fact, amongst procedures for $n=28$ with this restriction, this one is optimal in the sense of minimising the expected number of rolls needed.

    \n\n

    Different values of $n$ will in general use different predetermined sequences. For example, for $n=8$, the sequence (D5,D5,D5,...) gives an optimal procedure, taking 2.083333... dice rolls on average.

    \n\n

    Define $R(n)$ to be the expected number of dice rolls for an optimal procedure for emulating an $n$-sided dice using only a five-sided and a six-sided dice, considering only those procedures where the sequence of dice rolled is predetermined. So, $R(8) \\approx 2.083333$ and $R(28) \\approx 2.142476$.

    \n\n

    Let $S(n) = \\displaystyle\\sum_{k=2}^n R(k)$. You are given that $S(30) \\approx 56.054622$.

    \n\n

    Find $S(1000)$. Give your answer rounded to 6 decimal places.

    ", "url": "https://projecteuler.net/problem=863", "answer": "3862.871397"} {"id": 864, "problem": "Let $C(n)$ be the number of squarefree integers of the form $x^2 + 1$ such that $1 \\le x \\le n$.\n\nFor example, $C(10) = 9$ and $C(1000) = 895$.\n\nFind $C(123567101113)$.", "raw_html": "

    Let $C(n)$ be the number of squarefree integers of the form $x^2 + 1$ such that $1 \\le x \\le n$.

    \n\n

    For example, $C(10) = 9$ and $C(1000) = 895$.

    \n\n

    Find $C(123567101113)$.

    ", "url": "https://projecteuler.net/problem=864", "answer": "110572936177"} {"id": 865, "problem": "A triplicate number is a positive integer such that, after repeatedly removing three consecutive identical digits from it, all its digits can be removed.\n\nFor example, the integer $122555211$ is a triplicate number:\n$$122{\\color{red}555}211 \\rightarrow 1{\\color{red}222}11\\rightarrow{\\color{red}111}\\rightarrow.$$\nOn the other hand, neither $663633$ nor $9990$ are triplicate numbers.\n\nLet $T(n)$ be how many triplicate numbers are less than $10^n$.\n\nFor example, $T(6) = 261$ and $T(30) = 5576195181577716$.\n\nFind $T(10^4)$. Give your answer modulo $998244353$.", "raw_html": "

    \nA triplicate number is a positive integer such that, after repeatedly removing three consecutive identical digits from it, all its digits can be removed.

    \n\n

    \nFor example, the integer $122555211$ is a triplicate number:\n$$122{\\color{red}555}211 \\rightarrow 1{\\color{red}222}11\\rightarrow{\\color{red}111}\\rightarrow.$$\nOn the other hand, neither $663633$ nor $9990$ are triplicate numbers.

    \n\n

    \nLet $T(n)$ be how many triplicate numbers are less than $10^n$.

    \n\n

    \nFor example, $T(6) = 261$ and $T(30) = 5576195181577716$.

    \n\n

    \nFind $T(10^4)$. Give your answer modulo $998244353$.

    ", "url": "https://projecteuler.net/problem=865", "answer": "761181918"} {"id": 866, "problem": "A small child has a “number caterpillar” consisting of $N$ jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers $1$ to $N$ in order.\n\nEvery night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order.\n\nAs the caterpillar is built up in this way, it forms distinct segments that gradually merge together.\n\nAny time the father places a new piece in its correct position, a segment of length $k$ is formed and he writes down the $k$th hexagonal number $k\\cdot(2k-1)$. Once all pieces have been placed and the full caterpillar constructed he calculates the product of all the numbers written down. Interestingly, the expected value of this product is always an integer. For example if $N=4$ then the expected value is $994$.\n\nFind the expected value of the product for a caterpillar of $N=100$ pieces.\nGive your answer modulo $987654319$.", "raw_html": "

    \nA small child has a “number caterpillar” consisting of $N$ jigsaw pieces, each with one number on it, which, when connected together in a line, reveal the numbers $1$ to $N$ in order.

    \n\n

    \nEvery night, the child's father has to pick up the pieces of the caterpillar that have been scattered across the play room. He picks up the pieces at random and places them in the correct order.
    \nAs the caterpillar is built up in this way, it forms distinct segments that gradually merge together.

    \n\n

    \nAny time the father places a new piece in its correct position, a segment of length $k$ is formed and he writes down the $k$th hexagonal number $k\\cdot(2k-1)$. Once all pieces have been placed and the full caterpillar constructed he calculates the product of all the numbers written down. Interestingly, the expected value of this product is always an integer. For example if $N=4$ then the expected value is $994$.

    \n\n

    \nFind the expected value of the product for a caterpillar of $N=100$ pieces.\nGive your answer modulo $987654319$.

    ", "url": "https://projecteuler.net/problem=866", "answer": "492401720"} {"id": 867, "problem": "There are $5$ ways to tile a regular dodecagon of side $1$ with regular polygons of side $1$.\n\nLet $T(n)$ be the number of ways to tile a regular dodecagon of side $n$ with regular polygons of side $1$. Then $T(1) = 5$. You are also given $T(2) = 48$.\n\nFind $T(10)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nThere are $5$ ways to tile a regular dodecagon of side $1$ with regular polygons of side $1$.

    \n\n\"0867_DodecaDiagram.jpg\"\n\n

    \nLet $T(n)$ be the number of ways to tile a regular dodecagon of side $n$ with regular polygons of side $1$. Then $T(1) = 5$. You are also given $T(2) = 48$.

    \n\n

    \nFind $T(10)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=867", "answer": "870557257"} {"id": 868, "problem": "There is a method that is used by Bell ringers to generate all variations of the order that bells are rung.\n\nThe same method can be used to create all permutations of a set of letters. Consider the letters to be permuted initially in order from smallest to largest. At each step swap the largest letter with the letter on its left or right whichever generates a permutation that has not yet been seen. If neither gives a new permutation then try the next largest letter and so on. This procedure continues until all permutations have been generated.\n\nFor example, $3$ swaps are required to reach the permutation CBA when starting with ABC.\n\nThe swaps are ABC $\\to$ ACB $\\to$ CAB $\\to$ CBA.\n\nAlso $59$ swaps are required to reach BELFRY when starting with these letters in alphabetical order.\n\nFind the number of swaps that are required to reach NOWPICKBELFRYMATHS when starting with these letters in alphabetical order.", "raw_html": "

    \nThere is a method that is used by Bell ringers to generate all variations of the order that bells are rung.

    \n\n

    \nThe same method can be used to create all permutations of a set of letters. Consider the letters to be permuted initially in order from smallest to largest. At each step swap the largest letter with the letter on its left or right whichever generates a permutation that has not yet been seen. If neither gives a new permutation then try the next largest letter and so on. This procedure continues until all permutations have been generated.

    \n\n

    \nFor example, $3$ swaps are required to reach the permutation CBA when starting with ABC.
    \nThe swaps are ABC $\\to$ ACB $\\to$ CAB $\\to$ CBA.
    \nAlso $59$ swaps are required to reach BELFRY when starting with these letters in alphabetical order.

    \n\n

    \nFind the number of swaps that are required to reach NOWPICKBELFRYMATHS when starting with these letters in alphabetical order.

    ", "url": "https://projecteuler.net/problem=868", "answer": "3832914911887589"} {"id": 869, "problem": "A prime is drawn uniformly from all primes not exceeding $N$. The prime is written in binary notation, and a player tries to guess it bit-by-bit starting at the least significant bit. The player scores one point for each bit they guess correctly. Immediately after each guess, the player is informed whether their guess was correct, and also whether it was the last bit in the number - in which case the game is over.\n\nLet $E(N)$ be the expected number of points assuming that the player always guesses to maximize their score. For example, $E(10)=2$, achievable by always guessing \"1\". You are also given $E(30)=2.9$.\n\nFind $E(10^8)$. Give your answer rounded to eight digits after the decimal point.", "raw_html": "

    \nA prime is drawn uniformly from all primes not exceeding $N$. The prime is written in binary notation, and a player tries to guess it bit-by-bit starting at the least significant bit. The player scores one point for each bit they guess correctly. Immediately after each guess, the player is informed whether their guess was correct, and also whether it was the last bit in the number - in which case the game is over.

    \n\n

    \nLet $E(N)$ be the expected number of points assuming that the player always guesses to maximize their score. For example, $E(10)=2$, achievable by always guessing \"1\". You are also given $E(30)=2.9$.

    \n\n

    \nFind $E(10^8)$. Give your answer rounded to eight digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=869", "answer": "14.97696693"} {"id": 870, "problem": "Two players play a game with a single pile of stones of initial size $n$. They take stones from the pile in turn, according to the following rules which depend on a fixed real number $r > 0$:\n\n-\nIn the first turn, the first player may take $k$ stones with $1 \\le k \\lt n$.\n\n-\nIf a player takes $m$ stones in a turn, then in the next turn the opponent may take $k$ stones with $1 \\le k \\le \\lfloor r \\cdot m \\rfloor$.\n\nWhoever cannot make a legal move loses the game.\n\nLet $L(r)$ be the set of initial pile sizes $n$ for which the second player has a winning strategy. For example, $L(0.5) = \\{1\\}$, $L(1) = \\{1, 2, 4, 8, 16, \\dots\\}$, $L(2) = \\{1, 2, 3, 5, 8, \\dots\\}$.\n\nA real number $q \\gt 0$ is a transition value if $L(s)$ is different from $L(t)$ for all $s < q < t$.\n\nLet $T(i)$ be the $i$-th transition value. For example, $T(1) = 1$, $T(2) = 2$, $T(22) \\approx 6.3043478261$.\n\nFind $T(123456)$ and give your answer rounded to $10$ digits after the decimal point.", "raw_html": "

    \nTwo players play a game with a single pile of stones of initial size $n$. They take stones from the pile in turn, according to the following rules which depend on a fixed real number $r > 0$:

    \n\n
      \n
    • \nIn the first turn, the first player may take $k$ stones with $1 \\le k \\lt n$.
    • \n
    • \nIf a player takes $m$ stones in a turn, then in the next turn the opponent may take $k$ stones with $1 \\le k \\le \\lfloor r \\cdot m \\rfloor$.
    \n\n

    \nWhoever cannot make a legal move loses the game.

    \n\n

    \nLet $L(r)$ be the set of initial pile sizes $n$ for which the second player has a winning strategy. For example, $L(0.5) = \\{1\\}$, $L(1) = \\{1, 2, 4, 8, 16, \\dots\\}$, $L(2) = \\{1, 2, 3, 5, 8, \\dots\\}$.

    \n\n

    \nA real number $q \\gt 0$ is a transition value if $L(s)$ is different from $L(t)$ for all $s < q < t$.
    \nLet $T(i)$ be the $i$-th transition value. For example, $T(1) = 1$, $T(2) = 2$, $T(22) \\approx 6.3043478261$.

    \n\n

    \nFind $T(123456)$ and give your answer rounded to $10$ digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=870", "answer": "229.9129353234"} {"id": 871, "problem": "Let $f$ be a function from a finite set $S$ to itself. A drifting subset for $f$ is a subset $A$ of $S$ such that the number of elements in the union $A \\cup f(A)$ is equal to twice the number of elements of $A$.\n\nWe write $D(f)$ for the maximal number of elements among all drifting subsets for $f$.\n\nFor a positive integer $n$, define $f_n$ as the function from $\\{0, 1, \\dots, n - 1\\}$ to itself sending $x$ to $x^3 + x + 1 \\bmod n$.\n\nYou are given $D(f_5) = 1$ and $D(f_{10}) = 3$.\n\nFind $\\displaystyle\\sum_{i = 1}^{100} D(f_{10^5 + i})$.", "raw_html": "

    \nLet $f$ be a function from a finite set $S$ to itself. A drifting subset for $f$ is a subset $A$ of $S$ such that the number of elements in the union $A \\cup f(A)$ is equal to twice the number of elements of $A$.
    \nWe write $D(f)$ for the maximal number of elements among all drifting subsets for $f$.

    \n\n

    \nFor a positive integer $n$, define $f_n$ as the function from $\\{0, 1, \\dots, n - 1\\}$ to itself sending $x$ to $x^3 + x + 1 \\bmod n$.
    \nYou are given $D(f_5) = 1$ and $D(f_{10}) = 3$.

    \n\n

    \nFind $\\displaystyle\\sum_{i = 1}^{100} D(f_{10^5 + i})$.

    ", "url": "https://projecteuler.net/problem=871", "answer": "2848790"} {"id": 872, "problem": "A sequence of rooted trees $T_n$ is constructed such that $T_n$ has $n$ nodes numbered $1$ to $n$.\n\nThe sequence starts at $T_1$, a tree with a single node as a root with the number $1$.\n\nFor $n > 1$, $T_n$ is constructed from $T_{n-1}$ using the following procedure:\n\n- Trace a path from the root of $T_{n-1}$ to a leaf by following the largest-numbered child at each node.\n\n- Remove all edges along the traced path, disconnecting all nodes along it from their parents.\n\n- Connect all orphaned nodes directly to a new node numbered $n$, which becomes the root of $T_n$.\n\nFor example, the following figure shows $T_6$ and $T_7$. The path traced through $T_6$ during the construction of $T_7$ is coloured red.\n\nLet $f(n, k)$ be the sum of the node numbers along the path connecting the root of $T_n$ to the node $k$, including the root and the node $k$. For example, $f(6, 1) = 6 + 5 + 1 = 12$ and $f(10, 3) = 29$.\n\nFind $f(10^{17}, 9^{17})$.", "raw_html": "

    A sequence of rooted trees $T_n$ is constructed such that $T_n$ has $n$ nodes numbered $1$ to $n$.

    \n\n

    The sequence starts at $T_1$, a tree with a single node as a root with the number $1$.

    \n\n

    For $n > 1$, $T_n$ is constructed from $T_{n-1}$ using the following procedure:\n

      \n
    1. Trace a path from the root of $T_{n-1}$ to a leaf by following the largest-numbered child at each node.
    2. \n
    3. Remove all edges along the traced path, disconnecting all nodes along it from their parents.
    4. \n
    5. Connect all orphaned nodes directly to a new node numbered $n$, which becomes the root of $T_n$.
    6. \n
    \n\n\n

    For example, the following figure shows $T_6$ and $T_7$. The path traced through $T_6$ during the construction of $T_7$ is coloured red.

    \n
    \n\"0872_tree.png\"
    \n\n\n

    Let $f(n, k)$ be the sum of the node numbers along the path connecting the root of $T_n$ to the node $k$, including the root and the node $k$. For example, $f(6, 1) = 6 + 5 + 1 = 12$ and $f(10, 3) = 29$.

    \n\n

    Find $f(10^{17}, 9^{17})$.

    ", "url": "https://projecteuler.net/problem=872", "answer": "2903144925319290239"} {"id": 873, "problem": "Let $W(p,q,r)$ be the number of words that can be formed using the letter A $p$ times, the letter B $q$ times and the letter C $r$ times with the condition that every A is separated from every B by at least two Cs. For example, CACACCBB is a valid word for $W(2,2,4)$ but ACBCACBC is not.\n\nYou are given $W(2,2,4)=32$ and $W(4,4,44)=13908607644$.\n\nFind $W(10^6,10^7,10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nLet $W(p,q,r)$ be the number of words that can be formed using the letter A $p$ times, the letter B $q$ times and the letter C $r$ times with the condition that every A is separated from every B by at least two Cs. For example, CACACCBB is a valid word for $W(2,2,4)$ but ACBCACBC is not.

    \n\n

    \nYou are given $W(2,2,4)=32$ and $W(4,4,44)=13908607644$.

    \n\n

    \nFind $W(10^6,10^7,10^8)$. Give your answer modulo $1\\,000\\,000\\,007$.

    ", "url": "https://projecteuler.net/problem=873", "answer": "735131856"} {"id": 874, "problem": "Let $p(t)$ denote the $(t+1)$th prime number. So that $p(0) = 2$, $p(1) = 3$, etc.\n\nWe define the prime score of a list of nonnegative integers $[a_1, \\dots, a_n]$ as the sum $\\sum_{i = 1}^n p(a_i)$.\n\nLet $M(k, n)$ be the maximal prime score among all lists $[a_1, \\dots, a_n]$ such that:\n\n- $0 \\leq a_i < k$ for each $i$;\n\n- the sum $\\sum_{i = 1}^n a_i$ is a multiple of $k$.\n\nFor example, $M(2, 5) = 14$ as $[0, 1, 1, 1, 1]$ attains a maximal prime score of $14$.\n\nFind $M(7000, p(7000))$.", "raw_html": "

    \nLet $p(t)$ denote the $(t+1)$th prime number. So that $p(0) = 2$, $p(1) = 3$, etc.
    \nWe define the prime score of a list of nonnegative integers $[a_1, \\dots, a_n]$ as the sum $\\sum_{i = 1}^n p(a_i)$.
    \nLet $M(k, n)$ be the maximal prime score among all lists $[a_1, \\dots, a_n]$ such that:

    \n\n
      \n
    • $0 \\leq a_i < k$ for each $i$;\n
    • the sum $\\sum_{i = 1}^n a_i$ is a multiple of $k$.\n
    \n\n

    \nFor example, $M(2, 5) = 14$ as $[0, 1, 1, 1, 1]$ attains a maximal prime score of $14$.

    \n\n

    \nFind $M(7000, p(7000))$.

    ", "url": "https://projecteuler.net/problem=874", "answer": "4992775389"} {"id": 875, "problem": "For a positive integer $n$ we define $q(n)$ to be the number of solutions to:\n\n$$a_1^2+a_2^2+a_3^2+a_4^2 \\equiv b_1^2+b_2^2+b_3^2+b_4^2 \\pmod n$$\nwhere $0 \\leq a_i, b_i \\lt n$. For example, $q(4)= 18432$.\n\nDefine $\\displaystyle Q(n)=\\sum_{i=1}^{n}q(i)$. You are given $Q(10)=18573381$.\n\nFind $Q(12345678)$. Give your answer modulo $1001961001$.", "raw_html": "

    \nFor a positive integer $n$ we define $q(n)$ to be the number of solutions to:

    \n$$a_1^2+a_2^2+a_3^2+a_4^2 \\equiv b_1^2+b_2^2+b_3^2+b_4^2 \\pmod n$$\n

    where $0 \\leq a_i, b_i \\lt n$. For example, $q(4)= 18432$.

    \n\n

    \nDefine $\\displaystyle Q(n)=\\sum_{i=1}^{n}q(i)$. You are given $Q(10)=18573381$.

    \n\n

    \nFind $Q(12345678)$. Give your answer modulo $1001961001$.

    ", "url": "https://projecteuler.net/problem=875", "answer": "79645946"} {"id": 876, "problem": "Starting with three numbers $a, b, c$, at each step do one of the three operations:\n\n- change $a$ to $2(b + c) - a$;\n\n- change $b$ to $2(c + a) - b$;\n\n- change $c$ to $2(a + b) - c$;\n\nDefine $f(a, b, c)$ to be the minimum number of steps required for one number to become zero. If this is not possible then $f(a, b, c)=0$.\n\nFor example, $f(6,10,35)=3$:\n$$(6,10,35) \\to (6,10,-3) \\to (8,10,-3) \\to (8,0,-3).$$\nHowever, $f(6,10,36)=0$ as no series of operations leads to a zero number.\n\nAlso define $F(a, b)=\\sum_{c=1}^\\infty f(a,b,c)$.\nYou are given $F(6,10)=17$ and $F(36,100)=179$.\n\nFind $\\displaystyle\\sum_{k=1}^{18}F(6^k,10^k)$.", "raw_html": "

    \nStarting with three numbers $a, b, c$, at each step do one of the three operations:

    \n
      \n
    • change $a$ to $2(b + c) - a$;\n
    • change $b$ to $2(c + a) - b$;\n
    • change $c$ to $2(a + b) - c$;\n
    \n\n

    \nDefine $f(a, b, c)$ to be the minimum number of steps required for one number to become zero. If this is not possible then $f(a, b, c)=0$.

    \n\n

    \nFor example, $f(6,10,35)=3$:\n$$(6,10,35) \\to (6,10,-3) \\to (8,10,-3) \\to (8,0,-3).$$\nHowever, $f(6,10,36)=0$ as no series of operations leads to a zero number.

    \n\n

    \nAlso define $F(a, b)=\\sum_{c=1}^\\infty f(a,b,c)$.\nYou are given $F(6,10)=17$ and $F(36,100)=179$.

    \n\n

    \nFind $\\displaystyle\\sum_{k=1}^{18}F(6^k,10^k)$.

    ", "url": "https://projecteuler.net/problem=876", "answer": "457019806569269"} {"id": 877, "problem": "We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.\n\nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.\n\nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n\n$$\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}$$\n\nWe consider the equation:\n\n$$\\begin{align}\n(a \\otimes a) \\oplus (2 \\otimes a \\otimes b) \\oplus (b \\otimes b) = 5\n\\end{align}$$\n\nFor example, $(a, b) = (3, 6)$ is a solution.\n\nLet $X(N)$ be the XOR of the $b$ values for all solutions to this equation satisfying $0 \\le a \\le b \\le N$.\nYou are given $X(10)=5$.\n\nFind $X(10^{18})$.", "raw_html": "

    \nWe use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.
    \nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.\n

    \n

    \nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n

    \n$$\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}$$\n
    \nWe consider the equation:\n
    \n$$\\begin{align}\n(a \\otimes a) \\oplus (2 \\otimes a \\otimes b) \\oplus (b \\otimes b) = 5\n\\end{align}$$\n
    \n\nFor example, $(a, b) = (3, 6)$ is a solution.\n\n

    \nLet $X(N)$ be the XOR of the $b$ values for all solutions to this equation satisfying $0 \\le a \\le b \\le N$.
    You are given $X(10)=5$.\n

    \n

    \nFind $X(10^{18})$.\n

    ", "url": "https://projecteuler.net/problem=877", "answer": "336785000760344621"} {"id": 878, "problem": "We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.\n\nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.\n\nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n\n$$\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}$$\n\nWe consider the equation:\n\n$$\\begin{align}\n(a \\otimes a) \\oplus (2 \\otimes a \\otimes b) \\oplus (b \\otimes b) = k.\n\\end{align}$$\n\nFor example, $(a, b) = (3, 6)$ is a solution to this equation for $k=5$.\n\nLet $G(N,m)$ be the number of solutions to those equations with $k \\le m$ and $0 \\le a \\le b \\le N$.\n\nYou are given $G(1000,100)=398$.\n\nFind $G(10^{17},1\\,000\\,000).$", "raw_html": "We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.
    \nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.
    \n\nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n
    \n$$\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}$$\n
    \n\nWe consider the equation:\n
    \n$$\\begin{align}\n(a \\otimes a) \\oplus (2 \\otimes a \\otimes b) \\oplus (b \\otimes b) = k.\n\\end{align}$$\n
    \n

    \nFor example, $(a, b) = (3, 6)$ is a solution to this equation for $k=5$.\n

    \n

    \nLet $G(N,m)$ be the number of solutions to those equations with $k \\le m$ and $0 \\le a \\le b \\le N$.

    \n

    \nYou are given $G(1000,100)=398$.\n

    \nFind $G(10^{17},1\\,000\\,000).$\n

    ", "url": "https://projecteuler.net/problem=878", "answer": "23707109"} {"id": 879, "problem": "A touch-screen device can be unlocked with a \"password\" consisting of a sequence of two or more distinct spots that the user selects from a rectangular grid of spots on the screen. The user enters their sequence by touching the first spot, then tracing a straight line segment to the next spot, and so on until the end of the sequence. The user's finger remains in contact with the screen throughout, and may only move in straight line segments from spot to spot.\n\nIf the finger traces a straight line that passes over an intermediate spot, then that is treated as two line segments with the intermediate spot included in the password sequence. For example, on a $3\\times 3$ grid labelled with digits $1$ to $9$ (shown below), tracing $1-9$ is interpreted as $1-5-9$.\n\nOnce a spot has been selected it disappears from the screen. Thereafter, the spot may not be used as an endpoint of future line segments, and it is ignored by any future line segments which happen to pass through it. For example, tracing $1-9-3-7$ (which crosses the $5$ spot twice) will give the password $1-5-9-6-3-7$.\n\nThere are $389488$ different passwords that can be formed on a $3 \\times 3$ grid.\n\nFind the number of different passwords that can be formed on a $4 \\times 4$ grid.", "raw_html": "

    A touch-screen device can be unlocked with a \"password\" consisting of a sequence of two or more distinct spots that the user selects from a rectangular grid of spots on the screen. The user enters their sequence by touching the first spot, then tracing a straight line segment to the next spot, and so on until the end of the sequence. The user's finger remains in contact with the screen throughout, and may only move in straight line segments from spot to spot.

    \n\n

    If the finger traces a straight line that passes over an intermediate spot, then that is treated as two line segments with the intermediate spot included in the password sequence. For example, on a $3\\times 3$ grid labelled with digits $1$ to $9$ (shown below), tracing $1-9$ is interpreted as $1-5-9$.

    \n\n

    Once a spot has been selected it disappears from the screen. Thereafter, the spot may not be used as an endpoint of future line segments, and it is ignored by any future line segments which happen to pass through it. For example, tracing $1-9-3-7$ (which crosses the $5$ spot twice) will give the password $1-5-9-6-3-7$.

    \n\"1-5-9-6-3-7\n\n

    There are $389488$ different passwords that can be formed on a $3 \\times 3$ grid.

    \n\n

    Find the number of different passwords that can be formed on a $4 \\times 4$ grid.

    ", "url": "https://projecteuler.net/problem=879", "answer": "4350069824940"} {"id": 880, "problem": "$(x,y)$ is called a nested radical pair if $x$ and $y$ are non-zero integers such that $\\dfrac{x}{y}$ is not a cube of a rational number, and there exist integers $a$, $b$ and $c$ such that:\n\n$$\\sqrt{\\sqrt[3]{x}+\\sqrt[3]{y}}=\\sqrt[3]{a}+\\sqrt[3]{b}+\\sqrt[3]{c}$$\nFor example, both $(-4,125)$ and $(5,5324)$ are nested radical pairs:\n\n$$\n\\begin{align*}\n\\begin{split}\n\\sqrt{\\sqrt[3]{-4}+\\sqrt[3]{125}}\t&= \\sqrt[3]{-1}+\\sqrt[3]{2}+\\sqrt[3]{4}\\\\\n\\sqrt{\\sqrt[3]{5}+\\sqrt[3]{5324}}\t&= \\sqrt[3]{-2}+\\sqrt[3]{20}+\\sqrt[3]{25}\\\\\n\\end{split}\n\\end{align*}\n$$\n\nLet $H(N)$ be the sum of $|x|+|y|$ for all the nested radical pairs $(x, y)$ where $|x| \\leq |y|\\leq N$.\n\nFor example, $H(10^3)=2535$.\n\nFind $H(10^{15})$. Give your answer modulo $1031^3+2$.", "raw_html": "

    $(x,y)$ is called a nested radical pair if $x$ and $y$ are non-zero integers such that $\\dfrac{x}{y}$ is not a cube of a rational number, and there exist integers $a$, $b$ and $c$ such that:

    \n$$\\sqrt{\\sqrt[3]{x}+\\sqrt[3]{y}}=\\sqrt[3]{a}+\\sqrt[3]{b}+\\sqrt[3]{c}$$\n

    For example, both $(-4,125)$ and $(5,5324)$ are nested radical pairs:

    \n$$\n\\begin{align*}\n\\begin{split}\n\\sqrt{\\sqrt[3]{-4}+\\sqrt[3]{125}}\t&= \\sqrt[3]{-1}+\\sqrt[3]{2}+\\sqrt[3]{4}\\\\\n\\sqrt{\\sqrt[3]{5}+\\sqrt[3]{5324}}\t&= \\sqrt[3]{-2}+\\sqrt[3]{20}+\\sqrt[3]{25}\\\\\n\\end{split}\n\\end{align*}\n$$\n\n

    Let $H(N)$ be the sum of $|x|+|y|$ for all the nested radical pairs $(x, y)$ where $|x| \\leq |y|\\leq N$.
    \nFor example, $H(10^3)=2535$.

    \n\n

    Find $H(10^{15})$. Give your answer modulo $1031^3+2$.

    ", "url": "https://projecteuler.net/problem=880", "answer": "522095328"} {"id": 881, "problem": "For a positive integer $n$ create a graph using its divisors as vertices. An edge is drawn between two vertices $a \\lt b$ if their quotient $b/a$ is prime. The graph can be arranged into levels where vertex $n$ is at level $0$ and vertices that are a distance $k$ from $n$ are on level $k$. Define $g(n)$ to be the maximum number of vertices in a single level.\n\nThe example above shows that $g(45) = 2$. You are also given $g(5040) = 12$.\n\nFind the smallest number, $n$, such that $g(n) \\ge 10^4$.", "raw_html": "

    \nFor a positive integer $n$ create a graph using its divisors as vertices. An edge is drawn between two vertices $a \\lt b$ if their quotient $b/a$ is prime. The graph can be arranged into levels where vertex $n$ is at level $0$ and vertices that are a distance $k$ from $n$ are on level $k$. Define $g(n)$ to be the maximum number of vertices in a single level.

    \n\n\"0881_example45.jpg\"\n\n

    \nThe example above shows that $g(45) = 2$. You are also given $g(5040) = 12$.

    \n

    \nFind the smallest number, $n$, such that $g(n) \\ge 10^4$.

    ", "url": "https://projecteuler.net/problem=881", "answer": "205702861096933200"} {"id": 882, "problem": "Dr. One and Dr. Zero are playing the following partisan game.\n\nThe game begins with one $1$, two $2$'s, three $3$'s, ..., $n$ $n$'s. Starting with Dr. One, they make moves in turn.\n\nDr. One chooses a number and changes it by removing a $1$ from its binary expansion.\n\nDr. Zero chooses a number and changes it by removing a $0$ from its binary expansion.\n\nThe player that is unable to move loses.\n\nNote that leading zeros are not allowed in any binary expansion; in particular nobody can make a move on the number $0$.\n\nThey soon realize that Dr. Zero can never win the game. In order to make it more interesting, Dr. Zero is allowed to \"skip the turn\" several times, i.e. passing the turn back to Dr. One without making a move.\n\nFor example, when $n = 2$, Dr. Zero can win the game if allowed to skip $2$ turns. A sample game:\n$$\n[1, 2, 2]\\xrightarrow{\\textrm{Dr. One}}[1, 0, 2]\\xrightarrow{\\textrm{Dr. Zero}}[1, 0, 1]\\xrightarrow{\\textrm{Dr. One}}[1, 0, 0]\\xrightarrow[\\textrm{skip}]{\\textrm{Dr. Zero}}\n[1, 0, 0]\\xrightarrow{\\textrm{Dr. One}}[0, 0, 0]\\xrightarrow[\\textrm{skip}]{\\textrm{Dr. Zero}}[0, 0, 0].\n$$\nLet $S(n)$ be the minimal number of skips needed so that Dr. Zero has a winning strategy.\n\nFor example, $S(2) = 2$, $S(5) = 17$, $S(10) = 64$.\n\nFind $S(10^5)$.", "raw_html": "

    Dr. One and Dr. Zero are playing the following partisan game.
    \nThe game begins with one $1$, two $2$'s, three $3$'s, ..., $n$ $n$'s. Starting with Dr. One, they make moves in turn.
    \nDr. One chooses a number and changes it by removing a $1$ from its binary expansion.
    \nDr. Zero chooses a number and changes it by removing a $0$ from its binary expansion.
    \nThe player that is unable to move loses.
    \nNote that leading zeros are not allowed in any binary expansion; in particular nobody can make a move on the number $0$.

    \n\n

    They soon realize that Dr. Zero can never win the game. In order to make it more interesting, Dr. Zero is allowed to \"skip the turn\" several times, i.e. passing the turn back to Dr. One without making a move.

    \n\n

    For example, when $n = 2$, Dr. Zero can win the game if allowed to skip $2$ turns. A sample game:\n$$\n[1, 2, 2]\\xrightarrow{\\textrm{Dr. One}}[1, 0, 2]\\xrightarrow{\\textrm{Dr. Zero}}[1, 0, 1]\\xrightarrow{\\textrm{Dr. One}}[1, 0, 0]\\xrightarrow[\\textrm{skip}]{\\textrm{Dr. Zero}}\n[1, 0, 0]\\xrightarrow{\\textrm{Dr. One}}[0, 0, 0]\\xrightarrow[\\textrm{skip}]{\\textrm{Dr. Zero}}[0, 0, 0].\n$$\nLet $S(n)$ be the minimal number of skips needed so that Dr. Zero has a winning strategy.
    \nFor example, $S(2) = 2$, $S(5) = 17$, $S(10) = 64$.

    \n\n

    Find $S(10^5)$.

    ", "url": "https://projecteuler.net/problem=882", "answer": "15800662276"} {"id": 883, "problem": "In this problem we consider triangles drawn on a hexagonal lattice, where each lattice point in the plane has six neighbouring points equally spaced around it, all distance $1$ away.\n\nWe call a triangle remarkable if\n\n- All three vertices and its incentre lie on lattice points\n\n- At least one of its angles is $60^\\circ$\n\nAbove are four examples of remarkable triangles, with $60^\\circ$ angles illustrated in red. Triangles A and B have inradius $1$; C has inradius $\\sqrt{3}$; D has inradius $2$.\n\nDefine $T(r)$ to be the number of remarkable triangles with inradius $\\le r$. Rotations and reflections, such as triangles A and B above, are counted separately; however direct translations are not. That is, the same triangle drawn in different positions of the lattice is only counted once.\n\nYou are given $T(0.5)=2$, $T(2)=44$, and $T(10)=1302$.\n\nFind $T(10^6)$.", "raw_html": "

    \nIn this problem we consider triangles drawn on a hexagonal lattice, where each lattice point in the plane has six neighbouring points equally spaced around it, all distance $1$ away.

    \n\n

    \nWe call a triangle remarkable if

    \n
      \n
    • All three vertices and its incentre lie on lattice points
    • \n
    • At least one of its angles is $60^\\circ$
    • \n
    \n\"0883_diagram.png\"\n\n

    \nAbove are four examples of remarkable triangles, with $60^\\circ$ angles illustrated in red. Triangles A and B have inradius $1$; C has inradius $\\sqrt{3}$; D has inradius $2$.

    \n\n

    \nDefine $T(r)$ to be the number of remarkable triangles with inradius $\\le r$. Rotations and reflections, such as triangles A and B above, are counted separately; however direct translations are not. That is, the same triangle drawn in different positions of the lattice is only counted once.

    \n\n

    \nYou are given $T(0.5)=2$, $T(2)=44$, and $T(10)=1302$.

    \n\n

    \nFind $T(10^6)$.

    ", "url": "https://projecteuler.net/problem=883", "answer": "14854003484704"} {"id": 884, "problem": "Starting from a positive integer $n$, at each step we subtract from $n$ the largest perfect cube not exceeding $n$, until $n$ becomes $0$.\n\nFor example, with $n = 100$ the procedure ends in $4$ steps:\n$$100 \\xrightarrow{-4^3} 36 \\xrightarrow{-3^3} 9 \\xrightarrow{-2^3} 1 \\xrightarrow{-1^3} 0.$$\nLet $D(n)$ denote the number of steps of the procedure. Thus $D(100) = 4$.\n\nLet $S(N)$ denote the sum of $D(n)$ for all positive integers $n$ strictly less than $N$.\n\nFor example, $S(100) = 512$.\n\nFind $S(10^{17})$.", "raw_html": "

    \nStarting from a positive integer $n$, at each step we subtract from $n$ the largest perfect cube not exceeding $n$, until $n$ becomes $0$.
    \nFor example, with $n = 100$ the procedure ends in $4$ steps:\n$$100 \\xrightarrow{-4^3} 36 \\xrightarrow{-3^3} 9 \\xrightarrow{-2^3} 1 \\xrightarrow{-1^3} 0.$$\nLet $D(n)$ denote the number of steps of the procedure. Thus $D(100) = 4$.

    \n\n

    \nLet $S(N)$ denote the sum of $D(n)$ for all positive integers $n$ strictly less than $N$.
    \nFor example, $S(100) = 512$.

    \n\n

    \nFind $S(10^{17})$.

    ", "url": "https://projecteuler.net/problem=884", "answer": "1105985795684653500"} {"id": 885, "problem": "For a positive integer $d$, let $f(d)$ be the number created by sorting the digits of $d$ in ascending order, removing any zeros. For example, $f(3403) = 334$.\n\nLet $S(n)$ be the sum of $f(d)$ for all positive integers $d$ of $n$ digits or less. You are given $S(1) = 45$ and $S(5) = 1543545675$.\n\nFind $S(18)$. Give your answer modulo $1123455689$.", "raw_html": "

    \nFor a positive integer $d$, let $f(d)$ be the number created by sorting the digits of $d$ in ascending order, removing any zeros. For example, $f(3403) = 334$.

    \n\n

    \nLet $S(n)$ be the sum of $f(d)$ for all positive integers $d$ of $n$ digits or less. You are given $S(1) = 45$ and $S(5) = 1543545675$.

    \n\n

    \nFind $S(18)$. Give your answer modulo $1123455689$.

    ", "url": "https://projecteuler.net/problem=885", "answer": "827850196"} {"id": 886, "problem": "A permutation of $\\{2,3,\\ldots,n\\}$ is a rearrangement of these numbers. A coprime permutation is a rearrangement such that all pairs of adjacent numbers are coprime.\n\nLet $P(n)$ be the number of coprime permutations of $\\{2,3,\\ldots,n\\}$.\n\nFor example, $P(4)=2$ as there are two coprime permutations, $(2,3,4)$ and $(4,3,2)$. You are also given $P(10)=576$.\n\nFind $P(34)$ and give your answer modulo $83\\,456\\,729$.", "raw_html": "

    A permutation of $\\{2,3,\\ldots,n\\}$ is a rearrangement of these numbers. A coprime permutation is a rearrangement such that all pairs of adjacent numbers are coprime.

    \n\n

    Let $P(n)$ be the number of coprime permutations of $\\{2,3,\\ldots,n\\}$.

    \n\n

    For example, $P(4)=2$ as there are two coprime permutations, $(2,3,4)$ and $(4,3,2)$. You are also given $P(10)=576$.

    \n\n

    Find $P(34)$ and give your answer modulo $83\\,456\\,729$.

    ", "url": "https://projecteuler.net/problem=886", "answer": "5570163"} {"id": 887, "problem": "Consider the problem of determining a secret number from a set $\\{1, ..., N\\}$ by repeatedly choosing a number $y$ and asking \"Is the secret number greater than $y$?\".\n\nIf $N=1$ then no questions need to be asked. If $N=2$ then only one question needs to be asked. If $N=64$ then six questions need to be asked. However, in the latter case if the secret number is $1$ then six questions still need to be asked. We want to restrict the number of questions asked for small values.\n\nLet $Q(N, d)$ be the least number of questions needed for a strategy that can find any secret number from the set $\\{1, ..., N\\}$ where no more than $x + d$ questions are needed to find the secret value $x$.\n\nIt can be proved that $Q(N, 0) = N - 1$. You are also given $Q(7, 1) = 3$ and $Q(777, 2) = 10$.\n\nFind $\\displaystyle \\sum_{d=0}^7 \\sum_{N=1}^{7^{10}} Q(N, d)$.", "raw_html": "

    Consider the problem of determining a secret number from a set $\\{1, ..., N\\}$ by repeatedly choosing a number $y$ and asking \"Is the secret number greater than $y$?\".

    \n\n

    If $N=1$ then no questions need to be asked. If $N=2$ then only one question needs to be asked. If $N=64$ then six questions need to be asked. However, in the latter case if the secret number is $1$ then six questions still need to be asked. We want to restrict the number of questions asked for small values.

    \n\n

    Let $Q(N, d)$ be the least number of questions needed for a strategy that can find any secret number from the set $\\{1, ..., N\\}$ where no more than $x + d$ questions are needed to find the secret value $x$.

    \n\n

    It can be proved that $Q(N, 0) = N - 1$. You are also given $Q(7, 1) = 3$ and $Q(777, 2) = 10$.

    \n\n

    Find $\\displaystyle \\sum_{d=0}^7 \\sum_{N=1}^{7^{10}} Q(N, d)$.

    ", "url": "https://projecteuler.net/problem=887", "answer": "39896187138661622"} {"id": 888, "problem": "Two players play a game with a number of piles of stones, alternating turns. Each turn a player can choose to remove 1, 2, 4, or 9 stones from a single pile; or alternatively they can choose to split a pile containing two or more stones into two non-empty piles. The winner is the player who removes the last stone.\n\nA collection of piles is called a losing position if the player to move cannot force a win with optimal play. Define $S(N, m)$ to be the number of distinct losing positions arising from $m$ piles of stones where each pile contains from $1$ to $N$ stones. Two positions are considered equivalent if they consist of the same pile sizes. That is, the order of the piles does not matter.\n\nYou are given $S(12,4)=204$ and $S(124,9)=2259208528408$.\n\nFind $S(12491249,1249)$. Give your answer modulo $912491249$.", "raw_html": "

    \nTwo players play a game with a number of piles of stones, alternating turns. Each turn a player can choose to remove 1, 2, 4, or 9 stones from a single pile; or alternatively they can choose to split a pile containing two or more stones into two non-empty piles. The winner is the player who removes the last stone.

    \n\n

    \nA collection of piles is called a losing position if the player to move cannot force a win with optimal play. Define $S(N, m)$ to be the number of distinct losing positions arising from $m$ piles of stones where each pile contains from $1$ to $N$ stones. Two positions are considered equivalent if they consist of the same pile sizes. That is, the order of the piles does not matter.

    \n\n

    \nYou are given $S(12,4)=204$ and $S(124,9)=2259208528408$.

    \n\n

    \nFind $S(12491249,1249)$. Give your answer modulo $912491249$.

    ", "url": "https://projecteuler.net/problem=888", "answer": "227429102"} {"id": 889, "problem": "Recall the blancmange function from Problem 226: $T(x) = \\sum\\limits_{n = 0}^\\infty\\dfrac{s(2^nx)}{2^n}$, where $s(x)$ is the distance from $x$ to the nearest integer.\n\nFor positive integers $k, t, r$, we write $$F(k, t, r) = (2^{2k} - 1)T\\left(\\frac{(2^t + 1)^r}{2^k + 1}\\right).$$ It can be shown that $F(k, t, r)$ is always an integer.\n\nFor example, $F(3, 1, 1) = 42$, $F(13, 3, 3) = 23093880$ and $F(103, 13, 6) \\equiv 878922518\\pmod {1\\,000\\,062\\,031}$.\n\nFind $F(10^{18} + 31, 10^{14} + 31, 62)$. Give your answer modulo $1\\,000\\,062\\,031$.", "raw_html": "

    \nRecall the blancmange function from Problem 226: $T(x) = \\sum\\limits_{n = 0}^\\infty\\dfrac{s(2^nx)}{2^n}$, where $s(x)$ is the distance from $x$ to the nearest integer.

    \n\n

    \nFor positive integers $k, t, r$, we write $$F(k, t, r) = (2^{2k} - 1)T\\left(\\frac{(2^t + 1)^r}{2^k + 1}\\right).$$ It can be shown that $F(k, t, r)$ is always an integer.
    \nFor example, $F(3, 1, 1) = 42$, $F(13, 3, 3) = 23093880$ and $F(103, 13, 6) \\equiv 878922518\\pmod {1\\,000\\,062\\,031}$.

    \n\n

    \nFind $F(10^{18} + 31, 10^{14} + 31, 62)$. Give your answer modulo $1\\,000\\,062\\,031$.

    ", "url": "https://projecteuler.net/problem=889", "answer": "424315113"} {"id": 890, "problem": "Let $p(n)$ be the number of ways to write $n$ as the sum of powers of two, ignoring order.\n\nFor example, $p(7) = 6$, the partitions being\n$$\n\\begin{align}\n7 &= 1+1+1+1+1+1+1 \\\\\n&=1+1+1+1+1+2 \\\\\n&=1+1+1+2+2 \\\\\n&=1+1+1+4 \\\\\n&=1+2+2+2 \\\\\n&=1+2+4\n\\end{align}\n$$\nYou are also given $p(7^7) \\equiv 144548435 \\pmod {10^9+7}$.\n\nFind $p(7^{777})$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    Let $p(n)$ be the number of ways to write $n$ as the sum of powers of two, ignoring order.

    \n\n

    For example, $p(7) = 6$, the partitions being\n$$\n\\begin{align}\n7 &= 1+1+1+1+1+1+1 \\\\\n&=1+1+1+1+1+2 \\\\\n&=1+1+1+2+2 \\\\\n&=1+1+1+4 \\\\\n&=1+2+2+2 \\\\\n&=1+2+4\n\\end{align}\n$$\nYou are also given $p(7^7) \\equiv 144548435 \\pmod {10^9+7}$.

    \n\n

    Find $p(7^{777})$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=890", "answer": "820442179"} {"id": 891, "problem": "A round clock only has three hands: hour, minute, second. All hands look identical and move continuously. Moreover, there is no number or reference mark so that the \"upright position\" is unknown. The clock functions the same as a normal 12-hour analogue clock.\n\nDespite the inconvenient design, for most time it is possible to tell the correct time (within a 12-hour cycle) from the clock, just by measuring accurately the angles between the hands. For example, if all three hands coincide, then the time must be 12:00:00.\n\nNevertheless, there are several moments where the clock shows an ambiguous reading. For example, the following moment could be either 1:30:00 or 7:30:00 (with the clock rotated $180^\\circ$). Thus both 1:30:00 and 7:30:00 are ambiguous moments.\n\nNote that even if two hands perfectly coincide, we can still see them as two distinct hands in the same position. Thus for example 3:00:00 and 9:00:00 are not ambiguous moments.\n\nHow many ambiguous moments are there within a 12-hour cycle?", "raw_html": "

    \nA round clock only has three hands: hour, minute, second. All hands look identical and move continuously. Moreover, there is no number or reference mark so that the \"upright position\" is unknown. The clock functions the same as a normal 12-hour analogue clock.

    \n\n

    \nDespite the inconvenient design, for most time it is possible to tell the correct time (within a 12-hour cycle) from the clock, just by measuring accurately the angles between the hands. For example, if all three hands coincide, then the time must be 12:00:00.

    \n\n

    \nNevertheless, there are several moments where the clock shows an ambiguous reading. For example, the following moment could be either 1:30:00 or 7:30:00 (with the clock rotated $180^\\circ$). Thus both 1:30:00 and 7:30:00 are ambiguous moments.
    \nNote that even if two hands perfectly coincide, we can still see them as two distinct hands in the same position. Thus for example 3:00:00 and 9:00:00 are not ambiguous moments.\n

    \n\n
    \"0891_clock.png\"
    \n\n

    \nHow many ambiguous moments are there within a 12-hour cycle?

    ", "url": "https://projecteuler.net/problem=891", "answer": "1541414"} {"id": 892, "problem": "Consider a circle where $2n$ distinct points have been marked on its circumference.\n\nA cutting $C$ consists of connecting the $2n$ points with $n$ line segments, so that no two line segments intersect, including on their end points. The $n$ line segments then cut the circle into $n + 1$ pieces.\nEach piece is painted either black or white, so that adjacent pieces are opposite colours.\nLet $d(C)$ be the absolute difference between the numbers of black and white pieces under the cutting $C$.\n\nLet $D(n)$ be the sum of $d(C)$ over all different cuttings $C$.\nFor example, there are five different cuttings with $n = 3$.\n\nThe upper three cuttings all have $d = 0$ because there are two black and two white pieces; the lower two cuttings both have $d = 2$ because there are three black and one white pieces.\nTherefore $D(3) = 0 + 0 + 0 + 2 + 2 = 4$.\nYou are also given $D(100) \\equiv 1172122931\\pmod{1234567891}$.\n\nFind $\\displaystyle \\sum_{n=1}^{10^7} D(n)$. Give your answer modulo $1234567891$.", "raw_html": "

    \nConsider a circle where $2n$ distinct points have been marked on its circumference.

    \n\n

    \nA cutting $C$ consists of connecting the $2n$ points with $n$ line segments, so that no two line segments intersect, including on their end points. The $n$ line segments then cut the circle into $n + 1$ pieces.\nEach piece is painted either black or white, so that adjacent pieces are opposite colours.\nLet $d(C)$ be the absolute difference between the numbers of black and white pieces under the cutting $C$.

    \n\n

    \nLet $D(n)$ be the sum of $d(C)$ over all different cuttings $C$.\nFor example, there are five different cuttings with $n = 3$.

    \n\n
    \n\"0892_Zebra.png\"
    \n\n

    \nThe upper three cuttings all have $d = 0$ because there are two black and two white pieces; the lower two cuttings both have $d = 2$ because there are three black and one white pieces.\nTherefore $D(3) = 0 + 0 + 0 + 2 + 2 = 4$. \nYou are also given $D(100) \\equiv 1172122931\\pmod{1234567891}$.

    \n\n

    \nFind $\\displaystyle \\sum_{n=1}^{10^7} D(n)$. Give your answer modulo $1234567891$.

    ", "url": "https://projecteuler.net/problem=892", "answer": "469137427"} {"id": 893, "problem": "Define $M(n)$ to be the minimum number of matchsticks needed to represent the number $n$.\n\nA number can be represented in digit form or as an expression involving addition and/or multiplication. Also order of operations must be followed, that is multiplication binding tighter than addition. Any other symbols or operations, such as brackets, subtraction, division or exponentiation, are not allowed.\n\nThe valid digits and symbols are shown below:\n\nFor example, $28$ needs $12$ matchsticks to represent it in digit form but representing it as $4\\times 7$ would only need $9$ matchsticks and as there is no way using fewer matchsticks $M(28) = 9$.\n\nDefine $\\displaystyle T(N) = \\sum_{n=1}^N M(n)$. You are given $T(100) = 916$.\n\nFind $T(10^6)$.", "raw_html": "

    \nDefine $M(n)$ to be the minimum number of matchsticks needed to represent the number $n$.

    \n\n

    \nA number can be represented in digit form or as an expression involving addition and/or multiplication. Also order of operations must be followed, that is multiplication binding tighter than addition. Any other symbols or operations, such as brackets, subtraction, division or exponentiation, are not allowed.

    \n\n

    \nThe valid digits and symbols are shown below:

    \n
    \n\"0893_DigitDiagram.jpg\"
    \n\n

    \nFor example, $28$ needs $12$ matchsticks to represent it in digit form but representing it as $4\\times 7$ would only need $9$ matchsticks and as there is no way using fewer matchsticks $M(28) = 9$.

    \n\n

    \nDefine $\\displaystyle T(N) = \\sum_{n=1}^N M(n)$. You are given $T(100) = 916$.

    \n\n

    \nFind $T(10^6)$.

    ", "url": "https://projecteuler.net/problem=893", "answer": "26688208"} {"id": 894, "problem": "Consider a unit circlecircle with radius 1 $C_0$ on the plane that does not enclose the origin. For $k\\ge 1$, a circle $C_k$ is created by scaling and rotating $C_{k - 1}$ with respect to the origin. That is, both the radius and the distance to the origin are scaled by the same factor, and the centre of rotation is the origin. The scaling factor is positive and strictly less than one. Both it and the rotation angle remain constant for each $k$.\n\nIt is given that $C_0$ is externally tangent to $C_1$, $C_7$ and $C_8$, as shown in the diagram below, and no two circles overlap.\n\nFind the total area of all the circular trianglesA circular triangle is a triangle with circular arc edges in the diagram, i.e. the area painted green above.\n\nGive your answer rounded to $10$ places after the decimal point.", "raw_html": "

    Consider a unit circlecircle with radius 1 $C_0$ on the plane that does not enclose the origin. For $k\\ge 1$, a circle $C_k$ is created by scaling and rotating $C_{k - 1}$ with respect to the origin. That is, both the radius and the distance to the origin are scaled by the same factor, and the centre of rotation is the origin. The scaling factor is positive and strictly less than one. Both it and the rotation angle remain constant for each $k$.

    \n\n

    It is given that $C_0$ is externally tangent to $C_1$, $C_7$ and $C_8$, as shown in the diagram below, and no two circles overlap.

    \n
    \"0894_circle_spiral.jpg\"
    \n\n

    Find the total area of all the circular trianglesA circular triangle is a triangle with circular arc edges in the diagram, i.e. the area painted green above.
    \nGive your answer rounded to $10$ places after the decimal point.

    ", "url": "https://projecteuler.net/problem=894", "answer": "0.7718678168"} {"id": 895, "problem": "Gary and Sally play a game using gold and silver coins arranged into a number of vertical stacks, alternating turns. On Gary's turn he chooses a gold coin and removes it from the game along with any other coins sitting on top. Sally does the same on her turn by removing a silver coin. The first player unable to make a move loses.\n\nAn arrangement is called fair if the person moving first, whether it be Gary or Sally, will lose the game if both play optimally.\n\nAn arrangement is called balanced if the number of gold and silver coins are equal.\n\nDefine $G(m)$ to be the number of fair and balanced arrangements consisting of three non-empty stacks, each not exceeding $m$ in size. Different orderings of the stacks are to be counted separately, so $G(2)=6$ due to the following six arrangements:\n\nYou are also given $G(5)=348$ and $G(20)=125825982708$.\n\nFind $G(9898)$ giving your answer modulo $989898989$.", "raw_html": "

    \nGary and Sally play a game using gold and silver coins arranged into a number of vertical stacks, alternating turns. On Gary's turn he chooses a gold coin and removes it from the game along with any other coins sitting on top. Sally does the same on her turn by removing a silver coin. The first player unable to make a move loses.

    \n\n

    \nAn arrangement is called fair if the person moving first, whether it be Gary or Sally, will lose the game if both play optimally.

    \n\n

    \nAn arrangement is called balanced if the number of gold and silver coins are equal.

    \n\n

    \nDefine $G(m)$ to be the number of fair and balanced arrangements consisting of three non-empty stacks, each not exceeding $m$ in size. Different orderings of the stacks are to be counted separately, so $G(2)=6$ due to the following six arrangements:

    \n\n
    \"0895_G2.png\"
    \n\n

    \nYou are also given $G(5)=348$ and $G(20)=125825982708$.

    \n\n

    \nFind $G(9898)$ giving your answer modulo $989898989$.

    ", "url": "https://projecteuler.net/problem=895", "answer": "670785433"} {"id": 896, "problem": "A contiguous range of positive integers is called a divisible range if all the integers in the range can be arranged in a row such that the $n$-th term is a multiple of $n$.\n\nFor example, the range $[6..9]$ is a divisible range because we can arrange the numbers as $7,6,9,8$.\n\nIn fact, it is the $4$th divisible range of length $4$, the first three being $[1..4], [2..5], [3..6]$.\n\nFind the $36$th divisible range of length $36$.\n\nGive as answer the smallest number in the range.", "raw_html": "

    \nA contiguous range of positive integers is called a divisible range if all the integers in the range can be arranged in a row such that the $n$-th term is a multiple of $n$.
    \nFor example, the range $[6..9]$ is a divisible range because we can arrange the numbers as $7,6,9,8$.
    \nIn fact, it is the $4$th divisible range of length $4$, the first three being $[1..4], [2..5], [3..6]$.

    \n\n

    \nFind the $36$th divisible range of length $36$.
    \nGive as answer the smallest number in the range.

    ", "url": "https://projecteuler.net/problem=896", "answer": "274229635640"} {"id": 897, "problem": "Let $G(n)$ denote the largest possible area of an $n$-gona polygon with $n$ sides contained in the region $\\{(x, y) \\in \\Bbb R^2: x^4 \\leq y \\leq 1\\}$.\n\nFor example, $G(3) = 1$ and $G(5)\\approx 1.477309771$.\n\nFind $G(101)$ rounded to nine digits after the decimal point.", "raw_html": "

    \nLet $G(n)$ denote the largest possible area of an $n$-gona polygon with $n$ sides contained in the region $\\{(x, y) \\in \\Bbb R^2: x^4 \\leq y \\leq 1\\}$.
    \nFor example, $G(3) = 1$ and $G(5)\\approx 1.477309771$.
    \nFind $G(101)$ rounded to nine digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=897", "answer": "1.599827123"} {"id": 898, "problem": "Claire Voyant is a teacher playing a game with a class of students.\nA fair coin is tossed on the table. All the students can see the outcome of the toss, but Claire cannot.\nEach student then tells Claire whether the outcome is head or tail. The students may lie, but Claire knows the probability that each individual student lies. Moreover, the students lie independently.\nAfter that, Claire attempts to guess the outcome using an optimal strategy.\n\nFor example, for a class of four students with lying probabilities $20\\%,40\\%,60\\%,80\\%$, Claire guesses correctly with probability 0.832.\n\nFind the probability that Claire guesses correctly for a class of 51 students each lying with a probability of $25\\%, 26\\%, \\dots, 75\\%$\nrespectively.\n\nGive your answer rounded to 10 digits after the decimal point.", "raw_html": "

    \nClaire Voyant is a teacher playing a game with a class of students.\nA fair coin is tossed on the table. All the students can see the outcome of the toss, but Claire cannot.\nEach student then tells Claire whether the outcome is head or tail. The students may lie, but Claire knows the probability that each individual student lies. Moreover, the students lie independently.\nAfter that, Claire attempts to guess the outcome using an optimal strategy.\n

    \n

    \nFor example, for a class of four students with lying probabilities $20\\%,40\\%,60\\%,80\\%$, Claire guesses correctly with probability 0.832.\n

    \n

    \nFind the probability that Claire guesses correctly for a class of 51 students each lying with a probability of $25\\%, 26\\%, \\dots, 75\\%$\n respectively.\n

    \n

    \nGive your answer rounded to 10 digits after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=898", "answer": "0.9861343531"} {"id": 899, "problem": "Two players play a game with two piles of stones. The players alternately take stones from one or both piles, subject to:\n\n- the total number of stones taken is equal to the size of the smallest pile before the move;\n\n- the move cannot take all the stones from a pile.\n\nThe player that is unable to move loses.\n\nFor example, if the piles are of sizes 3 and 5 then there are three possible moves.\n$$(3,5) \\xrightarrow{(2,1)} (1,4)\\qquad\\qquad (3,5) \\xrightarrow{(1,2)} (2,3)\\qquad\\qquad (3,5) \\xrightarrow{(0,3)} (3,2)$$\n\nLet $L(n)$ be the number of ordered pairs $(a,b)$ with $1 \\leq a,b \\leq n$ such that the initial game position with piles of sizes $a$ and $b$ is losing for the first player assuming optimal play.\n\nYou are given $L(7) = 21$ and $L(7^2) = 221$.\n\nFind $L(7^{17})$.", "raw_html": "

    \nTwo players play a game with two piles of stones. The players alternately take stones from one or both piles, subject to:

    \n\n
      \n
    1. the total number of stones taken is equal to the size of the smallest pile before the move;
    2. \n\n
    3. the move cannot take all the stones from a pile.
    4. \n
    \n\n

    \nThe player that is unable to move loses.

    \n\n

    \nFor example, if the piles are of sizes 3 and 5 then there are three possible moves.\n$$(3,5) \\xrightarrow{(2,1)} (1,4)\\qquad\\qquad (3,5) \\xrightarrow{(1,2)} (2,3)\\qquad\\qquad (3,5) \\xrightarrow{(0,3)} (3,2)$$

    \n\n

    \nLet $L(n)$ be the number of ordered pairs $(a,b)$ with $1 \\leq a,b \\leq n$ such that the initial game position with piles of sizes $a$ and $b$ is losing for the first player assuming optimal play.

    \n\n

    \nYou are given $L(7) = 21$ and $L(7^2) = 221$.

    \n\n

    \nFind $L(7^{17})$.

    ", "url": "https://projecteuler.net/problem=899", "answer": "10784223938983273"} {"id": 900, "problem": "Two players play a game with at least two piles of stones. The players alternately take stones from one or more piles, subject to:\n\n- the total number of stones taken is equal to the size of the smallest pile before the move;\n\n- the move cannot take all the stones from a pile.\n\nThe player that is unable to move loses.\n\nFor example, if the piles are of sizes 2, 2 and 4 then there are four possible moves.\n$$ (2,2,4)\\xrightarrow{(1,1,0)}(1,1,4)\\quad (2,2,4)\\xrightarrow{(1,0,1)}(1,2,3)\\quad\n(2,2,4)\\xrightarrow{(0,1,1)}(2,1,3)\\quad (2,2,4)\\xrightarrow{(0,0,2)}(2,2,2)$$\n\nLet $t(n)$ be the smallest nonnegative integer $k$ such that the position with $n$ piles of $n$ stones and a single pile of $n+k$ stones is losing for the first player assuming optimal play. For example, $t(1) = t(2) = 0$ and $t(3) = 2$.\n\nDefine $\\displaystyle S(N) = \\sum_{n=1}^{2^N} t(n)$. You are given $S(10) = 361522$.\n\nFind $S(10^4)$. Give your answer modulo $900497239$.", "raw_html": "

    \nTwo players play a game with at least two piles of stones. The players alternately take stones from one or more piles, subject to:

    \n\n
      \n
    1. the total number of stones taken is equal to the size of the smallest pile before the move;
    2. \n\n
    3. the move cannot take all the stones from a pile.
    4. \n
    \n\n

    \nThe player that is unable to move loses.

    \n\n

    \nFor example, if the piles are of sizes 2, 2 and 4 then there are four possible moves.\n$$ (2,2,4)\\xrightarrow{(1,1,0)}(1,1,4)\\quad (2,2,4)\\xrightarrow{(1,0,1)}(1,2,3)\\quad\n(2,2,4)\\xrightarrow{(0,1,1)}(2,1,3)\\quad (2,2,4)\\xrightarrow{(0,0,2)}(2,2,2)$$

    \n\n

    \nLet $t(n)$ be the smallest nonnegative integer $k$ such that the position with $n$ piles of $n$ stones and a single pile of $n+k$ stones is losing for the first player assuming optimal play. For example, $t(1) = t(2) = 0$ and $t(3) = 2$.

    \n\n

    \nDefine $\\displaystyle S(N) = \\sum_{n=1}^{2^N} t(n)$. You are given $S(10) = 361522$.

    \n\n

    \nFind $S(10^4)$. Give your answer modulo $900497239$.\n

    ", "url": "https://projecteuler.net/problem=900", "answer": "646900900"} {"id": 901, "problem": "A driller drills for water. At each iteration the driller chooses a depth $d$ (a positive real number), drills to this depth and then checks if water was found. If so, the process terminates. Otherwise, a new depth is chosen and a new drilling starts from the ground level in a new location nearby.\n\nDrilling to depth $d$ takes exactly $d$ hours. The groundwater depth is constant in the relevant area and its distribution is known to be an exponential random variable with expected value of $1$. In other words, the probability that the groundwater is deeper than $d$ is $e^{-d}$.\n\nAssuming an optimal strategy, find the minimal expected drilling time in hours required to find water. Give your answer rounded to 9 places after the decimal point.", "raw_html": "

    A driller drills for water. At each iteration the driller chooses a depth $d$ (a positive real number), drills to this depth and then checks if water was found. If so, the process terminates. Otherwise, a new depth is chosen and a new drilling starts from the ground level in a new location nearby.

    \n\n

    Drilling to depth $d$ takes exactly $d$ hours. The groundwater depth is constant in the relevant area and its distribution is known to be an exponential random variable with expected value of $1$. In other words, the probability that the groundwater is deeper than $d$ is $e^{-d}$.

    \n\n

    Assuming an optimal strategy, find the minimal expected drilling time in hours required to find water. Give your answer rounded to 9 places after the decimal point.

    ", "url": "https://projecteuler.net/problem=901", "answer": "2.364497769"} {"id": 902, "problem": "A permutation $\\pi$ of $\\{1, \\dots, n\\}$ can be represented in one-line notation as $\\pi(1),\\ldots,\\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\\textrm{rank}(\\pi)$ is the position of $\\pi$ in this 1-based list.\n\nFor example, $\\text{rank}(2,1,3) = 3$ because the six permutations of $\\{1, 2, 3\\}$ in lexicographic order are:\n$$1, 2, 3\\quad 1, 3, 2 \\quad 2, 1, 3 \\quad 2, 3, 1 \\quad 3, 1, 2 \\quad 3, 2, 1$$\n\nFor a positive integer $m$, we define the following permutation of $\\{1, \\dots, n\\}$ with $n = \\frac{m(m+1)}2$:\n$$\n\\begin{align}\n\\sigma(i) &= \\begin{cases} \\frac{k(k-1)}2 + 1 & \\textrm{if } i = \\frac{k(k + 1)}2\\textrm{ for }k\\in\\{1, \\dots, m\\};\\\\i + 1 & \\textrm{otherwise};\\end{cases}\\\\\n\\tau(i) &= ((10^9 + 7)i \\bmod n) + 1\\\\\n\\pi(i) &= \\tau^{-1}(\\sigma(\\tau(i)))\n\\end{align}\n$$\nwhere $\\tau^{-1}$ is the inverse permutation of $\\tau$.\n\nDefine $\\displaystyle P(m) = \\sum_{k=1}^{m!} \\text{rank}(\\pi^k)$, where $\\pi^k$ is the permutation arising from applying $\\pi$ $k$ times.\n\nFor example, $P(2) = 4$, $P(3) = 780$ and $P(4) = 38810300$.\n\nFind $P(100)$. Give your answer modulo $(10^9 + 7)$.", "raw_html": "

    A permutation $\\pi$ of $\\{1, \\dots, n\\}$ can be represented in one-line notation as $\\pi(1),\\ldots,\\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\\textrm{rank}(\\pi)$ is the position of $\\pi$ in this 1-based list.

    \n\n

    For example, $\\text{rank}(2,1,3) = 3$ because the six permutations of $\\{1, 2, 3\\}$ in lexicographic order are:\n$$1, 2, 3\\quad 1, 3, 2 \\quad 2, 1, 3 \\quad 2, 3, 1 \\quad 3, 1, 2 \\quad 3, 2, 1$$\n

    \n\n

    For a positive integer $m$, we define the following permutation of $\\{1, \\dots, n\\}$ with $n = \\frac{m(m+1)}2$:\n$$\n\\begin{align}\n\\sigma(i) &= \\begin{cases} \\frac{k(k-1)}2 + 1 & \\textrm{if } i = \\frac{k(k + 1)}2\\textrm{ for }k\\in\\{1, \\dots, m\\};\\\\i + 1 & \\textrm{otherwise};\\end{cases}\\\\\n\\tau(i) &= ((10^9 + 7)i \\bmod n) + 1\\\\\n\\pi(i) &= \\tau^{-1}(\\sigma(\\tau(i)))\n\\end{align}\n$$\nwhere $\\tau^{-1}$ is the inverse permutation of $\\tau$.\n

    \n\n

    Define $\\displaystyle P(m) = \\sum_{k=1}^{m!} \\text{rank}(\\pi^k)$, where $\\pi^k$ is the permutation arising from applying $\\pi$ $k$ times.
    \nFor example, $P(2) = 4$, $P(3) = 780$ and $P(4) = 38810300$.

    \n\n

    \nFind $P(100)$. Give your answer modulo $(10^9 + 7)$.\n

    ", "url": "https://projecteuler.net/problem=902", "answer": "343557869"} {"id": 903, "problem": "A permutation $\\pi$ of $\\{1, \\dots, n\\}$ can be represented in one-line notation as $\\pi(1),\\ldots,\\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\\textrm{rank}(\\pi)$ is the position of $\\pi$ in this 1-based list.\n\nFor example, $\\text{rank}(2,1,3) = 3$ because the six permutations of $\\{1, 2, 3\\}$ in lexicographic order are:\n$$1, 2, 3\\quad 1, 3, 2 \\quad 2, 1, 3 \\quad 2, 3, 1 \\quad 3, 1, 2 \\quad 3, 2, 1$$\n\nLet $Q(n)$ be the sum $\\sum_{\\pi}\\sum_{i = 1}^{n!} \\text{rank}(\\pi^i)$, where $\\pi$ ranges over all permutations of $\\{1, \\dots, n\\}$, and $\\pi^i$ is the permutation arising from applying $\\pi$ $i$ times.\n\nFor example, $Q(2) = 5$, $Q(3) = 88$, $Q(6) = 133103808$ and $Q(10) \\equiv 468421536 \\pmod {10^9 + 7}$.\n\nFind $Q(10^6)$. Give your answer modulo $(10^9 + 7)$.", "raw_html": "

    A permutation $\\pi$ of $\\{1, \\dots, n\\}$ can be represented in one-line notation as $\\pi(1),\\ldots,\\pi(n) $. If all $n!$ permutations are written in lexicographic order then $\\textrm{rank}(\\pi)$ is the position of $\\pi$ in this 1-based list.

    \n\n

    For example, $\\text{rank}(2,1,3) = 3$ because the six permutations of $\\{1, 2, 3\\}$ in lexicographic order are:\n$$1, 2, 3\\quad 1, 3, 2 \\quad 2, 1, 3 \\quad 2, 3, 1 \\quad 3, 1, 2 \\quad 3, 2, 1$$\n

    \n\n

    Let $Q(n)$ be the sum $\\sum_{\\pi}\\sum_{i = 1}^{n!} \\text{rank}(\\pi^i)$, where $\\pi$ ranges over all permutations of $\\{1, \\dots, n\\}$, and $\\pi^i$ is the permutation arising from applying $\\pi$ $i$ times.

    \n\n

    For example, $Q(2) = 5$, $Q(3) = 88$, $Q(6) = 133103808$ and $Q(10) \\equiv 468421536 \\pmod {10^9 + 7}$.

    \n\n

    Find $Q(10^6)$. Give your answer modulo $(10^9 + 7)$.

    ", "url": "https://projecteuler.net/problem=903", "answer": "128553191"} {"id": 904, "problem": "Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpendicular sides is denoted by $\\theta$.\n\nLet $f(\\alpha, L)$ denote the sum of the sides of the right-angled triangle minimizing the absolute difference between $\\theta$ and $\\alpha$ among all right-angled triangles with integer sides and hypotenuse not exceeding $L$.\nIf more than one triangle attains the minimum value, the triangle with the maximum area is chosen. All angles in this problem are measured in degrees.\n\nFor example, $f(30,10^2)=198$ and $f(10,10^6)= 1600158$.\n\nDefine $F(N,L)=\\sum_{n=1}^{N}f\\left(\\sqrt[3]{n},L\\right)$.\nYou are given $F(10,10^6)= 16684370$.\n\nFind $F(45000, 10^{10})$.", "raw_html": "

    Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpendicular sides is denoted by $\\theta$.\n

    \n
    \"0904_Pythagorean_angle.jpg\"
    \n

    Let $f(\\alpha, L)$ denote the sum of the sides of the right-angled triangle minimizing the absolute difference between $\\theta$ and $\\alpha$ among all right-angled triangles with integer sides and hypotenuse not exceeding $L$.
    If more than one triangle attains the minimum value, the triangle with the maximum area is chosen. All angles in this problem are measured in degrees.\n

    \n

    \nFor example, $f(30,10^2)=198$ and $f(10,10^6)= 1600158$.\n

    \n

    \nDefine $F(N,L)=\\sum_{n=1}^{N}f\\left(\\sqrt[3]{n},L\\right)$.
    You are given $F(10,10^6)= 16684370$.

    \n

    \nFind $F(45000, 10^{10})$.

    ", "url": "https://projecteuler.net/problem=904", "answer": "880652522278760"} {"id": 905, "problem": "Three epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it. They have been informed beforehand that all three numbers are positive and that one of the numbers is the sum of the other two.\n\nOnce in the room, they can see the numbers on each other's hats but not on their own. Starting with A and proceeding cyclically, each epistemologist must either honestly state \"I don't know my number\" or announce \"Now I know my number!\" which terminates the game.\n\nFor instance, if their numbers are $A=2, B=1, C=1$ then A declares \"Now I know\" at the first turn. If their numbers are $A=2, B=7, C=5$ then \"I don't know\" is heard four times before B finally declares \"Now I know\" at the fifth turn.\n\nLet $F(A,B,C)$ be the number of turns it takes until an epistemologist declares \"Now I know\", including the turn this declaration is made. So $F(2,1,1)=1$ and $F(2,7,5)=5$.\n\nFind $\\displaystyle \\sum_{a=1}^7 \\sum_{b=1}^{19} F(a^b, b^a, a^b + b^a)$.", "raw_html": "

    \nThree epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it. They have been informed beforehand that all three numbers are positive and that one of the numbers is the sum of the other two.

    \n\n

    \nOnce in the room, they can see the numbers on each other's hats but not on their own. Starting with A and proceeding cyclically, each epistemologist must either honestly state \"I don't know my number\" or announce \"Now I know my number!\" which terminates the game.

    \n\n

    \nFor instance, if their numbers are $A=2, B=1, C=1$ then A declares \"Now I know\" at the first turn. If their numbers are $A=2, B=7, C=5$ then \"I don't know\" is heard four times before B finally declares \"Now I know\" at the fifth turn.

    \n\n

    \nLet $F(A,B,C)$ be the number of turns it takes until an epistemologist declares \"Now I know\", including the turn this declaration is made. So $F(2,1,1)=1$ and $F(2,7,5)=5$.

    \n\n

    \nFind $\\displaystyle \\sum_{a=1}^7 \\sum_{b=1}^{19} F(a^b, b^a, a^b + b^a)$.

    ", "url": "https://projecteuler.net/problem=905", "answer": "70228218"} {"id": 906, "problem": "Three friends attempt to collectively choose one of $n$ options, labeled $1,\\dots,n$, based upon their individual preferences. They choose option $i$ if for every alternative option $j$ at least two of the three friends prefer $i$ over $j$. If no such option $i$ exists they fail to reach an agreement.\n\nDefine $P(n)$ to be the probability the three friends successfully reach an agreement and choose one option, where each of the friends' individual order of preference is given by a (possibly different) random permutation of $1,\\dots,n$.\n\nYou are given $P(3)=17/18$ and $P(10)\\approx0.6760292265$.\n\nFind $P(20\\,000)$. Give your answer rounded to ten places after the decimal point.", "raw_html": "

    \nThree friends attempt to collectively choose one of $n$ options, labeled $1,\\dots,n$, based upon their individual preferences. They choose option $i$ if for every alternative option $j$ at least two of the three friends prefer $i$ over $j$. If no such option $i$ exists they fail to reach an agreement.\n

    \n

    \nDefine $P(n)$ to be the probability the three friends successfully reach an agreement and choose one option, where each of the friends' individual order of preference is given by a (possibly different) random permutation of $1,\\dots,n$.\n

    \n

    \nYou are given $P(3)=17/18$ and $P(10)\\approx0.6760292265$.\n

    \n

    \nFind $P(20\\,000)$. Give your answer rounded to ten places after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=906", "answer": "0.0195868911"} {"id": 907, "problem": "An infant's toy consists of $n$ cups, labelled $C_1,\\dots,C_n$ in increasing order of size.\n\nThe cups may be stacked in various combinations and orientations to form towers. The cups are shaped such that the following means of stacking are possible:\n\n- Nesting: $C_k$ may sit snugly inside $C_{k+1}$.\n\n- Base-to-base: $C_{k+2}$ or $C_{k-2}$ may sit, right-way-up, on top of an up-side-down $C_k$, with their bottoms fitting together snugly.\n\n- Rim-to-rim: $C_{k+2}$ or $C_{k-2}$ may sit, up-side-down, on top of a right-way-up $C_k$, with their tops fitting together snugly.\n\n- For the purposes of this problem, it is not permitted to stack both $C_{k+2}$ and $C_{k-2}$ rim-to-rim on top of $C_k$, despite the schematic diagrams appearing to allow it:\n\nDefine $S(n)$ to be the number of ways to build a single tower using all $n$ cups according to the above rules.\n\nYou are given $S(4)=12$, $S(8)=58$, and $S(20)=5560$.\n\nFind $S(10^7)$, giving your answer modulo $1\\,000\\,000\\,007$.", "raw_html": "

    \nAn infant's toy consists of $n$ cups, labelled $C_1,\\dots,C_n$ in increasing order of size.\n

    \n\"0907_four_cups.png\"\n

    \nThe cups may be stacked in various combinations and orientations to form towers. The cups are shaped such that the following means of stacking are possible:\n

    \n
      \n
    • Nesting: $C_k$ may sit snugly inside $C_{k+1}$.
      \n\"0907_nesting.png\"\n
    • \n\n
    • Base-to-base: $C_{k+2}$ or $C_{k-2}$ may sit, right-way-up, on top of an up-side-down $C_k$, with their bottoms fitting together snugly.
      \n\"0907_base_to_base.png\"\n
    • \n
    • Rim-to-rim: $C_{k+2}$ or $C_{k-2}$ may sit, up-side-down, on top of a right-way-up $C_k$, with their tops fitting together snugly.
      \n\"0907_rim_to_rim.png\"\n
    • \n
    • For the purposes of this problem, it is not permitted to stack both $C_{k+2}$ and $C_{k-2}$ rim-to-rim on top of $C_k$, despite the schematic diagrams appearing to allow it:
      \n\"0907_rim_to_rim_counter_example.png\"
      \n
    \n

    \nDefine $S(n)$ to be the number of ways to build a single tower using all $n$ cups according to the above rules.
    \nYou are given $S(4)=12$, $S(8)=58$, and $S(20)=5560$.\n

    \n

    \nFind $S(10^7)$, giving your answer modulo $1\\,000\\,000\\,007$.\n

    ", "url": "https://projecteuler.net/problem=907", "answer": "196808901"} {"id": 908, "problem": "A clock sequence is a periodic sequence of positive integers that can be broken into contiguous segments such that the sum of the $n$-th segment is equal to $n$.\n\nFor example, the sequence $$1\\ 2\\ 3\\ 4\\ 3\\ 2\\ 1\\ 2\\ 3\\ 4\\ 3\\ 2\\ 1\\ 2\\ 3\\ 4\\ 3\\ 2\\ 1\\ \\cdots$$ is a clock sequence with period $6$, as it can be broken into $$1\\Big |2\\Big |3\\Big |4\\Big |3\\ 2\\Big |1\\ 2\\ 3\\Big |4\\ 3\\Big |2\\ 1\\ 2\\ 3\\Big |4\\ 3\\ 2\\Big |1\\ 2\\ 3\\ 4\\Big |3\\ 2\\ 1\\ 2\\ 3\\Big |\\cdots$$\nLet $C(N)$ be the number of different clock sequences with period at most $N$.\nFor example, $C(3) = 3$, $C(4) = 7$ and $C(10) = 561$.\n\nFind $C(10^4) \\bmod 1111211113$.", "raw_html": "

    \nA clock sequence is a periodic sequence of positive integers that can be broken into contiguous segments such that the sum of the $n$-th segment is equal to $n$.

    \n\n

    \nFor example, the sequence $$1\\ 2\\ 3\\ 4\\ 3\\ 2\\ 1\\ 2\\ 3\\ 4\\ 3\\ 2\\ 1\\ 2\\ 3\\ 4\\ 3\\ 2\\ 1\\ \\cdots$$ is a clock sequence with period $6$, as it can be broken into $$1\\Big |2\\Big |3\\Big |4\\Big |3\\ 2\\Big |1\\ 2\\ 3\\Big |4\\ 3\\Big |2\\ 1\\ 2\\ 3\\Big |4\\ 3\\ 2\\Big |1\\ 2\\ 3\\ 4\\Big |3\\ 2\\ 1\\ 2\\ 3\\Big |\\cdots$$\nLet $C(N)$ be the number of different clock sequences with period at most $N$.\nFor example, $C(3) = 3$, $C(4) = 7$ and $C(10) = 561$.

    \n\n

    \nFind $C(10^4) \\bmod 1111211113$.

    ", "url": "https://projecteuler.net/problem=908", "answer": "451822602"} {"id": 909, "problem": "An L-expression is defined as any one of the following:\n\n- a natural number;\n\n- the symbol $A$;\n\n- the symbol $Z$;\n\n- the symbol $S$;\n\n- a pair of L-expressions $u, v$, which is written as $u(v)$.\n\nAn L-expression can be transformed according to the following rules:\n\n- $A(x) \\to x + 1$ for any natural number $x$;\n\n- $Z(u)(v) \\to v$ for any L-expressions $u, v$;\n\n- $S(u)(v)(w) \\to v(u(v)(w))$ for any L-expressions $u, v, w$.\n\nFor example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$:\n$$S(Z)(A)(0) \\to A(Z(A)(0)) \\to A(0) \\to 1.$$\nSimilarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.\n\nFind the result of the L-expression $S(S)(S(S))(S(S))(S(Z))(A)(0)$ after applying all possible rules. Give the last nine digits as your answer.\n\nNote: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.", "raw_html": "

    \nAn L-expression is defined as any one of the following:

    \n
      \n
    • a natural number;
    • \n
    • the symbol $A$;
    • \n
    • the symbol $Z$;
    • \n
    • the symbol $S$;
    • \n
    • a pair of L-expressions $u, v$, which is written as $u(v)$.
    • \n
    \n\n

    \nAn L-expression can be transformed according to the following rules:

    \n
      \n
    • $A(x) \\to x + 1$ for any natural number $x$;
    • \n
    • $Z(u)(v) \\to v$ for any L-expressions $u, v$;
    • \n
    • $S(u)(v)(w) \\to v(u(v)(w))$ for any L-expressions $u, v, w$.
    • \n
    \n

    \nFor example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$:\n$$S(Z)(A)(0) \\to A(Z(A)(0)) \\to A(0) \\to 1.$$\nSimilarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.

    \n\n

    \nFind the result of the L-expression $S(S)(S(S))(S(S))(S(Z))(A)(0)$ after applying all possible rules. Give the last nine digits as your answer.

    \n\n

    Note: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.

    ", "url": "https://projecteuler.net/problem=909", "answer": "399885292"} {"id": 910, "problem": "An L-expression is defined as any one of the following:\n\n- a natural number;\n\n- the symbol $A$;\n\n- the symbol $Z$;\n\n- the symbol $S$;\n\n- a pair of L-expressions $u, v$, which is written as $u(v)$.\n\nAn L-expression can be transformed according to the following rules:\n\n- $A(x) \\to x + 1$ for any natural number $x$;\n\n- $Z(u)(v) \\to v$ for any L-expressions $u, v$;\n\n- $S(u)(v)(w) \\to v(u(v)(w))$ for any L-expressions $u, v, w$.\n\nFor example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$:\n$$S(Z)(A)(0) \\to A(Z(A)(0)) \\to A(0) \\to 1.$$\nSimilarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.\n\nDefine the following L-expressions:\n\n- $C_0 = Z$;\n\n- $C_i = S(C_{i - 1})$ for $i \\ge 1$;\n\n- $D_i = C_i(S)(S)$.\n\nFor natural numbers $a, b, c, d, e$, let $F(a, b, c, d, e)$ denote the result of the L-expression $D_a(D_b)(D_c)(C_d)(A)(e)$ after applying all possible rules.\n\nFind the last nine digits of $F(12, 345678, 9012345, 678, 90)$.\n\nNote: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.", "raw_html": "

    \nAn L-expression is defined as any one of the following:

    \n
      \n
    • a natural number;
    • \n
    • the symbol $A$;
    • \n
    • the symbol $Z$;
    • \n
    • the symbol $S$;
    • \n
    • a pair of L-expressions $u, v$, which is written as $u(v)$.
    • \n
    \n\n

    \nAn L-expression can be transformed according to the following rules:

    \n
      \n
    • $A(x) \\to x + 1$ for any natural number $x$;
    • \n
    • $Z(u)(v) \\to v$ for any L-expressions $u, v$;
    • \n
    • $S(u)(v)(w) \\to v(u(v)(w))$ for any L-expressions $u, v, w$.
    • \n
    \n

    \nFor example, after applying all possible rules, the L-expression $S(Z)(A)(0)$ is transformed to the number $1$:\n$$S(Z)(A)(0) \\to A(Z(A)(0)) \\to A(0) \\to 1.$$\nSimilarly, the L-expression $S(S)(S(S))(S(Z))(A)(0)$ is transformed to the number $6$ after applying all possible rules.

    \n\n

    \nDefine the following L-expressions:

    \n
      \n
    • $C_0 = Z$;
    • \n
    • $C_i = S(C_{i - 1})$ for $i \\ge 1$;
    • \n
    • $D_i = C_i(S)(S)$.
    • \n
    \n\n

    \nFor natural numbers $a, b, c, d, e$, let $F(a, b, c, d, e)$ denote the result of the L-expression $D_a(D_b)(D_c)(C_d)(A)(e)$ after applying all possible rules.

    \n\n

    \nFind the last nine digits of $F(12, 345678, 9012345, 678, 90)$.

    \n\n

    Note: it can be proved that the L-expression in question can only be transformed a finite number of times, and the final result does not depend on the order of the transformations.

    ", "url": "https://projecteuler.net/problem=910", "answer": "547480666"} {"id": 911, "problem": "An irrational number $x$ can be uniquely expressed as a continued fraction $[a_0; a_1,a_2,a_3,\\dots]$:\n$$\nx=a_{0}+\\cfrac{1}{a_1+\\cfrac{1}{a_2+\\cfrac{1}{a_3+{_\\ddots}}}}\n$$where $a_0$ is an integer and $a_1,a_2,a_3,\\dots$ are positive integers.\n\nDefine $k_j(x)$ to be the geometric mean of $a_1,a_2,\\dots,a_j$.\nThat is, $k_j(x)=(a_1a_2 \\cdots a_j)^{1/j}$.\nAlso define $k_\\infty(x)=\\lim_{j\\to \\infty} k_j(x)$.\n\nKhinchin proved that almost all irrational numbers $x$ have the same value of $k_\\infty(x)\\approx2.685452\\dots$ known as Khinchin's constant. However, there are some exceptions to this rule.\n\nFor $n\\geq 0$ define\n$$\\rho_n = \\sum_{i=0}^{\\infty} \\frac{2^n}{2^{2^i}}\n$$For example $\\rho_2$, with continued fraction beginning $[3; 3, 1, 3, 4, 3, 1, 3,\\dots]$, has $k_\\infty(\\rho_2)\\approx2.059767$.\n\nFind the geometric mean of $k_{\\infty}(\\rho_n)$ for $0\\leq n\\leq 50$, giving your answer rounded to six digits after the decimal point.", "raw_html": "

    \nAn irrational number $x$ can be uniquely expressed as a continued fraction $[a_0; a_1,a_2,a_3,\\dots]$:\n$$\nx=a_{0}+\\cfrac{1}{a_1+\\cfrac{1}{a_2+\\cfrac{1}{a_3+{_\\ddots}}}}\n$$where $a_0$ is an integer and $a_1,a_2,a_3,\\dots$ are positive integers.\n

    \n

    \nDefine $k_j(x)$ to be the geometric mean of $a_1,a_2,\\dots,a_j$.
    That is, $k_j(x)=(a_1a_2 \\cdots a_j)^{1/j}$.
    Also define $k_\\infty(x)=\\lim_{j\\to \\infty} k_j(x)$.\n

    \n

    \nKhinchin proved that almost all irrational numbers $x$ have the same value of $k_\\infty(x)\\approx2.685452\\dots$ known as Khinchin's constant. However, there are some exceptions to this rule.\n

    \n

    \nFor $n\\geq 0$ define\n$$\\rho_n = \\sum_{i=0}^{\\infty} \\frac{2^n}{2^{2^i}}\n$$For example $\\rho_2$, with continued fraction beginning $[3; 3, 1, 3, 4, 3, 1, 3,\\dots]$, has $k_\\infty(\\rho_2)\\approx2.059767$.\n

    \n

    \nFind the geometric mean of $k_{\\infty}(\\rho_n)$ for $0\\leq n\\leq 50$, giving your answer rounded to six digits after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=911", "answer": "5679.934966"} {"id": 912, "problem": "Let $s_n$ be the $n$-th positive integer that does not contain three consecutive ones in its binary representation.\n\nFor example, $s_1 = 1$ and $s_7 = 8$.\n\nDefine $F(N)$ to be the sum of $n^2$ for all $n\\leq N$ where $s_n$ is odd. You are given $F(10)=199$.\n\nFind $F(10^{16})$ giving your answer modulo $10^9+7$.", "raw_html": "

    \nLet $s_n$ be the $n$-th positive integer that does not contain three consecutive ones in its binary representation.
    \nFor example, $s_1 = 1$ and $s_7 = 8$.\n

    \n

    \nDefine $F(N)$ to be the sum of $n^2$ for all $n\\leq N$ where $s_n$ is odd. You are given $F(10)=199$.\n

    \n

    \nFind $F(10^{16})$ giving your answer modulo $10^9+7$.\n

    ", "url": "https://projecteuler.net/problem=912", "answer": "674045136"} {"id": 913, "problem": "The numbers from $1$ to $12$ can be arranged into a $3 \\times 4$ matrix in either row-major or column-major order:\n$$R=\\begin{pmatrix}\n1 & 2 & 3 & 4\\\\\n5 & 6 & 7 & 8\\\\\n9 & 10 & 11 & 12\\end{pmatrix}, C=\\begin{pmatrix}\n1 & 4 & 7 & 10\\\\\n2 & 5 & 8 & 11\\\\\n3 & 6 & 9 & 12\\end{pmatrix}$$\nBy swapping two entries at a time, at least $8$ swaps are needed to transform $R$ to $C$.\n\nLet $S(n, m)$ be the minimal number of swaps needed to transform an $n\\times m$ matrix of $1$ to $nm$ from row-major order to column-major order. Thus $S(3, 4) = 8$.\n\nYou are given that the sum of $S(n, m)$ for $2 \\leq n \\leq m \\leq 100$ is $12578833$.\n\nFind the sum of $S(n^4, m^4)$ for $2 \\leq n \\leq m \\leq 100$.", "raw_html": "

    \nThe numbers from $1$ to $12$ can be arranged into a $3 \\times 4$ matrix in either row-major or column-major order:\n$$R=\\begin{pmatrix}\n1 & 2 & 3 & 4\\\\\n5 & 6 & 7 & 8\\\\\n9 & 10 & 11 & 12\\end{pmatrix}, C=\\begin{pmatrix}\n1 & 4 & 7 & 10\\\\\n2 & 5 & 8 & 11\\\\\n3 & 6 & 9 & 12\\end{pmatrix}$$\nBy swapping two entries at a time, at least $8$ swaps are needed to transform $R$ to $C$.

    \n\n

    \nLet $S(n, m)$ be the minimal number of swaps needed to transform an $n\\times m$ matrix of $1$ to $nm$ from row-major order to column-major order. Thus $S(3, 4) = 8$.

    \n\n

    \nYou are given that the sum of $S(n, m)$ for $2 \\leq n \\leq m \\leq 100$ is $12578833$.

    \n\n

    \nFind the sum of $S(n^4, m^4)$ for $2 \\leq n \\leq m \\leq 100$.

    ", "url": "https://projecteuler.net/problem=913", "answer": "2101925115560555020"} {"id": 914, "problem": "For a given integer $R$ consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with radius $R$. Define $F(R)$ to be the largest inradius of those triangles. You are given $F(100) = 36$.\n\nFind $F(10^{18})$.", "raw_html": "

    \nFor a given integer $R$ consider all primitive Pythagorean triangles that can fit inside, without touching, a circle with radius $R$. Define $F(R)$ to be the largest inradius of those triangles. You are given $F(100) = 36$.

    \n

    \nFind $F(10^{18})$.

    ", "url": "https://projecteuler.net/problem=914", "answer": "414213562371805310"} {"id": 915, "problem": "The function $s(n)$ is defined recursively for positive integers by\n$s(1) = 1$ and $s(n+1) = \\big(s(n) - 1\\big)^3 +2$ for $n\\geq 1$.\n\nThe sequence begins: $s(1) = 1, s(2) = 2, s(3) = 3, s(4) = 10, \\ldots$.\n\nFor positive integers $N$, define $$T(N) = \\sum_{a=1}^N \\sum_{b=1}^N \\gcd\\Big(s\\big(s(a)\\big), s\\big(s(b)\\big)\\Big).$$ You are given $T(3) = 12$, $T(4) \\equiv 24881925$ and $T(100)\\equiv 14416749$ both modulo $123456789$.\n\nFind $T(10^8)$. Give your answer modulo $123456789$.", "raw_html": "

    \nThe function $s(n)$ is defined recursively for positive integers by \n$s(1) = 1$ and $s(n+1) = \\big(s(n) - 1\\big)^3 +2$ for $n\\geq 1$.
    \nThe sequence begins: $s(1) = 1, s(2) = 2, s(3) = 3, s(4) = 10, \\ldots$.

    \n\n

    \nFor positive integers $N$, define $$T(N) = \\sum_{a=1}^N \\sum_{b=1}^N \\gcd\\Big(s\\big(s(a)\\big), s\\big(s(b)\\big)\\Big).$$ You are given $T(3) = 12$, $T(4) \\equiv 24881925$ and $T(100)\\equiv 14416749$ both modulo $123456789$.

    \n\n

    \nFind $T(10^8)$. Give your answer modulo $123456789$.

    ", "url": "https://projecteuler.net/problem=915", "answer": "55601924"} {"id": 916, "problem": "Let $P(n)$ be the number of permutations of $\\{1,2,3,\\ldots,2n\\}$ such that:\n\n1. There is no ascending subsequence with more than $n+1$ elements, and\n\n2. There is no descending subsequence with more than two elements.\n\nNote that subsequences need not be contiguous. For example, the permutation $(4,1,3,2)$ is not counted because it has a descending subsequence of three elements: $(4,3,2)$. You are given $P(2)=13$ and $P(10) \\equiv 45265702 \\pmod{10^9 + 7}$.\n\nFind $P(10^8)$ and give your answer modulo $10^9 + 7$.", "raw_html": "

    Let $P(n)$ be the number of permutations of $\\{1,2,3,\\ldots,2n\\}$ such that:\n
    \n1. There is no ascending subsequence with more than $n+1$ elements, and\n
    \n2. There is no descending subsequence with more than two elements.\n

    \n\n

    Note that subsequences need not be contiguous. For example, the permutation $(4,1,3,2)$ is not counted because it has a descending subsequence of three elements: $(4,3,2)$. You are given $P(2)=13$ and $P(10) \\equiv 45265702 \\pmod{10^9 + 7}$.

    \n\n

    Find $P(10^8)$ and give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=916", "answer": "877789135"} {"id": 917, "problem": "The sequence $s_n$ is defined by $s_1 = 102022661$ and $s_n = s_{n-1}^2 \\bmod {998388889}$ for $n > 1$.\n\nLet $a_n = s_{2n - 1}$ and $b_n = s_{2n}$ for $n=1,2,...$\n\nDefine an $N \\times N$ matrix whose values are $M_{i,j} = a_i + b_j$.\n\nLet $A(N)$ be the minimal path sum from $M_{1,1}$ (top left) to $M_{N,N}$ (bottom right), where each step is either right or down.\n\nYou are given $A(1) = 966774091$, $A(2) = 2388327490$ and $A(10) = 13389278727$.\n\nFind $A(10^7)$.", "raw_html": "

    The sequence $s_n$ is defined by $s_1 = 102022661$ and $s_n = s_{n-1}^2 \\bmod {998388889}$ for $n > 1$.

    \n\n

    Let $a_n = s_{2n - 1}$ and $b_n = s_{2n}$ for $n=1,2,...$

    \n\n

    Define an $N \\times N$ matrix whose values are $M_{i,j} = a_i + b_j$.

    \n\n

    Let $A(N)$ be the minimal path sum from $M_{1,1}$ (top left) to $M_{N,N}$ (bottom right), where each step is either right or down.

    \n\n

    You are given $A(1) = 966774091$, $A(2) = 2388327490$ and $A(10) = 13389278727$.

    \n\n

    Find $A(10^7)$.

    ", "url": "https://projecteuler.net/problem=917", "answer": "9986212680734636"} {"id": 918, "problem": "The sequence $a_n$ is defined by $a_1=1$, and then recursively for $n\\geq1$:\n$$\\begin{align*}\na_{2n} &=2a_n\\\\\na_{2n+1} &=a_n-3a_{n+1}\n\\end{align*}$$\nThe first ten terms are $1, 2, -5, 4, 17, -10, -17, 8, -47, 34$.\n\nDefine $\\displaystyle S(N) = \\sum_{n=1}^N a_n$. You are given $S(10) = -13$.\n\nFind $S(10^{12})$.", "raw_html": "

    \nThe sequence $a_n$ is defined by $a_1=1$, and then recursively for $n\\geq1$:\n$$\\begin{align*}\na_{2n} &=2a_n\\\\\na_{2n+1} &=a_n-3a_{n+1}\n\\end{align*}$$\nThe first ten terms are $1, 2, -5, 4, 17, -10, -17, 8, -47, 34$.
    \nDefine $\\displaystyle S(N) = \\sum_{n=1}^N a_n$. You are given $S(10) = -13$.
    \nFind $S(10^{12})$.\n

    ", "url": "https://projecteuler.net/problem=918", "answer": "-6999033352333308"} {"id": 919, "problem": "We call a triangle fortunate if it has integral sides and at least one of its vertices has the property that the distance from it to the triangle's orthocentre is exactly half the distance from the same vertex to the triangle's circumcentre.\n\nTriangle $ABC$ above is an example of a fortunate triangle with sides $(6,7,8)$. The distance from the vertex $C$ to the circumcentre $O$ is $\\approx 4.131182$, while the distance from $C$ to the orthocentre $H$ is half that, at $\\approx 2.065591$.\n\nDefine $S(P)$ to be the sum of $a+b+c$ over all fortunate triangles with sides $a\\leq b\\leq c$ and perimeter not exceeding $P$.\n\nFor example $S(10)=24$, arising from three triangles with sides $(1,2,2)$, $(2,3,4)$, and $(2,4,4)$. You are also given $S(100)=3331$.\n\nFind $S(10^7)$.", "raw_html": "

    We call a triangle fortunate if it has integral sides and at least one of its vertices has the property that the distance from it to the triangle's orthocentre is exactly half the distance from the same vertex to the triangle's circumcentre.

    \n
    \"0919_remarkablediagram.jpg\"
    \n

    \nTriangle $ABC$ above is an example of a fortunate triangle with sides $(6,7,8)$. The distance from the vertex $C$ to the circumcentre $O$ is $\\approx 4.131182$, while the distance from $C$ to the orthocentre $H$ is half that, at $\\approx 2.065591$.\n

    \n

    \nDefine $S(P)$ to be the sum of $a+b+c$ over all fortunate triangles with sides $a\\leq b\\leq c$ and perimeter not exceeding $P$.\n

    \n

    \nFor example $S(10)=24$, arising from three triangles with sides $(1,2,2)$, $(2,3,4)$, and $(2,4,4)$. You are also given $S(100)=3331$.\n

    \n

    \nFind $S(10^7)$.\n

    ", "url": "https://projecteuler.net/problem=919", "answer": "134222859969633"} {"id": 920, "problem": "For a positive integer $n$ we define $\\tau(n)$ to be the count of the divisors of $n$. For example, the divisors of $12$ are $\\{1,2,3,4,6,12\\}$ and so $\\tau(12) = 6$.\n\nA positive integer $n$ is a tau number if it is divisible by $\\tau(n)$. For example $\\tau(12)=6$ and $6$ divides $12$ so $12$ is a tau number.\n\nLet $m(k)$ be the smallest tau number $x$ such that $\\tau(x) = k$. For example, $m(8) = 24$, $m(12)=60$ and $m(16)=384$.\n\nFurther define $M(n)$ to be the sum of all $m(k)$ whose values do not exceed $10^n$. You are given $M(3) = 3189$.\n\nFind $M(16)$.", "raw_html": "

    For a positive integer $n$ we define $\\tau(n)$ to be the count of the divisors of $n$. For example, the divisors of $12$ are $\\{1,2,3,4,6,12\\}$ and so $\\tau(12) = 6$.

    \n\n

    \nA positive integer $n$ is a tau number if it is divisible by $\\tau(n)$. For example $\\tau(12)=6$ and $6$ divides $12$ so $12$ is a tau number.

    \n\n

    \nLet $m(k)$ be the smallest tau number $x$ such that $\\tau(x) = k$. For example, $m(8) = 24$, $m(12)=60$ and $m(16)=384$.

    \n\n

    \nFurther define $M(n)$ to be the sum of all $m(k)$ whose values do not exceed $10^n$. You are given $M(3) = 3189$.

    \n\n

    \nFind $M(16)$.

    ", "url": "https://projecteuler.net/problem=920", "answer": "1154027691000533893"} {"id": 921, "problem": "Consider the following recurrence relation:\n$$\\begin{align}\na_0 &= \\frac{\\sqrt 5 + 1}2\\\\\na_{n+1} &= \\dfrac{a_n(a_n^4 + 10a_n^2 + 5)}{5a_n^4 + 10a_n^2 + 1}\n\\end{align}$$\n\nNote that $a_0$ is the golden ratio.\n\n$a_n$ can always be written in the form $\\dfrac{p_n\\sqrt{5}+1}{q_n}$, where $p_n$ and $q_n$ are positive integers.\n\nLet $s(n)=p_n^5+q_n^5$. So, $s(0)=1^5+2^5=33$.\n\nThe Fibonacci sequence is defined as: $F_1=1$, $F_2=1$, $F_n=F_{n-1}+F_{n-2}$ for $n > 2$.\n\nDefine $\\displaystyle S(m)=\\sum_{i=2}^{m}s(F_i)$.\n\nFind $S(1618034)$. Submit your answer modulo $398874989$.", "raw_html": "

    Consider the following recurrence relation:\n$$\\begin{align}\na_0 &= \\frac{\\sqrt 5 + 1}2\\\\\na_{n+1} &= \\dfrac{a_n(a_n^4 + 10a_n^2 + 5)}{5a_n^4 + 10a_n^2 + 1}\n\\end{align}$$

    \n\n

    \nNote that $a_0$ is the golden ratio.

    \n\n

    \n$a_n$ can always be written in the form $\\dfrac{p_n\\sqrt{5}+1}{q_n}$, where $p_n$ and $q_n$ are positive integers.

    \n\n

    \nLet $s(n)=p_n^5+q_n^5$. So, $s(0)=1^5+2^5=33$.

    \n\n

    \nThe Fibonacci sequence is defined as: $F_1=1$, $F_2=1$, $F_n=F_{n-1}+F_{n-2}$ for $n > 2$.

    \n\n

    \nDefine $\\displaystyle S(m)=\\sum_{i=2}^{m}s(F_i)$.

    \n\n

    \nFind $S(1618034)$. Submit your answer modulo $398874989$.

    ", "url": "https://projecteuler.net/problem=921", "answer": "378401935"} {"id": 922, "problem": "A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that\n\n- the left-most squares of all rows are aligned vertically;\n\n- the top squares of all columns are aligned horizontally;\n\n- the rows are non-increasing in size as we move top to bottom;\n\n- the columns are non-increasing in size as we move left to right.\n\nTwo examples of Young diagrams are shown below.\n\nTwo players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it any number of squares to the right. On Down's turn, Down selects a token on one diagram and moves it any number of squares downwards. A player unable to make a legal move on their turn loses the game.\n\nFor $a,b,k\\geq 1$ we define an $(a,b,k)$-staircase to be the Young diagram where the bottom-right frontier consists of $k$ steps of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$.\n\nAdditionally, define the weight of an $(a,b,k)$-staircase to be $a+b+k$.\n\nLet $R(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately.\n\nFor example, $R(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions.\n\nYou are also given $R(3, 9)=314104$.\n\nFind $R(8, 64)$ giving your answer modulo $10^9+7$.", "raw_html": "

    \nA Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that

    \n
      \n
    • the left-most squares of all rows are aligned vertically;\n
    • the top squares of all columns are aligned horizontally;\n
    • the rows are non-increasing in size as we move top to bottom;\n
    • the columns are non-increasing in size as we move left to right.\n
    \n

    \nTwo examples of Young diagrams are shown below.

    \n
    \n\"0922_youngs_game_diagrams.png\"
    \n

    \nTwo players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it any number of squares to the right. On Down's turn, Down selects a token on one diagram and moves it any number of squares downwards. A player unable to make a legal move on their turn loses the game.

    \n\n

    \nFor $a,b,k\\geq 1$ we define an $(a,b,k)$-staircase to be the Young diagram where the bottom-right frontier consists of $k$ steps of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$.

    \n
    \n\"0922_youngs_game_staircases.png\"
    \n

    \nAdditionally, define the weight of an $(a,b,k)$-staircase to be $a+b+k$.

    \n\n

    \nLet $R(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately.

    \n\n

    \nFor example, $R(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions.

    \n
    \n\"0922_youngs_game_example.png\"
    \n\n

    \nYou are also given $R(3, 9)=314104$.

    \n\n

    \nFind $R(8, 64)$ giving your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=922", "answer": "858945298"} {"id": 923, "problem": "A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that\n\n- the left-most squares of all rows are aligned vertically;\n\n- the top squares of all columns are aligned horizontally;\n\n- the rows are non-increasing in size as we move top to bottom;\n\n- the columns are non-increasing in size as we move left to right.\n\nTwo examples of Young diagrams are shown below.\n\nTwo players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it one square to the right. On Down's turn, Down selects a token on one diagram and moves it one square downwards. A player unable to make a legal move on their turn loses the game.\n\nFor $a,b,k\\geq 1$ we define an $(a,b,k)$-staircase to be the Young diagram where the bottom-right frontier consists of $k$ steps of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$.\n\nAdditionally, define the weight of an $(a,b,k)$-staircase to be $a+b+k$.\n\nLet $S(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately.\n\nFor example, $S(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions.\n\nYou are also given $S(3, 9)=315319$.\n\nFind $S(8, 64)$ giving your answer modulo $10^9+7$.", "raw_html": "

    \nA Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such that

    \n
      \n
    • the left-most squares of all rows are aligned vertically;\n
    • the top squares of all columns are aligned horizontally;\n
    • the rows are non-increasing in size as we move top to bottom;\n
    • the columns are non-increasing in size as we move left to right.\n
    \n

    \nTwo examples of Young diagrams are shown below.

    \n
    \n\"0922_youngs_game_diagrams.png\"
    \n

    \nTwo players Right and Down play a game on several Young diagrams, all disconnected from each other. Initially, a token is placed in the top-left square of each diagram. Then they take alternating turns, starting with Right. On Right's turn, Right selects a token on one diagram and moves it one square to the right. On Down's turn, Down selects a token on one diagram and moves it one square downwards. A player unable to make a legal move on their turn loses the game.

    \n\n

    \nFor $a,b,k\\geq 1$ we define an $(a,b,k)$-staircase to be the Young diagram where the bottom-right frontier consists of $k$ steps of vertical height $a$ and horizontal length $b$. Shown below are four examples of staircases with $(a,b,k)$ respectively $(1,1,4),$ $(5,1,1),$ $(3,3,2),$ $(2,4,3)$.

    \n
    \n\"0922_youngs_game_staircases.png\"
    \n

    \nAdditionally, define the weight of an $(a,b,k)$-staircase to be $a+b+k$.

    \n\n

    \nLet $S(m, w)$ be the number ways of choosing $m$ staircases, each having weight not exceeding $w$, upon which Right (moving first in the game) will win the game assuming optimal play. Different orderings of the same set of staircases are to be counted separately.

    \n\n

    \nFor example, $S(2, 4)=7$ is illustrated below, with tokens as grey circles drawn in their initial positions.

    \n
    \n\"0922_youngs_game_example.png\"
    \n\n

    \nYou are also given $S(3, 9)=315319$.

    \n\n

    \nFind $S(8, 64)$ giving your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=923", "answer": "740759929"} {"id": 924, "problem": "Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$.\n\nDefine $a_0 = 0$ and $a_n = a_{n - 1}^2 + 2$ for $n>0$.\nLet $\\displaystyle U(N) = \\sum_{n = 1}^N B(a_n)$. You are given $U(10) \\equiv 543870437 \\pmod{10^9+7}$.\n\nFind $U(10^{16})$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$.

    \n\n

    Define $a_0 = 0$ and $a_n = a_{n - 1}^2 + 2$ for $n>0$.\nLet $\\displaystyle U(N) = \\sum_{n = 1}^N B(a_n)$. You are given $U(10) \\equiv 543870437 \\pmod{10^9+7}$.

    \n\n

    Find $U(10^{16})$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=924", "answer": "811141860"} {"id": 925, "problem": "Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$.\n\nDefine $\\displaystyle T(N) = \\sum_{n=1}^N B(n^2)$. You are given $T(10)=270$ and $T(100)=335316$.\n\nFind $T(10^{16})$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    Let $B(n)$ be the smallest number larger than $n$ that can be formed by rearranging digits of $n$, or $0$ if no such number exists. For example, $B(245) = 254$ and $B(542) = 0$.

    \n\n

    Define $\\displaystyle T(N) = \\sum_{n=1}^N B(n^2)$. You are given $T(10)=270$ and $T(100)=335316$.

    \n\n

    Find $T(10^{16})$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=925", "answer": "400034379"} {"id": 926, "problem": "A round number is a number that ends with one or more zeros in a given base.\n\nLet us define the roundness of a number $n$ in base $b$ as the number of zeros at the end of the base $b$ representation of $n$.\n\nFor example, $20$ has roundness $2$ in base $2$, because the base $2$ representation of $20$ is $10100$, which ends with $2$ zeros.\n\nAlso define $R(n)$, the total roundness of a number $n$, as the sum of the roundness of $n$ in base $b$ for all $b > 1$.\n\nFor example, $20$ has roundness $2$ in base $2$ and roundness $1$ in base $4$, $5$, $10$, $20$, hence we get $R(20)=6$.\n\nYou are also given $R(10!) = 312$.\n\nFind $R(10\\,000\\,000!)$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    \nA round number is a number that ends with one or more zeros in a given base.

    \n\n

    \nLet us define the roundness of a number $n$ in base $b$ as the number of zeros at the end of the base $b$ representation of $n$.
    \nFor example, $20$ has roundness $2$ in base $2$, because the base $2$ representation of $20$ is $10100$, which ends with $2$ zeros.

    \n\n

    \nAlso define $R(n)$, the total roundness of a number $n$, as the sum of the roundness of $n$ in base $b$ for all $b > 1$.
    \nFor example, $20$ has roundness $2$ in base $2$ and roundness $1$ in base $4$, $5$, $10$, $20$, hence we get $R(20)=6$.
    \nYou are also given $R(10!) = 312$.

    \n\n

    \nFind $R(10\\,000\\,000!)$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=926", "answer": "40410219"} {"id": 927, "problem": "A full $k$-ary tree is a tree with a single root node, such that every node is either a leaf or has exactly $k$ ordered children. The height of a $k$-ary tree is the number of edges in the longest path from the root to a leaf.\n\nFor instance, there is one full 3-ary tree of height 0, one full 3-ary tree of height 1, and seven full 3-ary trees of height 2. These seven are shown below.\n\nFor integers $n$ and $k$ with $n\\ge 0$ and $k \\ge 2$, define $t_k(n)$ to be the number of full $k$-ary trees of height $n$ or less.\n\nThus, $t_3(0) = 1$, $t_3(1) = 2$, and $t_3(2) = 9$. Also, $t_2(0) = 1$, $t_2(1) = 2$, and $t_2(2) = 5$.\n\nDefine $S_k$ to be the set of positive integers $m$ such that $m$ divides $t_k(n)$ for some integer $n\\ge 0$. For instance, the above values show that 1, 2, and 5 are in $S_2$ and 1, 2, 3, and 9 are in $S_3$.\n\nLet $S = \\bigcap_p S_p$ where the intersection is taken over all primes $p$. Finally, define $R(N)$ to be the sum of all elements of $S$ not exceeding $N$. You are given that $R(20) = 18$ and $R(1000) = 2089$.\n\nFind $R(10^7)$.", "raw_html": "

    A full $k$-ary tree is a tree with a single root node, such that every node is either a leaf or has exactly $k$ ordered children. The height of a $k$-ary tree is the number of edges in the longest path from the root to a leaf.

    \n\n

    \nFor instance, there is one full 3-ary tree of height 0, one full 3-ary tree of height 1, and seven full 3-ary trees of height 2. These seven are shown below.

    \n\n\"0927_PrimeTrees.jpg\"\n

    \nFor integers $n$ and $k$ with $n\\ge 0$ and $k \\ge 2$, define $t_k(n)$ to be the number of full $k$-ary trees of height $n$ or less.
    \nThus, $t_3(0) = 1$, $t_3(1) = 2$, and $t_3(2) = 9$. Also, $t_2(0) = 1$, $t_2(1) = 2$, and $t_2(2) = 5$.

    \n\n

    \nDefine $S_k$ to be the set of positive integers $m$ such that $m$ divides $t_k(n)$ for some integer $n\\ge 0$. For instance, the above values show that 1, 2, and 5 are in $S_2$ and 1, 2, 3, and 9 are in $S_3$.

    \n\n

    \nLet $S = \\bigcap_p S_p$ where the intersection is taken over all primes $p$. Finally, define $R(N)$ to be the sum of all elements of $S$ not exceeding $N$. You are given that $R(20) = 18$ and $R(1000) = 2089$.

    \n\n

    \nFind $R(10^7)$.

    ", "url": "https://projecteuler.net/problem=927", "answer": "207282955"} {"id": 928, "problem": "This problem is based on (but not identical to) the scoring for the card game\nCribbage.\n\nConsider a normal pack of $52$ cards. A Hand is a selection of one or more of these cards.\n\nFor each Hand the Hand score is the sum of the values of the cards in the Hand where the value of Aces is $1$ and the value of court cards (Jack, Queen, King) is $10$.\n\nThe Cribbage score is obtained for a Hand by adding together the scores for:\n\n-\nPairs. A pair is two cards of the same rank. Every pair is worth $2$ points.\n\n-\nRuns. A run is a set of at least $3$ cards whose ranks are consecutive, e.g. 9, 10, Jack. Note that Ace is never high, so Queen, King, Ace is not a valid run. The number of points for each run is the size of the run. All locally maximum runs are counted. For example, 2, 3, 4, 5, 7, 8, 9 the two runs of 2, 3, 4, 5 and 7, 8, 9 are counted but not 2, 3, 4 or 3, 4, 5.\n\n-\nFifteens. A fifteen is a combination of cards that has value adding to $15$. Every fifteen is worth $2$ points. For this purpose the value of the cards is the same as in the Hand Score.\n\nFor example, $(5 \\spadesuit, 5 \\clubsuit, 5 \\diamondsuit, K \\heartsuit)$ has a Cribbage score of $14$ as there are four ways that fifteen can be made and also three pairs can be made.\n\nThe example $( A \\diamondsuit, A \\heartsuit, 2 \\clubsuit, 3 \\heartsuit, 4 \\clubsuit, 5 \\spadesuit)$ has a Cribbage score of $16$: two runs of five worth $10$ points, two ways of getting fifteen worth $4$ points and one pair worth $2$ points. In this example the Hand score is equal to the Cribbage score.\n\nFind the number of Hands in a normal pack of cards where the Hand score is equal to the Cribbage score.", "raw_html": "

    This problem is based on (but not identical to) the scoring for the card game \nCribbage.

    \n\n

    \nConsider a normal pack of $52$ cards. A Hand is a selection of one or more of these cards.

    \n\n

    \nFor each Hand the Hand score is the sum of the values of the cards in the Hand where the value of Aces is $1$ and the value of court cards (Jack, Queen, King) is $10$.

    \n\n

    \nThe Cribbage score is obtained for a Hand by adding together the scores for:

    \n
      \n
    • \nPairs. A pair is two cards of the same rank. Every pair is worth $2$ points.
    • \n\n
    • \nRuns. A run is a set of at least $3$ cards whose ranks are consecutive, e.g. 9, 10, Jack. Note that Ace is never high, so Queen, King, Ace is not a valid run. The number of points for each run is the size of the run. All locally maximum runs are counted. For example, 2, 3, 4, 5, 7, 8, 9 the two runs of 2, 3, 4, 5 and 7, 8, 9 are counted but not 2, 3, 4 or 3, 4, 5.
    • \n\n
    • \nFifteens. A fifteen is a combination of cards that has value adding to $15$. Every fifteen is worth $2$ points. For this purpose the value of the cards is the same as in the Hand Score.
    \n\n

    \nFor example, $(5 \\spadesuit, 5 \\clubsuit, 5 \\diamondsuit, K \\heartsuit)$ has a Cribbage score of $14$ as there are four ways that fifteen can be made and also three pairs can be made.

    \n\n

    \nThe example $( A \\diamondsuit, A \\heartsuit, 2 \\clubsuit, 3 \\heartsuit, 4 \\clubsuit, 5 \\spadesuit)$ has a Cribbage score of $16$: two runs of five worth $10$ points, two ways of getting fifteen worth $4$ points and one pair worth $2$ points. In this example the Hand score is equal to the Cribbage score.

    \n\n

    \nFind the number of Hands in a normal pack of cards where the Hand score is equal to the Cribbage score.

    ", "url": "https://projecteuler.net/problem=928", "answer": "81108001093"} {"id": 929, "problem": "A composition of $n$ is a sequence of positive integers which sum to $n$. Such a sequence can be split into runs, where a run is a maximal contiguous subsequence of equal terms.\n\nFor example, $2,2,1,1,1,3,2,2$ is a composition of $14$ consisting of four runs:\n\n$2, 2\\quad 1, 1, 1\\quad 3 \\quad 2, 2$\n\nLet $F(n)$ be the number of compositions of $n$ where every run has odd length.\n\nFor example, $F(5)=10$:\n\n$$\\begin{align*}\n& 5 &&4,1 && 3,2 &&2,3 &&2,1,2\\\\\n&2,1,1,1 &&1,4 &&1,3,1 &&1,1,1,2 &&1,1,1,1,1\n\\end{align*}$$\nFind $F(10^5)$. Give your answer modulo $1111124111$.", "raw_html": "

    A composition of $n$ is a sequence of positive integers which sum to $n$. Such a sequence can be split into runs, where a run is a maximal contiguous subsequence of equal terms.

    \n\n

    For example, $2,2,1,1,1,3,2,2$ is a composition of $14$ consisting of four runs:

    \n
    $2, 2\\quad 1, 1, 1\\quad 3 \\quad 2, 2$
    \n\n

    Let $F(n)$ be the number of compositions of $n$ where every run has odd length.

    \n\n

    For example, $F(5)=10$:

    \n$$\\begin{align*}\n& 5 &&4,1 && 3,2 &&2,3 &&2,1,2\\\\\n&2,1,1,1 &&1,4 &&1,3,1 &&1,1,1,2 &&1,1,1,1,1\n\\end{align*}$$\n

    Find $F(10^5)$. Give your answer modulo $1111124111$.

    ", "url": "https://projecteuler.net/problem=929", "answer": "57322484"} {"id": 930, "problem": "Given $n\\ge 2$ bowls arranged in a circle, $m\\ge 2$ balls are distributed amongst them.\n\nInitially the balls are distributed randomly: for each ball, a bowl is chosen equiprobably and independently of the other balls. After this is done, we start the following process:\n\n- Choose one of the $m$ balls equiprobably at random.\n\n- Choose a direction to move - either clockwise or anticlockwise - again equiprobably at random.\n\n- Move the chosen ball to the neighbouring bowl in the chosen direction.\n\n- Return to step 1.\n\nThis process stops when all the $m$ balls are located in the same bowl. Note that this may be after zero steps, if the balls happen to have been initially distributed all in the same bowl.\n\nLet $F(n, m)$ be the expected number of times we move a ball before the process stops. For example, $F(2, 2) = \\frac{1}{2}$, $F(3, 2) = \\frac{4}{3}$, $F(2, 3) = \\frac{9}{4}$, and $F(4, 5) = \\frac{6875}{24}$.\n\nLet $G(N, M) = \\sum_{n=2}^N \\sum_{m=2}^M F(n, m)$. For example, $G(3, 3) = \\frac{137}{12}$ and $G(4, 5) = \\frac{6277}{12}$. You are also given that $G(6, 6) \\approx 1.681521567954e4$ in scientific format with 12 significant digits after the decimal point.\n\nFind $G(12, 12)$. Give your answer in scientific format with 12 significant digits after the decimal point.", "raw_html": "

    Given $n\\ge 2$ bowls arranged in a circle, $m\\ge 2$ balls are distributed amongst them.

    \n\n

    Initially the balls are distributed randomly: for each ball, a bowl is chosen equiprobably and independently of the other balls. After this is done, we start the following process:

    \n
      \n
    1. Choose one of the $m$ balls equiprobably at random.
    2. \n
    3. Choose a direction to move - either clockwise or anticlockwise - again equiprobably at random.
    4. \n
    5. Move the chosen ball to the neighbouring bowl in the chosen direction.
    6. \n
    7. Return to step 1.
    8. \n
    \n\n

    This process stops when all the $m$ balls are located in the same bowl. Note that this may be after zero steps, if the balls happen to have been initially distributed all in the same bowl.

    \n\n

    Let $F(n, m)$ be the expected number of times we move a ball before the process stops. For example, $F(2, 2) = \\frac{1}{2}$, $F(3, 2) = \\frac{4}{3}$, $F(2, 3) = \\frac{9}{4}$, and $F(4, 5) = \\frac{6875}{24}$.

    \n\n

    Let $G(N, M) = \\sum_{n=2}^N \\sum_{m=2}^M F(n, m)$. For example, $G(3, 3) = \\frac{137}{12}$ and $G(4, 5) = \\frac{6277}{12}$. You are also given that $G(6, 6) \\approx 1.681521567954e4$ in scientific format with 12 significant digits after the decimal point.

    \n\n

    Find $G(12, 12)$. Give your answer in scientific format with 12 significant digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=930", "answer": "1.345679959251e12"} {"id": 931, "problem": "For a positive integer $n$ construct a graph using all the divisors of $n$ as the vertices. An edge is drawn between $a$ and $b$ if $a$ is divisible by $b$ and $a/b$ is prime, and is given weight $\\phi(a)-\\phi(b)$, where $\\phi$ is the Euler totient function.\nDefine $t(n)$ to be the total weight of this graph.\n\nThe example below shows that $t(45) = 52$\n\nLet $T(N)=\\displaystyle\\sum_{n=1}^{N} t(n)$. You are given $T(10)=26$ and $T(10^2)=5282$.\n\nFind $T(10^{12})$. Give your answer modulo $715827883$.", "raw_html": "

    \nFor a positive integer $n$ construct a graph using all the divisors of $n$ as the vertices. An edge is drawn between $a$ and $b$ if $a$ is divisible by $b$ and $a/b$ is prime, and is given weight $\\phi(a)-\\phi(b)$, where $\\phi$ is the Euler totient function.
    Define $t(n)$ to be the total weight of this graph.
    \nThe example below shows that $t(45) = 52$\n

    \n\"0931_totientgraph.png\"\n

    \nLet $T(N)=\\displaystyle\\sum_{n=1}^{N} t(n)$. You are given $T(10)=26$ and $T(10^2)=5282$.\n

    \n

    \nFind $T(10^{12})$. Give your answer modulo $715827883$.\n

    ", "url": "https://projecteuler.net/problem=931", "answer": "128856311"} {"id": 932, "problem": "For the year $2025$\n\n$$2025 = (20 + 25)^2$$\nGiven positive integers $a$ and $b$, the concatenation $ab$ we call a $2025$-number if $ab = (a+b)^2$.\n\nOther examples are $3025$ and $81$.\n\nNote $9801$ is not a $2025$-number because the concatenation of $98$ and $1$ is $981$.\n\nLet $T(n)$ be the sum of all $2025$-numbers with $n$ digits or less. You are given $T(4) = 5131$.\n\nFind $T(16)$.", "raw_html": "

    For the year $2025$

    \n$$2025 = (20 + 25)^2$$\n

    Given positive integers $a$ and $b$, the concatenation $ab$ we call a $2025$-number if $ab = (a+b)^2$.
    \nOther examples are $3025$ and $81$.
    \nNote $9801$ is not a $2025$-number because the concatenation of $98$ and $1$ is $981$.

    \n\n

    \nLet $T(n)$ be the sum of all $2025$-numbers with $n$ digits or less. You are given $T(4) = 5131$.

    \n\n

    \nFind $T(16)$.

    ", "url": "https://projecteuler.net/problem=932", "answer": "72673459417881349"} {"id": 933, "problem": "Starting with one piece of integer-sized rectangle paper, two players make moves in turn.\n\nA valid move consists of choosing one piece of paper and cutting it both horizontally and vertically, so that it becomes four pieces of smaller rectangle papers, all of which are integer-sized.\n\nThe player that does not have a valid move loses the game.\n\nLet $C(w, h)$ be the number of winning moves for the first player, when the original paper has size $w \\times h$. For example, $C(5,3)=4$, with the four winning moves shown below.\n\nAlso write $\\displaystyle D(W, H) = \\sum_{w = 2}^W\\sum_{h = 2}^H C(w, h)$. You are given that $D(12, 123) = 327398$.\n\nFind $D(123, 1234567)$.", "raw_html": "

    \nStarting with one piece of integer-sized rectangle paper, two players make moves in turn.
    \nA valid move consists of choosing one piece of paper and cutting it both horizontally and vertically, so that it becomes four pieces of smaller rectangle papers, all of which are integer-sized.
    \nThe player that does not have a valid move loses the game.

    \n\n

    \nLet $C(w, h)$ be the number of winning moves for the first player, when the original paper has size $w \\times h$. For example, $C(5,3)=4$, with the four winning moves shown below.

    \n
    \"0933_PaperCutting2.jpg\"
    \n

    \nAlso write $\\displaystyle D(W, H) = \\sum_{w = 2}^W\\sum_{h = 2}^H C(w, h)$. You are given that $D(12, 123) = 327398$.

    \n\n

    \nFind $D(123, 1234567)$.

    ", "url": "https://projecteuler.net/problem=933", "answer": "5707485980743099"} {"id": 934, "problem": "We define the unlucky prime of a number $n$, denoted $u(n)$, as the smallest prime number $p$ such that the remainder of $n$ divided by $p$ (i.e. $n \\bmod p$) is not a multiple of seven.\n\nFor example, $u(14) = 3$, $u(147) = 2$ and $u(1470) = 13$.\n\nLet $U(N)$ be the sum $\\sum_{n = 1}^N u(n)$.\n\nYou are given $U(1470) = 4293$.\n\nFind $U(10^{17})$.", "raw_html": "

    We define the unlucky prime of a number $n$, denoted $u(n)$, as the smallest prime number $p$ such that the remainder of $n$ divided by $p$ (i.e. $n \\bmod p$) is not a multiple of seven.
    \nFor example, $u(14) = 3$, $u(147) = 2$ and $u(1470) = 13$.

    \n\n

    Let $U(N)$ be the sum $\\sum_{n = 1}^N u(n)$.
    \nYou are given $U(1470) = 4293$.

    \n\n

    Find $U(10^{17})$.

    ", "url": "https://projecteuler.net/problem=934", "answer": "292137809490441370"} {"id": 935, "problem": "A square of side length $b<1$ is rolling around the inside of a larger square of side length $1$, always touching the larger square but without sliding.\n\nInitially the two squares share a common corner. At each step, the small square rotates clockwise about a corner that touches the large square, until another of its corners touches the large square. Here is an illustration of the first three steps for $b = \\frac5{13}$.\n\nFor some values of $b$, the small square may return to its initial position after several steps. For example, when $b = \\frac12$, this happens in $4$ steps; and for $b = \\frac5{13}$ it happens in $24$ steps.\n\nLet $F(N)$ be the number of different values of $b$ for which the small square first returns to its initial position within at most $N$ steps. For example, $F(6) = 4$, with the corresponding $b$ values:\n$$\\frac12,\\quad 2 - \\sqrt 2,\\quad 2 + \\sqrt 2 - \\sqrt{2 + 4\\sqrt2},\\quad 8 - 5\\sqrt2 + 4\\sqrt3 - 3\\sqrt6,$$\nthe first three in $4$ steps and the last one in $6$ steps. Note that it does not matter whether the small square returns to its original orientation.\n\nAlso $F(100) = 805$.\n\nFind $F(10^8)$.", "raw_html": "

    \nA square of side length $b<1$ is rolling around the inside of a larger square of side length $1$, always touching the larger square but without sliding.
    \nInitially the two squares share a common corner. At each step, the small square rotates clockwise about a corner that touches the large square, until another of its corners touches the large square. Here is an illustration of the first three steps for $b = \\frac5{13}$.

    \n
    \"0935_rolling.png\"
    \n

    \nFor some values of $b$, the small square may return to its initial position after several steps. For example, when $b = \\frac12$, this happens in $4$ steps; and for $b = \\frac5{13}$ it happens in $24$ steps.

    \n\n

    \nLet $F(N)$ be the number of different values of $b$ for which the small square first returns to its initial position within at most $N$ steps. For example, $F(6) = 4$, with the corresponding $b$ values:\n$$\\frac12,\\quad 2 - \\sqrt 2,\\quad 2 + \\sqrt 2 - \\sqrt{2 + 4\\sqrt2},\\quad 8 - 5\\sqrt2 + 4\\sqrt3 - 3\\sqrt6,$$\nthe first three in $4$ steps and the last one in $6$ steps. Note that it does not matter whether the small square returns to its original orientation.
    \nAlso $F(100) = 805$.

    \n\n

    \nFind $F(10^8)$.

    ", "url": "https://projecteuler.net/problem=935", "answer": "759908921637225"} {"id": 936, "problem": "A peerless tree is a tree with no edge between two vertices of the same degree. Let $P(n)$ be the number of peerless trees on $n$ unlabelled vertices.\n\nThere are six of these trees on seven unlabelled vertices, $P(7)=6$, shown below.\n\nDefine $\\displaystyle S(N) = \\sum_{n=3}^N P(n)$. You are given $S(10) = 74$.\n\nFind $S(50)$.", "raw_html": "

    A peerless tree is a tree with no edge between two vertices of the same degree. Let $P(n)$ be the number of peerless trees on $n$ unlabelled vertices.

    \n\n

    There are six of these trees on seven unlabelled vertices, $P(7)=6$, shown below.

    \n\"0936_diagram.jpg\"\n\n

    Define $\\displaystyle S(N) = \\sum_{n=3}^N P(n)$. You are given $S(10) = 74$.

    \n\n

    Find $S(50)$.

    ", "url": "https://projecteuler.net/problem=936", "answer": "12144907797522336"} {"id": 937, "problem": "Let $\\theta=\\sqrt{-2}$.\n\nDefine $T$ to be the set of numbers of the form $a+b\\theta$, where $a$ and $b$ are integers and either $a\\gt 0$, or $a=0$ and $b\\gt 0$. For a set $S \\subseteq T$ and element $z \\in T$, define $p(S,z)$ to be the number of ways of choosing two distinct elements from $S$ with product either $z$ or $-z$.\n\nFor example if $S=\\{1,2,4\\}$ and $z=4$, there is only one valid pair of elements with product $\\pm4$, namely $1$ and $4$. Thus, in this case $p(S,z)=1$.\n\nFor another example, if $S=\\{1,\\theta,1+\\theta,2-\\theta\\}$ and $z=2-\\theta$, we have $1\\cdot(2-\\theta)=z$ and $\\theta\\cdot(1+\\theta)=-z$, giving $p(S,z)=2$.\n\nLet $A$ and $B$ be two sets satisfying the following conditions:\n\n- $1 \\in A$\n\n- $A \\cap B = \\emptyset$\n\n- $A \\cup B = T$\n\n- $p(A,z) = p(B,z)$ for all $z\\in T$\n\nRemarkably, these four conditions uniquely determine the sets $A$ and $B$.\n\nLet $F_n$ be the set of the first $n$ factorials: $F_n=\\{1!,2!,\\dots,n!\\}$, and define $G(n)$ to be the sum of all elements of $F_n\\cap A$.\n\nYou are given $G(4) = 25$, $G(7) = 745$, and $G(100) \\equiv 709772949 \\pmod{10^9+7}$.\n\nFind $G(10^8)$ and give your answer modulo $10^9+7$.", "raw_html": "

    Let $\\theta=\\sqrt{-2}$.

    \n\n

    Define $T$ to be the set of numbers of the form $a+b\\theta$, where $a$ and $b$ are integers and either $a\\gt 0$, or $a=0$ and $b\\gt 0$. For a set $S \\subseteq T$ and element $z \\in T$, define $p(S,z)$ to be the number of ways of choosing two distinct elements from $S$ with product either $z$ or $-z$.

    \n\n

    For example if $S=\\{1,2,4\\}$ and $z=4$, there is only one valid pair of elements with product $\\pm4$, namely $1$ and $4$. Thus, in this case $p(S,z)=1$.

    \n\n

    For another example, if $S=\\{1,\\theta,1+\\theta,2-\\theta\\}$ and $z=2-\\theta$, we have $1\\cdot(2-\\theta)=z$ and $\\theta\\cdot(1+\\theta)=-z$, giving $p(S,z)=2$.

    \n\n

    Let $A$ and $B$ be two sets satisfying the following conditions:

    \n
      \n
    • $1 \\in A$
    • \n
    • $A \\cap B = \\emptyset$
    • \n
    • $A \\cup B = T$
    • \n
    • $p(A,z) = p(B,z)$ for all $z\\in T$
    • \n
    \n

    Remarkably, these four conditions uniquely determine the sets $A$ and $B$.

    \n\n

    Let $F_n$ be the set of the first $n$ factorials: $F_n=\\{1!,2!,\\dots,n!\\}$, and define $G(n)$ to be the sum of all elements of $F_n\\cap A$.

    \n\n

    You are given $G(4) = 25$, $G(7) = 745$, and $G(100) \\equiv 709772949 \\pmod{10^9+7}$.

    \n\n

    Find $G(10^8)$ and give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=937", "answer": "792169346"} {"id": 938, "problem": "A deck of cards contains $R$ red cards and $B$ black cards.\n\nA card is chosen uniformly randomly from the deck and removed. A second card is then chosen uniformly randomly from the cards remaining and removed.\n\n-\nIf both cards are red, they are discarded.\n\n-\nIf both cards are black, they are both put back in the deck.\n\n-\nIf they are different colours, the red card is put back in the deck and the black card is discarded.\n\nPlay ends when all the remaining cards in the deck are the same colour and let $P(R,B)$ be the probability that this colour is black.\n\nYou are given $P(2,2) = 0.4666666667$, $P(10,9) = 0.4118903397$ and $P(34,25) = 0.3665688069$.\n\nFind $P(24690,12345)$. Give your answer with 10 digits after the decimal point.", "raw_html": "

    \nA deck of cards contains $R$ red cards and $B$ black cards.
    \nA card is chosen uniformly randomly from the deck and removed. A second card is then chosen uniformly randomly from the cards remaining and removed.

    \n
      \n
    • \nIf both cards are red, they are discarded.
    • \n
    • \nIf both cards are black, they are both put back in the deck.
    • \n
    • \nIf they are different colours, the red card is put back in the deck and the black card is discarded.
    \n

    \nPlay ends when all the remaining cards in the deck are the same colour and let $P(R,B)$ be the probability that this colour is black.

    \n

    \nYou are given $P(2,2) = 0.4666666667$, $P(10,9) = 0.4118903397$ and $P(34,25) = 0.3665688069$.

    \n

    \nFind $P(24690,12345)$. Give your answer with 10 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=938", "answer": "0.2928967987"} {"id": 939, "problem": "Two players A and B are playing a variant of Nim.\n\nAt the beginning, there are several piles of stones. Each pile is either at the side of A or at the side of B. The piles are unordered.\n\nThey make moves in turn. At a player's turn, the player can\n\n- either choose a pile on the opponent's side and remove one stone from that pile;\n\n- or choose a pile on their own side and remove the whole pile.\n\nThe winner is the player who removes the last stone.\n\nLet $E(N)$ be the number of initial settings with at most $N$ stones such that, whoever plays first, A always has a winning strategy.\n\nFor example $E(4) = 9$; the settings are:\n\n| Nr. | Piles at the side of A | Piles at the side of B |\n| --- | --- | --- |\n| 1 | $4$ | none |\n| 2 | $1, 3$ | none |\n| 3 | $2, 2$ | none |\n| 4 | $1, 1, 2$ | none |\n| 5 | $3$ | $1$ |\n| 6 | $1, 2$ | $1$ |\n| 7 | $2$ | $1, 1$ |\n| 8 | $3$ | none |\n| 9 | $2$ | none |\n\nFind $E(5000) \\bmod 1234567891$.", "raw_html": "

    \nTwo players A and B are playing a variant of Nim.
    \nAt the beginning, there are several piles of stones. Each pile is either at the side of A or at the side of B. The piles are unordered.

    \n\n

    \nThey make moves in turn. At a player's turn, the player can

    \n
      \n
    • either choose a pile on the opponent's side and remove one stone from that pile;
    • \n
    • or choose a pile on their own side and remove the whole pile.
    \n

    The winner is the player who removes the last stone.

    \n\n

    \nLet $E(N)$ be the number of initial settings with at most $N$ stones such that, whoever plays first, A always has a winning strategy.

    \n\n

    \nFor example $E(4) = 9$; the settings are:\n

    \n
    \n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n\n \n \n
    Nr.Piles at the side of APiles at the side of B
    1$4$none
    2$1, 3$none
    3$2, 2$none
    4$1, 1, 2$none
    5$3$$1$
    6$1, 2$$1$
    7$2$$1, 1$
    8$3$none
    9$2$none
    \n\n

    \nFind $E(5000) \\bmod 1234567891$.

    ", "url": "https://projecteuler.net/problem=939", "answer": "246776732"} {"id": 940, "problem": "The Fibonacci sequence $(f_i)$ is the unique sequence such that\n\n- $f_0=0$\n\n- $f_1=1$\n\n- $f_{i+1}=f_i+f_{i-1}$\n\nSimilarly, there is a unique function $A(m,n)$ such that\n\n- $A(0,0)=0$\n\n- $A(0,1)=1$\n\n- $A(m+1,n)=A(m,n+1)+A(m,n)$\n\n- $A(m+1,n+1)=2A(m+1,n)+A(m,n)$\n\nDefine $S(k)=\\displaystyle\\sum_{i=2}^k\\sum_{j=2}^k A(f_i,f_j)$. For example\n$$\n\\begin{align}\nS(3)&=A(1,1)+A(1,2)+A(2,1)+A(2,2)\\\\\n&=2+5+7+16\\\\\n&=30\n\\end{align}\n$$You are also given $S(5)=10396$.\n\nFind $S(50)$, giving your answer modulo $1123581313$.", "raw_html": "

    \nThe Fibonacci sequence $(f_i)$ is the unique sequence such that\n

    \n
      \n
    • $f_0=0$
    • \n
    • $f_1=1$
    • \n
    • $f_{i+1}=f_i+f_{i-1}$
    • \n
    \n

    \nSimilarly, there is a unique function $A(m,n)$ such that\n

    \n
      \n
    • $A(0,0)=0$
    • \n
    • $A(0,1)=1$
    • \n
    • $A(m+1,n)=A(m,n+1)+A(m,n)$
    • \n
    • $A(m+1,n+1)=2A(m+1,n)+A(m,n)$
    • \n
    \n

    \nDefine $S(k)=\\displaystyle\\sum_{i=2}^k\\sum_{j=2}^k A(f_i,f_j)$. For example\n$$\n\\begin{align}\nS(3)&=A(1,1)+A(1,2)+A(2,1)+A(2,2)\\\\\n&=2+5+7+16\\\\\n&=30\n\\end{align}\n$$You are also given $S(5)=10396$.\n

    \n\n

    \nFind $S(50)$, giving your answer modulo $1123581313$.\n

    ", "url": "https://projecteuler.net/problem=940", "answer": "969134784"} {"id": 941, "problem": "de Bruijn has a digital combination lock with $k$ buttons numbered $0$ to $k-1$ where $k \\le 10$.\n\nThe lock opens when the last $n$ buttons pressed match the preset combination.\n\nUnfortunately he has forgotten the combination. He creates a sequence of these digits which contains every possible combination of length $n$. Then by pressing the buttons in this order he is sure to open the lock.\n\nConsider all sequences of shortest possible length that contains every possible combination of the digits.\n\nDenote by $C(k, n)$ the lexicographically smallest of these.\n\nFor example, $C(3, 2) = $ 0010211220.\n\nDefine the sequence $a_n$ by $a_0=0$ and\n\n$$a_n=(920461 a_{n-1}+800217387569)\\bmod 10^{12} \\text{ for }\\ n > 0$$\nInterpret each $a_n$ as a $12$-digit combination, adding leading zeros for any $a_n$ with less than $12$ digits.\n\nGiven a positive integer $N$, we are interested in the order the combinations $a_1,\\dots,a_N$ appear in $C(10,12)$.\n\nDenote by $p_n$ the place, numbered $1,\\dots,N$, in which $a_n$ appears out of $a_1,\\dots,a_N$. Define $\\displaystyle F(N)=\\sum_{n=1}^Np_na_n$.\n\nFor example, the combination $a_1=800217387569$ is entered before $a_2=696996536878$. Therefore:\n$$F(2)=1\\cdot800217387569 + 2\\cdot696996536878 = 2194210461325$$\nYou are also given $F(10)=32698850376317$.\n\nFind $F(10^7)$. Give your answer modulo $1234567891$.", "raw_html": "

    \nde Bruijn has a digital combination lock with $k$ buttons numbered $0$ to $k-1$ where $k \\le 10$.
    \nThe lock opens when the last $n$ buttons pressed match the preset combination.

    \n\n

    \nUnfortunately he has forgotten the combination. He creates a sequence of these digits which contains every possible combination of length $n$. Then by pressing the buttons in this order he is sure to open the lock.

    \n\n

    \nConsider all sequences of shortest possible length that contains every possible combination of the digits.
    \nDenote by $C(k, n)$ the lexicographically smallest of these.

    \n\n

    \nFor example, $C(3, 2) = $ 0010211220.

    \n\n

    \nDefine the sequence $a_n$ by $a_0=0$ and
    \n$$a_n=(920461 a_{n-1}+800217387569)\\bmod 10^{12} \\text{ for }\\ n > 0$$\nInterpret each $a_n$ as a $12$-digit combination, adding leading zeros for any $a_n$ with less than $12$ digits.

    \n\n

    \nGiven a positive integer $N$, we are interested in the order the combinations $a_1,\\dots,a_N$ appear in $C(10,12)$.
    \n Denote by $p_n$ the place, numbered $1,\\dots,N$, in which $a_n$ appears out of $a_1,\\dots,a_N$. Define $\\displaystyle F(N)=\\sum_{n=1}^Np_na_n$.

    \n\n

    \nFor example, the combination $a_1=800217387569$ is entered before $a_2=696996536878$. Therefore:\n$$F(2)=1\\cdot800217387569 + 2\\cdot696996536878 = 2194210461325$$\nYou are also given $F(10)=32698850376317$.

    \n\n

    \nFind $F(10^7)$. Give your answer modulo $1234567891$.

    ", "url": "https://projecteuler.net/problem=941", "answer": "1068765750"} {"id": 942, "problem": "Given a natural number $q$, let $p = 2^q - 1$ be the $q$-th Mersenne number.\n\nLet $R(q)$ be the minimal square root of $q$ modulo $p$, if one exists. In other words, $R(q)$ is the smallest positive integer $x$ such that $x^2 - q$ is divisible by $p$.\n\nFor example, $R(5)=6$ and $R(17)=47569$.\n\nFind $R(74\\,207\\,281)$. Give your answer modulo $10^9 + 7$.\n\nNote: $2^{74207281}-1$ is prime.", "raw_html": "

    Given a natural number $q$, let $p = 2^q - 1$ be the $q$-th Mersenne number.

    \n\n

    Let $R(q)$ be the minimal square root of $q$ modulo $p$, if one exists. In other words, $R(q)$ is the smallest positive integer $x$ such that $x^2 - q$ is divisible by $p$.

    \n\n

    For example, $R(5)=6$ and $R(17)=47569$.

    \n\n

    Find $R(74\\,207\\,281)$. Give your answer modulo $10^9 + 7$.

    \n\n

    Note: $2^{74207281}-1$ is prime.

    ", "url": "https://projecteuler.net/problem=942", "answer": "557539756"} {"id": 943, "problem": "Given two unequal positive integers $a$ and $b$, we define a self-describing sequence consisting of alternating runs of $a$s and $b$s. The first element is $a$ and the sequence of run lengths is the original sequence.\n\nFor $a=2, b=3$, the sequence is:\n$$2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3,...$$\nThe sequence begins with two $2$s and two $3$s, then three $2$s and three $3$s, so the run lengths $2, 2, 3, 3, ...$ are given by the original sequence.\n\nLet $T(a, b, N)$ be the sum of the first $N$ elements of the sequence. You are given $T(2,3,10) = 25$, $T(4,2,10^4) = 30004$, $T(5,8,10^6) = 6499871$.\n\nFind $\\sum T(a, b, 22332223332233)$ for $2 \\le a \\le 223$, $2 \\le b \\le 223$ and $a \\neq b$. Give your answer modulo $2233222333$.", "raw_html": "

    Given two unequal positive integers $a$ and $b$, we define a self-describing sequence consisting of alternating runs of $a$s and $b$s. The first element is $a$ and the sequence of run lengths is the original sequence.

    \n\n

    For $a=2, b=3$, the sequence is: \n$$2, 2, 3, 3, 2, 2, 2, 3, 3, 3, 2, 2, 3, 3, 2, 2, 3, 3, 3, 2, 2, 2, 3, 3, 3,...$$\nThe sequence begins with two $2$s and two $3$s, then three $2$s and three $3$s, so the run lengths $2, 2, 3, 3, ...$ are given by the original sequence.

    \n\n

    Let $T(a, b, N)$ be the sum of the first $N$ elements of the sequence. You are given $T(2,3,10) = 25$, $T(4,2,10^4) = 30004$, $T(5,8,10^6) = 6499871$.

    \n\n

    Find $\\sum T(a, b, 22332223332233)$ for $2 \\le a \\le 223$, $2 \\le b \\le 223$ and $a \\neq b$. Give your answer modulo $2233222333$.

    ", "url": "https://projecteuler.net/problem=943", "answer": "1038733707"} {"id": 944, "problem": "Given a set $E$ of positive integers, an element $x$ of $E$ is called an element divisor (elevisor) of $E$ if $x$ divides another element of $E$.\n\nThe sum of all elevisors of $E$ is denoted $\\operatorname{sev}(E)$.\n\nFor example, $\\operatorname{sev}(\\{1, 2, 5, 6\\}) = 1 + 2 = 3$.\n\nLet $S(n)$ be the sum of $\\operatorname{sev}(E)$ for all subsets $E$ of $\\{1, 2, \\dots, n\\}$.\n\nYou are given $S(10) = 4927$.\n\nFind $S(10^{14}) \\bmod 1234567891$.", "raw_html": "

    \nGiven a set $E$ of positive integers, an element $x$ of $E$ is called an element divisor (elevisor) of $E$ if $x$ divides another element of $E$.

    \n\n

    \nThe sum of all elevisors of $E$ is denoted $\\operatorname{sev}(E)$.
    \nFor example, $\\operatorname{sev}(\\{1, 2, 5, 6\\}) = 1 + 2 = 3$.

    \n\n

    \nLet $S(n)$ be the sum of $\\operatorname{sev}(E)$ for all subsets $E$ of $\\{1, 2, \\dots, n\\}$.
    \nYou are given $S(10) = 4927$.

    \n\n

    \nFind $S(10^{14}) \\bmod 1234567891$.

    ", "url": "https://projecteuler.net/problem=944", "answer": "1228599511"} {"id": 945, "problem": "We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.\n\nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.\n\nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n\n$$\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}$$\n\nWe consider the equation:\n\n$$\\begin{align}\n(a \\otimes a) \\oplus (2 \\otimes a \\otimes b) \\oplus (b \\otimes b) = c \\otimes c\n\\end{align}$$\n\nFor example, $(a, b, c) = (1, 2, 1)$ is a solution to this equation, and so is $(1, 8, 13)$.\n\nLet $F(N)$ be the number of solutions to this equation satisfying $0 \\le a \\le b \\le N$. You are given $F(10)=21$.\n\nFind $F(10^7)$.", "raw_html": "We use $x\\oplus y$ for the bitwise XOR of $x$ and $y$.
    \nDefine the XOR-product of $x$ and $y$, denoted by $x \\otimes y$, similar to a long multiplication in base $2$, except that the intermediate results are XORed instead of the usual integer addition.
    \n\nFor example, $7 \\otimes 3 = 9$, or in base $2$, $111_2 \\otimes 11_2 = 1001_2$:\n
    \n$$\\begin{align*}\n\\phantom{\\otimes 111} 111_2 \\\\\n\\otimes \\phantom{1111} 11_2 \\\\\n\\hline\n\\phantom{\\otimes 111} 111_2 \\\\\n\\oplus \\phantom{11} 111_2 \\phantom{9} \\\\\n\\hline\n\\phantom{\\otimes 11} 1001_2 \\\\\n\\end{align*}$$\n
    \n\nWe consider the equation:\n
    \n$$\\begin{align}\n(a \\otimes a) \\oplus (2 \\otimes a \\otimes b) \\oplus (b \\otimes b) = c \\otimes c\n\\end{align}$$\n
    \n

    \nFor example, $(a, b, c) = (1, 2, 1)$ is a solution to this equation, and so is $(1, 8, 13)$.\n

    \nLet $F(N)$ be the number of solutions to this equation satisfying $0 \\le a \\le b \\le N$. You are given $F(10)=21$.\n

    \nFind $F(10^7)$.\n

    ", "url": "https://projecteuler.net/problem=945", "answer": "83357132"} {"id": 946, "problem": "Given the representation of a continued fraction\n$$ a_0+ \\cfrac 1{a_1+ \\cfrac 1{a_2+\\cfrac 1{a_3+\\ddots }}}= [a_0;a_1,a_2,a_3,\\ldots] $$\n\n$\\alpha$ is a real number with continued fraction representation:\n$\\alpha = [2;1,1,2,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,\\ldots]$\nwhere the number of $1$'s between each of the $2$'s are consecutive prime numbers.\n\n$\\beta$ is another real number defined as\n$$\t\\beta = \\frac{2\\alpha+3}{3\\alpha+2} $$\n\nThe first ten coefficients of the continued fraction of $\\beta$ are $[0;1,5,6,16,9,1,10,16,11]$ with sum $75$.\n\nFind the sum of the first $10^8$ coefficients of the continued fraction of $\\beta$.", "raw_html": "

    Given the representation of a continued fraction\n$$ a_0+ \\cfrac 1{a_1+ \\cfrac 1{a_2+\\cfrac 1{a_3+\\ddots }}}= [a_0;a_1,a_2,a_3,\\ldots] $$

    \n\n

    \n$\\alpha$ is a real number with continued fraction representation:\n$\\alpha = [2;1,1,2,1,1,1,2,1,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,2,\\ldots]$
    where the number of $1$'s between each of the $2$'s are consecutive prime numbers.

    \n\n

    \n$\\beta$ is another real number defined as\n$$\t\\beta = \\frac{2\\alpha+3}{3\\alpha+2} $$

    \n\n

    \nThe first ten coefficients of the continued fraction of $\\beta$ are $[0;1,5,6,16,9,1,10,16,11]$ with sum $75$.

    \n\n

    \nFind the sum of the first $10^8$ coefficients of the continued fraction of $\\beta$.

    ", "url": "https://projecteuler.net/problem=946", "answer": "585787007"} {"id": 947, "problem": "The $(a,b,m)$-sequence, where $0 \\leq a,b \\lt m$, is defined as\n\n$\\begin{align*}\ng(0)&=a\\\\\ng(1)&=b\\\\\ng(n)&= \\big(g(n-1) + g(n-2)\\big) \\bmod m\n\\end{align*}$\n\nAll $(a,b,m)$-sequences are periodic with period denoted by $p(a,b,m)$.\n\nThe first few terms of the $(0,1,8)$-sequence are $(0,1,1,2,3,5,0,5,5,2,7,1,0,1,1,2,\\ldots )$ and so $p(0,1,8)=12$.\n\nLet $\\displaystyle s(m)=\\sum_{a=0}^{m-1}\\sum_{b=0}^{m-1} p(a,b,m)^2$. For example, $s(3)=513$ and $s(10)=225820$.\n\nDefine $\\displaystyle S(M)=\\sum_{m=1}^{M}s(m)$. You are given, $S(3)=542$ and $S(10)=310897$.\n\nFind $S(10^6)$. Give your answer modulo $999\\,999\\,893$.", "raw_html": "

    \nThe $(a,b,m)$-sequence, where $0 \\leq a,b \\lt m$, is defined as

    \n\n
    \n$\\begin{align*}\ng(0)&=a\\\\\ng(1)&=b\\\\\ng(n)&= \\big(g(n-1) + g(n-2)\\big) \\bmod m\n\\end{align*}$\n
    \n\n

    \nAll $(a,b,m)$-sequences are periodic with period denoted by $p(a,b,m)$.
    \nThe first few terms of the $(0,1,8)$-sequence are $(0,1,1,2,3,5,0,5,5,2,7,1,0,1,1,2,\\ldots )$ and so $p(0,1,8)=12$.

    \n\n

    \nLet $\\displaystyle s(m)=\\sum_{a=0}^{m-1}\\sum_{b=0}^{m-1} p(a,b,m)^2$. For example, $s(3)=513$ and $s(10)=225820$.

    \n\n

    \nDefine $\\displaystyle S(M)=\\sum_{m=1}^{M}s(m)$. You are given, $S(3)=542$ and $S(10)=310897$.

    \n\n

    \nFind $S(10^6)$. Give your answer modulo $999\\,999\\,893$.

    ", "url": "https://projecteuler.net/problem=947", "answer": "213731313"} {"id": 948, "problem": "Left and Right play a game with a word consisting of L's and R's, alternating turns. On Left's turn, Left can remove any positive number of letters, but not all the letters, from the left side of the word. Right does the same on Right's turn except that Right removes letters from the right side. The game continues until only one letter remains: if it is an 'L' then Left wins; if it is an 'R' then Right wins.\n\nLet $F(n)$ be the number of words of length $n$ where the player moving first, whether it's Left or Right, will win the game if both play optimally.\n\nYou are given $F(3)=4$ and $F(8)=181$.\n\nFind $F(60)$.", "raw_html": "

    Left and Right play a game with a word consisting of L's and R's, alternating turns. On Left's turn, Left can remove any positive number of letters, but not all the letters, from the left side of the word. Right does the same on Right's turn except that Right removes letters from the right side. The game continues until only one letter remains: if it is an 'L' then Left wins; if it is an 'R' then Right wins.

    \n\n

    Let $F(n)$ be the number of words of length $n$ where the player moving first, whether it's Left or Right, will win the game if both play optimally.

    \n\n

    You are given $F(3)=4$ and $F(8)=181$.

    \n\n

    Find $F(60)$.

    ", "url": "https://projecteuler.net/problem=948", "answer": "1033654680825334184"} {"id": 949, "problem": "Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns. On Left's turn, for each word, Left can remove any number of letters (possibly zero), but not all the letters, from the left side of the word. However, at least one letter must be removed from at least one word. Right does the same on Right's turn except that Right removes letters from the right side of each word. The game continues until each word is reduced to a single letter. If there are more L's than R's remaining then Left wins; otherwise if there are more R's than L's then Right wins. In this problem we only consider games with an odd number of words, thus making ties impossible.\n\nLet $G(n, k)$ be the number of ways of choosing $k$ words of length $n$, for which Right has a winning strategy when Left plays first. Different orderings of the same set of words are to be counted separately.\n\nIt can be seen that $G(2, 3)=14$ due to the following solutions (and their reorderings):\n$$\\begin{align}\n(\\texttt{LL},\\texttt{RR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{LR},\\texttt{LR},\\texttt{LR})&:1\\text{ ordering}\\\\\n(\\texttt{LR},\\texttt{LR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{LR},\\texttt{RR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{RL},\\texttt{RR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{RR},\\texttt{RR},\\texttt{RR})&:1\\text{ ordering}\n\\end{align}\n$$You are also given $G(4, 3)=496$ and $G(8, 5)=26359197010$.\n\nFind $G(20, 7)$ giving your answer modulo $1001001011$.", "raw_html": "

    Left and Right play a game with a number of words, each consisting of L's and R's, alternating turns. On Left's turn, for each word, Left can remove any number of letters (possibly zero), but not all the letters, from the left side of the word. However, at least one letter must be removed from at least one word. Right does the same on Right's turn except that Right removes letters from the right side of each word. The game continues until each word is reduced to a single letter. If there are more L's than R's remaining then Left wins; otherwise if there are more R's than L's then Right wins. In this problem we only consider games with an odd number of words, thus making ties impossible.

    \n\n

    Let $G(n, k)$ be the number of ways of choosing $k$ words of length $n$, for which Right has a winning strategy when Left plays first. Different orderings of the same set of words are to be counted separately.

    \n\n

    It can be seen that $G(2, 3)=14$ due to the following solutions (and their reorderings):\n$$\\begin{align}\n(\\texttt{LL},\\texttt{RR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{LR},\\texttt{LR},\\texttt{LR})&:1\\text{ ordering}\\\\\n(\\texttt{LR},\\texttt{LR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{LR},\\texttt{RR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{RL},\\texttt{RR},\\texttt{RR})&:3\\text{ orderings}\\\\\n(\\texttt{RR},\\texttt{RR},\\texttt{RR})&:1\\text{ ordering}\n\\end{align}\n$$You are also given $G(4, 3)=496$ and $G(8, 5)=26359197010$.

    \n\n

    Find $G(20, 7)$ giving your answer modulo $1001001011$.

    ", "url": "https://projecteuler.net/problem=949", "answer": "726010935"} {"id": 950, "problem": "A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves. The treasure consists of identical, indivisible gold coins.\n\nAccording to pirate law, the distribution of treasure must proceed as follows:\n\n- The most senior pirate proposes a distribution of the coins.\n\n- All pirates, including the most senior, vote on whether to accept the distribution.\n\n- If at least half of the pirates vote to accept, the distribution stands.\n\n- Otherwise, the most senior pirate must walk the plank, and the process resumes from step 1 with the next most senior pirate proposing another distribution.\n\nThe happiness of a pirate is equal to $-\\infty$ if he doesn't survive; otherwise, it is equal to $c + p\\cdot w$, where $c$ is the number of coins that pirate receives in the distribution, $w$ is the total number of pirates who were made to walk the plank, and $p$ is the bloodthirstiness of the pirate.\n\nThe pirates have a number of characteristics:\n\n- Greed: to maximise their happiness.\n\n- Ruthlessness: incapable of cooperation, making promises or maintaining any kind of reputation.\n\n- Shrewdness: perfectly rational and logical.\n\nConsider the happiness $c(n,C,p) + p\\cdot w(n,C,p)$ of the most senior surviving pirate in the situation where $n$ pirates, all with equal bloodthirstiness $p$, have found $C$ coins. For example, $c(5,5,\\frac{1}{10}) = 3$ and $w(5,5,\\frac{1}{10})=0$ because it can be shown that if the most senior pirate proposes a distribution of $3,0,1,0,1$ coins to the pirates (in decreasing order of seniority), the three pirates receiving coins will all vote to accept. On the other hand, $c(5,1,\\frac{1}{10}) = 0$ and $w(5,1,\\frac{1}{10}) = 1$: the most senior pirate cannot survive with any proposal, and then the second most senior pirate must give the only coin to another pirate in order to survive.\n\nDefine $\\displaystyle T(N,C,p) = \\sum_{n=1}^N \\left ( c(n,C,p) + w(n,C,p) \\right )$. You are given that $T(30,3,\\frac{1}{\\sqrt{3}}) = 190$, $T(50,3,\\frac{1}{\\sqrt{31}}) = 385$, and $T(10^3, 101, \\frac{1}{\\sqrt{101}}) = 142427$.\n\nFind $\\displaystyle \\sum_{k=1}^6 T(10^{16},10^k+1,\\tfrac{1}{\\sqrt{10^k+1}})$. Give the last 9 digits as your answer.", "raw_html": "

    A band of pirates has come into a hoard of treasure, and must decide how to distribute it amongst themselves. The treasure consists of identical, indivisible gold coins.

    \n\n

    According to pirate law, the distribution of treasure must proceed as follows:

    \n
      \n
    1. The most senior pirate proposes a distribution of the coins.
    2. \n
    3. All pirates, including the most senior, vote on whether to accept the distribution.
    4. \n
    5. If at least half of the pirates vote to accept, the distribution stands.
    6. \n
    7. Otherwise, the most senior pirate must walk the plank, and the process resumes from step 1 with the next most senior pirate proposing another distribution.
    8. \n
    \n\n

    The happiness of a pirate is equal to $-\\infty$ if he doesn't survive; otherwise, it is equal to $c + p\\cdot w$, where $c$ is the number of coins that pirate receives in the distribution, $w$ is the total number of pirates who were made to walk the plank, and $p$ is the bloodthirstiness of the pirate.

    \n\n

    The pirates have a number of characteristics:

    \n
      \n
    • Greed: to maximise their happiness.
    • \n
    • Ruthlessness: incapable of cooperation, making promises or maintaining any kind of reputation.
    • \n
    • Shrewdness: perfectly rational and logical.
    • \n
    \n\n

    Consider the happiness $c(n,C,p) + p\\cdot w(n,C,p)$ of the most senior surviving pirate in the situation where $n$ pirates, all with equal bloodthirstiness $p$, have found $C$ coins. For example, $c(5,5,\\frac{1}{10}) = 3$ and $w(5,5,\\frac{1}{10})=0$ because it can be shown that if the most senior pirate proposes a distribution of $3,0,1,0,1$ coins to the pirates (in decreasing order of seniority), the three pirates receiving coins will all vote to accept. On the other hand, $c(5,1,\\frac{1}{10}) = 0$ and $w(5,1,\\frac{1}{10}) = 1$: the most senior pirate cannot survive with any proposal, and then the second most senior pirate must give the only coin to another pirate in order to survive.

    \n\n

    Define $\\displaystyle T(N,C,p) = \\sum_{n=1}^N \\left ( c(n,C,p) + w(n,C,p) \\right )$. You are given that $T(30,3,\\frac{1}{\\sqrt{3}}) = 190$, $T(50,3,\\frac{1}{\\sqrt{31}}) = 385$, and $T(10^3, 101, \\frac{1}{\\sqrt{101}}) = 142427$.

    \n\n

    Find $\\displaystyle \\sum_{k=1}^6 T(10^{16},10^k+1,\\tfrac{1}{\\sqrt{10^k+1}})$. Give the last 9 digits as your answer.

    ", "url": "https://projecteuler.net/problem=950", "answer": "429162542"} {"id": 951, "problem": "Two players play a game using a deck of $2n$ cards: $n$ red and $n$ black. Initially the deck is shuffled into one of the $\\binom{2n}{n}$ possible starting configurations. Play then proceeds, alternating turns, where a player follows two steps on each turn:\n\n-\nRemove the top card from the deck, taking note of its colour.\n\n-\nIf there is a next card and it is the same colour as the previous card they toss a fair coin. If the coin lands on heads they remove that card as well; otherwise leave it on top of the deck.\n\nThe player who removes the final card from the deck wins the game.\n\nSome starting configurations give an advantage to one of the players; while some starting configurations are fair, in which both players have exactly $50\\%$ chance to win the game. For example, if $n=2$ there are four starting configurations which are fair: RRBB, BBRR, RBBR, BRRB. The remaining two, RBRB and BRBR, result in a guaranteed win for the second player.\n\nDefine $F(n)$ to be the number of starting configurations which are fair. Therefore $F(2)=4$. You are also given $F(8)=11892$.\n\nFind $F(26)$.", "raw_html": "

    \nTwo players play a game using a deck of $2n$ cards: $n$ red and $n$ black. Initially the deck is shuffled into one of the $\\binom{2n}{n}$ possible starting configurations. Play then proceeds, alternating turns, where a player follows two steps on each turn:

    \n\n
      \n
    1. \nRemove the top card from the deck, taking note of its colour.
    2. \n\n
    3. \nIf there is a next card and it is the same colour as the previous card they toss a fair coin. If the coin lands on heads they remove that card as well; otherwise leave it on top of the deck.
    \n\n

    \nThe player who removes the final card from the deck wins the game.

    \n\n

    \nSome starting configurations give an advantage to one of the players; while some starting configurations are fair, in which both players have exactly $50\\%$ chance to win the game. For example, if $n=2$ there are four starting configurations which are fair: RRBB, BBRR, RBBR, BRRB. The remaining two, RBRB and BRBR, result in a guaranteed win for the second player.

    \n\n

    \nDefine $F(n)$ to be the number of starting configurations which are fair. Therefore $F(2)=4$. You are also given $F(8)=11892$.

    \n\n

    \nFind $F(26)$.

    ", "url": "https://projecteuler.net/problem=951", "answer": "495568995495726"} {"id": 952, "problem": "Given a prime $p$ and a positive integer $n \\lt p$, let $R(p, n)$ be the multiplicative order of $p$ modulo $n!$.\n\nIn other words, $R(p, n)$ is the minimal positive integer $r$ such that\n\n$$p^r \\equiv 1 \\pmod{n!}$$\n\nFor example, $R(7, 4) = 2$ and $R(10^9 + 7, 12) = 17280$.\n\nFind $R(10^9 + 7, 10^7)$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    \nGiven a prime $p$ and a positive integer $n \\lt p$, let $R(p, n)$ be the multiplicative order of $p$ modulo $n!$.
    \nIn other words, $R(p, n)$ is the minimal positive integer $r$ such that

    \n\n$$p^r \\equiv 1 \\pmod{n!}$$\n\n

    \nFor example, $R(7, 4) = 2$ and $R(10^9 + 7, 12) = 17280$.

    \n\n

    \nFind $R(10^9 + 7, 10^7)$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=952", "answer": "794394453"} {"id": 953, "problem": "In the classical game of Nim two players take turns removing stones from piles. A player may remove any positive number of stones from a single pile. If there are no remaining stones, the next player to move loses.\n\nIn Factorisation Nim the initial position of the game is chosen according to the prime factorisation of a given natural number $n$ by setting a pile for each prime factor, including multiplicity. For example, if $n=12=2 \\times 2 \\times 3$ the game starts with three piles: two piles with two stones and one pile with three stones.\n\nIt can be verified that the first player to move loses for $n=1$ and for $n=70$, assuming both players play optimally.\n\nLet $S(N)$ be the sum of $n$ for $1 \\le n \\le N$ such that the first player to move loses, assuming both players play optimally. You are given $S(10) = 14$ and $S(100) = 455$.\n\nFind $S(10^{14})$. Give your answer modulo $10^9 + 7$.", "raw_html": "

    In the classical game of Nim two players take turns removing stones from piles. A player may remove any positive number of stones from a single pile. If there are no remaining stones, the next player to move loses.

    \n\n

    In Factorisation Nim the initial position of the game is chosen according to the prime factorisation of a given natural number $n$ by setting a pile for each prime factor, including multiplicity. For example, if $n=12=2 \\times 2 \\times 3$ the game starts with three piles: two piles with two stones and one pile with three stones.

    \n\n

    It can be verified that the first player to move loses for $n=1$ and for $n=70$, assuming both players play optimally.

    \n\n

    Let $S(N)$ be the sum of $n$ for $1 \\le n \\le N$ such that the first player to move loses, assuming both players play optimally. You are given $S(10) = 14$ and $S(100) = 455$.

    \n\n

    Find $S(10^{14})$. Give your answer modulo $10^9 + 7$.

    ", "url": "https://projecteuler.net/problem=953", "answer": "176907658"} {"id": 954, "problem": "A positive integer is called heptaphobic if it is not divisible by seven and no number divisible by seven can be produced by swapping two of its digits. Note that leading zeros are not allowed before or after the swap.\n\nFor example, $17$ and $1305$ are heptaphobic, but $14$ and $132$ are not because $14$ and $231$ are divisible by seven.\n\nLet $C(N)$ count heptaphobic numbers smaller than $N$. You are given $C(100) = 74$ and $C(10^4) = 3737$.\n\nFind $C(10^{13})$.", "raw_html": "

    A positive integer is called heptaphobic if it is not divisible by seven and no number divisible by seven can be produced by swapping two of its digits. Note that leading zeros are not allowed before or after the swap.

    \n\n

    For example, $17$ and $1305$ are heptaphobic, but $14$ and $132$ are not because $14$ and $231$ are divisible by seven.

    \n\n

    Let $C(N)$ count heptaphobic numbers smaller than $N$. You are given $C(100) = 74$ and $C(10^4) = 3737$.

    \n\n

    Find $C(10^{13})$.

    ", "url": "https://projecteuler.net/problem=954", "answer": "736463823"} {"id": 955, "problem": "A sequence $(a_n)_{n \\ge 0}$ starts with $a_0 = 3$ and for each $n \\ge 0$,\n\n- if $a_n$ is a triangle numberA triangle number is a number of the form $m(m + 1)/2$ for some integer $m$., then $a_{n + 1} = a_n + 1$;\n\n- otherwise, $a_{n + 1} = 2a_n - a_{n - 1} + 1$.\n\nThe sequence begins:\n$${\\color{red}3}, 4, {\\color{red}6}, 7, 9, 12, 16, {\\color{red}21}, 22, 24, 27, 31, {\\color{red}36}, 37, 39, 42, \\dots$$\nwhere triangle numbers are marked red.\n\nThe $10$th triangle number in the sequence is $a_{2964} = 1439056$.\n\nFind the index $n$ such that $a_n$ is the $70$th triangle number in the sequence.", "raw_html": "

    \nA sequence $(a_n)_{n \\ge 0}$ starts with $a_0 = 3$ and for each $n \\ge 0$,

    \n
      \n
    • if $a_n$ is a triangle numberA triangle number is a number of the form $m(m + 1)/2$ for some integer $m$., then $a_{n + 1} = a_n + 1$;
    • \n
    • otherwise, $a_{n + 1} = 2a_n - a_{n - 1} + 1$.
    \n\n

    \nThe sequence begins:\n$${\\color{red}3}, 4, {\\color{red}6}, 7, 9, 12, 16, {\\color{red}21}, 22, 24, 27, 31, {\\color{red}36}, 37, 39, 42, \\dots$$\nwhere triangle numbers are marked red.

    \n\n

    \nThe $10$th triangle number in the sequence is $a_{2964} = 1439056$.
    \nFind the index $n$ such that $a_n$ is the $70$th triangle number in the sequence.

    ", "url": "https://projecteuler.net/problem=955", "answer": "6795261671274"} {"id": 956, "problem": "The total number of prime factors of $n$, counted with multiplicity, is denoted $\\Omega(n)$.\n\nFor example, $\\Omega(12)=3$, counting the factor $2$ twice, and the factor $3$ once.\n\nDefine $D(n, m)$ to be the sum of all divisors $d$ of $n$ where $\\Omega(d)$ is divisible by $m$.\n\nFor example, $D(24, 3)=1+8+12=21$.\n\nThe superfactorial of $n$, often written as $n\\$$, is defined as the product of the first $n$ factorials:\n$$n\\$=1!\\times 2! \\times\\cdots\\times n!$$\nThe superduperfactorial of $n$, we write as $n\\bigstar$, is defined as the product of the first $n$ superfactorials:\n$$n\\bigstar=1\\$ \\times 2\\$ \\times\\cdots\\times n\\$ $$\n\nYou are given $D(6\\bigstar, 6)=6368195719791280$.\n\nFind $D(1\\,000\\bigstar, 1\\,000)$.\nGive your answer modulo $999\\,999\\,001$.", "raw_html": "

    \nThe total number of prime factors of $n$, counted with multiplicity, is denoted $\\Omega(n)$.
    \nFor example, $\\Omega(12)=3$, counting the factor $2$ twice, and the factor $3$ once.

    \n\n

    \nDefine $D(n, m)$ to be the sum of all divisors $d$ of $n$ where $\\Omega(d)$ is divisible by $m$.
    \nFor example, $D(24, 3)=1+8+12=21$.

    \n\n

    \nThe superfactorial of $n$, often written as $n\\$$, is defined as the product of the first $n$ factorials:\n$$n\\$=1!\\times 2! \\times\\cdots\\times n!$$\nThe superduperfactorial of $n$, we write as $n\\bigstar$, is defined as the product of the first $n$ superfactorials:\n$$n\\bigstar=1\\$ \\times 2\\$ \\times\\cdots\\times n\\$ $$\n

    \n\n

    \nYou are given $D(6\\bigstar, 6)=6368195719791280$.

    \n\n

    \nFind $D(1\\,000\\bigstar, 1\\,000)$. \nGive your answer modulo $999\\,999\\,001$.

    ", "url": "https://projecteuler.net/problem=956", "answer": "882086212"} {"id": 957, "problem": "There is a plane on which all points are initially white, except three red points and two blue points.\n\nOn each day, every line passing through a red point and a blue point is constructed. Then every white point, where two different such lines meet, turns blue.\n\nLet $g(n)$ be the maximal possible number of blue points after $n$ days.\n\nFor example, $g(1)=8$ and $g(2)=28$.\n\nFind $g(16)$.", "raw_html": "

    \nThere is a plane on which all points are initially white, except three red points and two blue points.
    \nOn each day, every line passing through a red point and a blue point is constructed. Then every white point, where two different such lines meet, turns blue.

    \n\n

    \nLet $g(n)$ be the maximal possible number of blue points after $n$ days.

    \n\n

    \nFor example, $g(1)=8$ and $g(2)=28$.

    \n\n

    \nFind $g(16)$.

    ", "url": "https://projecteuler.net/problem=957", "answer": "234897386493229284"} {"id": 958, "problem": "The Euclidean algorithm can be used to find the greatest common divisor of two positive integers. At each step of the algorithm the smaller number is subtracted from the larger one. The algorithm terminates when the numbers are equal, which is then the greatest common divisor of the original numbers.\n\nFor two numbers $n$ and $m$, let $d(n, m)$ be the number of subtraction steps used by the Euclidean algorithm for computing the greatest common divisor of $n$ and $m$.\n\nFor a number $n$, let $f(n)$ be the positive number $m$ coprime to $n$ that minimizes $d(n, m)$. If more than one number attains the minimum, the minimal $m$ is chosen.\n\nFor example, at least four steps are needed for computing the GCD of $7$ and any positive number $m$ coprime to $7$. This number of steps is obtained by $m=2,3,4,5$, yielding $f(7)=2$. You are also given $f(89)=34$ and $f(8191) = 1856$.\n\nFind $f(10^{12}+39)$.", "raw_html": "

    The Euclidean algorithm can be used to find the greatest common divisor of two positive integers. At each step of the algorithm the smaller number is subtracted from the larger one. The algorithm terminates when the numbers are equal, which is then the greatest common divisor of the original numbers.

    \n\n

    For two numbers $n$ and $m$, let $d(n, m)$ be the number of subtraction steps used by the Euclidean algorithm for computing the greatest common divisor of $n$ and $m$.

    \n\n

    For a number $n$, let $f(n)$ be the positive number $m$ coprime to $n$ that minimizes $d(n, m)$. If more than one number attains the minimum, the minimal $m$ is chosen.

    \n\n

    For example, at least four steps are needed for computing the GCD of $7$ and any positive number $m$ coprime to $7$. This number of steps is obtained by $m=2,3,4,5$, yielding $f(7)=2$. You are also given $f(89)=34$ and $f(8191) = 1856$.

    \n\n

    Find $f(10^{12}+39)$.

    ", "url": "https://projecteuler.net/problem=958", "answer": "367554579311"} {"id": 959, "problem": "A frog is placed on the number line. Every step the frog jumps either $a$ units to the left or $b$ units to the right, both with $1/2$ probability.\n\nDefine $f(a, b)$ as the limit $\\lim_{n \\to \\infty} \\frac{c_n}n$ where $c_n$ is the expected number of unique numbers visited in the first $n$ steps. You are given $f(1, 1) = 0$ and $f(1, 2) \\approx 0.427050983$.\n\nFind $f(89, 97)$. Give your answer rounded to nine digits after the decimal point.", "raw_html": "

    A frog is placed on the number line. Every step the frog jumps either $a$ units to the left or $b$ units to the right, both with $1/2$ probability.

    \n\n

    Define $f(a, b)$ as the limit $\\lim_{n \\to \\infty} \\frac{c_n}n$ where $c_n$ is the expected number of unique numbers visited in the first $n$ steps. You are given $f(1, 1) = 0$ and $f(1, 2) \\approx 0.427050983$.

    \n\n

    Find $f(89, 97)$. Give your answer rounded to nine digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=959", "answer": "0.857162085"} {"id": 960, "problem": "There are $n$ distinct piles of stones, each of size $n-1$. Starting with an initial score of $0$, the following procedure is repeated:\n\n- Choose any two piles and remove exactly $n$ stones in total from the two piles.\n\n- If the number of stones removed from the two piles were $a$ and $b$, add $\\min(a,b)$ to the score.\n\nIf all piles are eventually emptied, the current score is confirmed as final. However, if one gets \"stuck\" and cannot empty all piles, the current score is discarded, resulting in a final score of $0$.\n\nThree example sequences of turns are illustrated below for $n=4$, with each tuple representing pile sizes as one proceeds, and with additions to the score indicated above the arrows.\n$$\n\\begin{align}\n&(3,3,3,3)\\xrightarrow{+1}(0,3,2,3)\\xrightarrow{+1}(0,3,1,0)\\xrightarrow{+1}(0,0,0,0)&:\\quad\\text{final score }=3\\\\\n&(3,3,3,3)\\xrightarrow{+1}(3,0,3,2)\\xrightarrow{+2}(1,0,3,0)\\xrightarrow{+1}(0,0,0,0)&:\\quad\\text{final score }=4\\\\\n&(3,3,3,3)\\xrightarrow{+2}(1,3,1,3)\\xrightarrow{+1}(1,2,1,0)\\rightarrow\\text{stuck!}&:\\quad\\text{final score }=0\n\\end{align}\n$$\n\nDefine $F(n)$ to be the sum of the final scores achieved for every sequence of turns which successfully empty all piles.\n\nYou are given $F(3)=12$, $F(4)=360$, and $F(8)=16785941760$.\n\nFind $F(100)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nThere are $n$ distinct piles of stones, each of size $n-1$. Starting with an initial score of $0$, the following procedure is repeated:

    \n
      \n
    1. Choose any two piles and remove exactly $n$ stones in total from the two piles.
    2. \n
    3. If the number of stones removed from the two piles were $a$ and $b$, add $\\min(a,b)$ to the score.
    \n\n

    \nIf all piles are eventually emptied, the current score is confirmed as final. However, if one gets \"stuck\" and cannot empty all piles, the current score is discarded, resulting in a final score of $0$.

    \n\n

    \nThree example sequences of turns are illustrated below for $n=4$, with each tuple representing pile sizes as one proceeds, and with additions to the score indicated above the arrows.\n$$\n\\begin{align}\n&(3,3,3,3)\\xrightarrow{+1}(0,3,2,3)\\xrightarrow{+1}(0,3,1,0)\\xrightarrow{+1}(0,0,0,0)&:\\quad\\text{final score }=3\\\\\n&(3,3,3,3)\\xrightarrow{+1}(3,0,3,2)\\xrightarrow{+2}(1,0,3,0)\\xrightarrow{+1}(0,0,0,0)&:\\quad\\text{final score }=4\\\\\n&(3,3,3,3)\\xrightarrow{+2}(1,3,1,3)\\xrightarrow{+1}(1,2,1,0)\\rightarrow\\text{stuck!}&:\\quad\\text{final score }=0\n\\end{align}\n$$

    \n\n

    \nDefine $F(n)$ to be the sum of the final scores achieved for every sequence of turns which successfully empty all piles.

    \n\n

    \nYou are given $F(3)=12$, $F(4)=360$, and $F(8)=16785941760$.

    \n\n

    \nFind $F(100)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=960", "answer": "243559751"} {"id": 961, "problem": "This game starts with a positive integer. Two players take turns to remove a single digit from that integer. After the digit is removed any resulting leading zeros are removed.\n\nFor example, removing a digit from $105$ results in either $5$, $10$ or $15$.\n\nThe winner is the person who removes the last nonzero digit.\n\nDefine $W(N)$ to be how many positive integers less than $N$ for which the first player can guarantee a win given optimal play. You are given $W(100) = 18$ and $W(10^4) = 1656$.\n\nFind $W(10^{18})$.", "raw_html": "

    \nThis game starts with a positive integer. Two players take turns to remove a single digit from that integer. After the digit is removed any resulting leading zeros are removed.

    \n\n

    \nFor example, removing a digit from $105$ results in either $5$, $10$ or $15$.

    \n\n

    \nThe winner is the person who removes the last nonzero digit.

    \n\n

    \nDefine $W(N)$ to be how many positive integers less than $N$ for which the first player can guarantee a win given optimal play. You are given $W(100) = 18$ and $W(10^4) = 1656$.

    \n\n

    \nFind $W(10^{18})$.

    ", "url": "https://projecteuler.net/problem=961", "answer": "166666666689036288"} {"id": 962, "problem": "Given is an integer sided triangle $ABC$ with $BC \\le AC \\le AB$.\n$k$ is the angular bisector of angle $ACB$.\n$m$ is the tangent at $C$ to the circumscribed circle of $ABC$.\n$n$ is a line parallel to $m$ through $B$.\n\nThe intersection of $n$ and $k$ is called $E$.\n\nHow many triangles $ABC$ with a perimeter not exceeding $1\\,000\\,000$ exist such that $CE$ has integral length?\n\nNote: This problem is a more difficult version of Problem 296. Please pay close attention to the differences between the two statements.", "raw_html": "

    \nGiven is an integer sided triangle $ABC$ with $BC \\le AC \\le AB$.
    $k$ is the angular bisector of angle $ACB$.
    $m$ is the tangent at $C$ to the circumscribed circle of $ABC$.
    $n$ is a line parallel to $m$ through $B$.
    \nThe intersection of $n$ and $k$ is called $E$.\n

    \n
    \"0296_bisector.gif\"
    \n

    \nHow many triangles $ABC$ with a perimeter not exceeding $1\\,000\\,000$ exist such that $CE$ has integral length?

    \n\n

    Note: This problem is a more difficult version of Problem 296. Please pay close attention to the differences between the two statements.

    ", "url": "https://projecteuler.net/problem=962", "answer": "7259046"} {"id": 963, "problem": "NOTE: This problem is related to Problem 882. It is recommended to solve that problem before doing this one.\n\nTwo players are playing a game. When the game starts, each player holds a paper with two positive integers written on it.\n\nThey make moves in turn. At a player's turn, the player can do one of the following:\n\n- pick a number on the player's own paper and change it by removing a $0$ from its ternary expansionbase-$3$ expansion;\n\n- pick a number on the opponent's paper and change it by removing a $1$ from its ternary expansion;\n\n- pick a number on either paper and change it by removing a $2$ from its ternary expansion.\n\nThe player that is unable to make a move loses.\n\nLeading zeros are not allowed in any ternary expansion; in particular nobody can make a move on the number $0$.\n\nAn initial setting is called fair if whichever player moves first will lose the game if both play optimally.\n\nFor example, if initially the integers on the paper of the first player are $1, 5$ and those on the paper of the second player are $2, 4$, then this is a fair initial setting, which we can denote as $(1, 5 \\mid 2, 4)$.\n\nNote that the order of the two integers on a paper does not matter, but the order of the two papers matter.\n\nThus $(5, 1 \\mid 4, 2)$ is considered the same as $(1, 5 \\mid 2, 4)$, while $(2, 4 \\mid 1, 5)$ is a different initial setting.\n\nLet $F(N)$ be the number of fair initial settings where each initial number does not exceed $N$.\n\nFor example, $F(5) = 21$.\n\nFind $F(10^5)$.", "raw_html": "

    NOTE: This problem is related to Problem 882. It is recommended to solve that problem before doing this one.

    \n\n

    \nTwo players are playing a game. When the game starts, each player holds a paper with two positive integers written on it.
    \nThey make moves in turn. At a player's turn, the player can do one of the following:

    \n
      \n
    • pick a number on the player's own paper and change it by removing a $0$ from its ternary expansionbase-$3$ expansion;
    • \n
    • pick a number on the opponent's paper and change it by removing a $1$ from its ternary expansion;
    • \n
    • pick a number on either paper and change it by removing a $2$ from its ternary expansion.
    \n

    \nThe player that is unable to make a move loses.
    \nLeading zeros are not allowed in any ternary expansion; in particular nobody can make a move on the number $0$.

    \n\n

    \nAn initial setting is called fair if whichever player moves first will lose the game if both play optimally.

    \n\n

    \nFor example, if initially the integers on the paper of the first player are $1, 5$ and those on the paper of the second player are $2, 4$, then this is a fair initial setting, which we can denote as $(1, 5 \\mid 2, 4)$.
    \nNote that the order of the two integers on a paper does not matter, but the order of the two papers matter.
    \nThus $(5, 1 \\mid 4, 2)$ is considered the same as $(1, 5 \\mid 2, 4)$, while $(2, 4 \\mid 1, 5)$ is a different initial setting.

    \n\n

    \nLet $F(N)$ be the number of fair initial settings where each initial number does not exceed $N$.
    \nFor example, $F(5) = 21$.

    \n\n

    \nFind $F(10^5)$.

    ", "url": "https://projecteuler.net/problem=963", "answer": "55129975871328418"} {"id": 964, "problem": "A group of $k(k-1) / 2 + 1$ children play a game of $k$ rounds.\n\nAt the beginning, they are all seated on chairs arranged in a circle.\n\nDuring the $i$-th round:\n\n- The music starts playing and $i$ children are randomly selected, with all combinations being equally likely. The selected children stand up and dance around.\n\n- When the music stops, these $i$ children sit back down randomly in the $i$ available chairs, with all permutations being equally likely.\n\nLet $P(k)$ be the probability that every child ends up sitting exactly one chair to the right of their original chair when the game ends (at the end of the $k$-th round).\n\nYou are given $P(3) \\approx 1.3888888889 \\mathrm {e}{-2}$.\n\nFind $P(7)$. Give your answer in scientific notation rounded to ten significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.", "raw_html": "

    A group of $k(k-1) / 2 + 1$ children play a game of $k$ rounds.
    \nAt the beginning, they are all seated on chairs arranged in a circle.

    \n\n

    During the $i$-th round:

    \n
      \n
    1. The music starts playing and $i$ children are randomly selected, with all combinations being equally likely. The selected children stand up and dance around.
    2. \n
    3. When the music stops, these $i$ children sit back down randomly in the $i$ available chairs, with all permutations being equally likely.
    4. \n
    \n\n\n

    Let $P(k)$ be the probability that every child ends up sitting exactly one chair to the right of their original chair when the game ends (at the end of the $k$-th round).

    \n\n

    You are given $P(3) \\approx 1.3888888889 \\mathrm {e}{-2}$.

    \n\n

    Find $P(7)$. Give your answer in scientific notation rounded to ten significant digits after the decimal point. Use a lowercase e to separate the mantissa and the exponent.

    ", "url": "https://projecteuler.net/problem=964", "answer": "4.7126135532e-29"} {"id": 965, "problem": "Let $\\{x\\}$ denote the fractional part of a real number $x$.\n\nDefine $f_N(x)$ to be the minimal value of $\\{nx\\}$ for integer $n$ satisfying $0 < n \\le N$.\n\nFurther define $F(N)$ to be the expected value of $f_N(x)$ when $x$ is sampled uniformly in $[0, 1]$.\n\nYou are given $F(1) = \\frac{1}{2}$, $F(4) = \\frac{1}{4}$ and $F(10) \\approx 0.1319444444444$.\n\nFind $F(10^4)$ and give your answer rounded to 13 digits after the decimal point.", "raw_html": "

    Let $\\{x\\}$ denote the fractional part of a real number $x$.

    \n\n

    Define $f_N(x)$ to be the minimal value of $\\{nx\\}$ for integer $n$ satisfying $0 < n \\le N$.
    \nFurther define $F(N)$ to be the expected value of $f_N(x)$ when $x$ is sampled uniformly in $[0, 1]$.

    \n\n

    You are given $F(1) = \\frac{1}{2}$, $F(4) = \\frac{1}{4}$ and $F(10) \\approx 0.1319444444444$.

    \n\n

    Find $F(10^4)$ and give your answer rounded to 13 digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=965", "answer": "0.0003452201133"} {"id": 966, "problem": "Let $I(a, b, c)$ be the largest possible area of intersection between a triangle of side lengths $a, b, c$ and a circle which has the same area as the triangle.\n\nFor example $I(3, 4, 5) \\approx 4.593049$ and $I(3, 4, 6) \\approx 3.552564$.\n\nFind the sum of $I(a, b, c)$ for integers $a, b, c$ such that $1 \\le a \\le b \\le c \\lt a + b$ and $a + b + c \\le 200$.\n\nGive your answer rounded to two digits after the decimal point.", "raw_html": "

    \nLet $I(a, b, c)$ be the largest possible area of intersection between a triangle of side lengths $a, b, c$ and a circle which has the same area as the triangle.
    \nFor example $I(3, 4, 5) \\approx 4.593049$ and $I(3, 4, 6) \\approx 3.552564$.

    \n\n

    \nFind the sum of $I(a, b, c)$ for integers $a, b, c$ such that $1 \\le a \\le b \\le c \\lt a + b$ and $a + b + c \\le 200$.
    \nGive your answer rounded to two digits after the decimal point.

    ", "url": "https://projecteuler.net/problem=966", "answer": "29337152.09"} {"id": 967, "problem": "A positive integer $n$ is considered $B$-trivisible if the sum of all different prime factors of $n$ which are not larger than $B$ is divisible by $3$.\n\nFor example, $175 = 5^2 \\cdot 7$ is $10$-trivisible because $5 + 7 = 12$ which is divisible by $3$. Similarly, $175$ is $4$-trivisible because all primes dividing $175$ are larger than $4$, and the empty summation $0$ is divisible by $3$.\n\nOn the other hand, $175$ is not $6$-trivisible because the sum of relevant primes is $5$ which is not divisible by $3$.\n\nLet $F(N, B)$ be the number of $B$-trivisible integers not larger than $N$.\n\nFor example, $F(10, 4) = 5$, the $4$-trivisible numbers being $1,3,5,7,9$.\n\nYou are also given $F(10, 10) = 3$ and $F(100, 10) = 41$.\n\nFind $F(10^{18}, 120)$.", "raw_html": "

    \nA positive integer $n$ is considered $B$-trivisible if the sum of all different prime factors of $n$ which are not larger than $B$ is divisible by $3$.

    \n\n

    \nFor example, $175 = 5^2 \\cdot 7$ is $10$-trivisible because $5 + 7 = 12$ which is divisible by $3$. Similarly, $175$ is $4$-trivisible because all primes dividing $175$ are larger than $4$, and the empty summation $0$ is divisible by $3$.
    \nOn the other hand, $175$ is not $6$-trivisible because the sum of relevant primes is $5$ which is not divisible by $3$.

    \n\n

    \nLet $F(N, B)$ be the number of $B$-trivisible integers not larger than $N$.

    \n\n

    \nFor example, $F(10, 4) = 5$, the $4$-trivisible numbers being $1,3,5,7,9$.
    \nYou are also given $F(10, 10) = 3$ and $F(100, 10) = 41$.

    \n\n

    \nFind $F(10^{18}, 120)$.

    ", "url": "https://projecteuler.net/problem=967", "answer": "357591131712034236"} {"id": 968, "problem": "Define\n$$P(X_{a,b},X_{a,c},X_{a,d},X_{a,e},X_{b,c},X_{b,d},X_{b,e},X_{c,d},X_{c,e},X_{d,e})$$\nas the sum of $2^a3^b5^c7^d11^e$ over all quintuples of non-negative integers $(a, b, c, d, e)$ such that the sum of each two of the five variables is restricted by a given value. In other words, $a+b \\le X_{a,b}$, $a+d \\le X_{a,d}$, $b+e \\le X_{b,e}$ etc.\n\nFor example, $P(2,2,2,2,2,2,2,2,2,2)=7120$ and $P(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) \\equiv 799809376 \\pmod{10^9 + 7}$.\n\nDefine a sequence $A$ as follows:\n\n- $A_0 = 1$, $A_1 = 7$;\n\n- $A_n =(7A_{n−1}+A_{n-2}^2) \\bmod(10^9+7)$ for $n \\ge 2$.\n\nAlso define $Q(n) = P(A_{10n}, A_{10n+1}, A_{10n+2}, \\dots , A_{10n+9})$.\n\nFind $\\displaystyle\\sum_{0 \\le n \\lt 100}Q(n)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nDefine\n$$P(X_{a,b},X_{a,c},X_{a,d},X_{a,e},X_{b,c},X_{b,d},X_{b,e},X_{c,d},X_{c,e},X_{d,e})$$\nas the sum of $2^a3^b5^c7^d11^e$ over all quintuples of non-negative integers $(a, b, c, d, e)$ such that the sum of each two of the five variables is restricted by a given value. In other words, $a+b \\le X_{a,b}$, $a+d \\le X_{a,d}$, $b+e \\le X_{b,e}$ etc.

    \n\n

    \nFor example, $P(2,2,2,2,2,2,2,2,2,2)=7120$ and $P(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) \\equiv 799809376 \\pmod{10^9 + 7}$.

    \n\n

    \nDefine a sequence $A$ as follows:

    \n
      \n
    • $A_0 = 1$, $A_1 = 7$;
    • \n
    • $A_n =(7A_{n−1}+A_{n-2}^2) \\bmod(10^9+7)$ for $n \\ge 2$.
    \n

    \nAlso define $Q(n) = P(A_{10n}, A_{10n+1}, A_{10n+2}, \\dots , A_{10n+9})$.

    \n\n

    \nFind $\\displaystyle\\sum_{0 \\le n \\lt 100}Q(n)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=968", "answer": "885362394"} {"id": 969, "problem": "Starting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line.\n\nIf we write $\\alpha = H(1)$, then for all positive integers $n$, $H(n)$ can be expressed as a polynomial function of $\\alpha$ with rational coefficients. For example $H(3)=\\alpha^3-2\\alpha^2+\\frac{1}{2}\\alpha$. Define $S(n)$ to be the sum of all integer coefficients in this polynomial form of $H(n)$. Therefore $S(1)=1$ and $S(3)=1+(-2)=-1$.\n\nYou are also given $\\displaystyle \\sum_{n=1}^{10} S(n)=43$.\n\nFind $\\displaystyle\\sum_{n=1}^{10^{18}} S(n)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nStarting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line.\n

    \n

    \nIf we write $\\alpha = H(1)$, then for all positive integers $n$, $H(n)$ can be expressed as a polynomial function of $\\alpha$ with rational coefficients. For example $H(3)=\\alpha^3-2\\alpha^2+\\frac{1}{2}\\alpha$. Define $S(n)$ to be the sum of all integer coefficients in this polynomial form of $H(n)$. Therefore $S(1)=1$ and $S(3)=1+(-2)=-1$.
    \nYou are also given $\\displaystyle \\sum_{n=1}^{10} S(n)=43$.
    \nFind $\\displaystyle\\sum_{n=1}^{10^{18}} S(n)$. Give your answer modulo $10^9+7$.\n

    ", "url": "https://projecteuler.net/problem=969", "answer": "412543690"} {"id": 970, "problem": "Starting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line.\n\nFor example, $H(2) \\approx 4.67077427047$. The first eight digits after the decimal point that are different from six are $70774270$.\n\nSimilarly, $H(3) \\approx 6.6665656395558899$. Here the first eight digits after the decimal point that are different from six are $55395558$.\n\nFind $H(10^6)$ and give as your answer the first eight digits after the decimal point that are different from six.", "raw_html": "

    \nStarting at zero, a kangaroo hops along the real number line in the positive direction. Each successive hop takes the kangaroo forward a uniformly random distance between $0$ and $1$. Let $H(n)$ be the expected number of hops needed for the kangaroo to pass $n$ on the real line.\n

    \n

    \nFor example, $H(2) \\approx 4.67077427047$. The first eight digits after the decimal point that are different from six are $70774270$.\n

    \n

    \nSimilarly, $H(3) \\approx 6.6665656395558899$. Here the first eight digits after the decimal point that are different from six are $55395558$.\n

    \n

    \nFind $H(10^6)$ and give as your answer the first eight digits after the decimal point that are different from six.\n

    ", "url": "https://projecteuler.net/problem=970", "answer": "44754029"} {"id": 971, "problem": "Let $p$ be a prime of the form $5k-4$ and define $f_p(x) = \\left(x^k+x\\right) \\bmod p$.\n\nLet $C(p)$ be the number of values $0 \\le x \\lt p$ such that $f_p^{(m)}(x) = x$ for some positive integer $m$, that is, $x$ can be obtained by iteratively applying $f_p$ on itself starting at $x$.\n\nFor example, $C(11) = 7$, due to $x = 0, 1, 2, 3, 8, 9, 10$.\n\nLet $S(N)$ be the sum of $C(p)$ for all primes of the form $5k-4$ not exceeding $N$. For example $S(100) = 127$.\n\nFind $S(10^8)$.", "raw_html": "

    Let $p$ be a prime of the form $5k-4$ and define $f_p(x) = \\left(x^k+x\\right) \\bmod p$.

    \n\n

    Let $C(p)$ be the number of values $0 \\le x \\lt p$ such that $f_p^{(m)}(x) = x$ for some positive integer $m$, that is, $x$ can be obtained by iteratively applying $f_p$ on itself starting at $x$.

    \n\n

    For example, $C(11) = 7$, due to $x = 0, 1, 2, 3, 8, 9, 10$.

    \n\n

    Let $S(N)$ be the sum of $C(p)$ for all primes of the form $5k-4$ not exceeding $N$. For example $S(100) = 127$.

    \n\n

    Find $S(10^8)$.

    ", "url": "https://projecteuler.net/problem=971", "answer": "33626723890930"} {"id": 972, "problem": "The hyperbolic plane can be represented by the open unit disc, namely the set of points $(x, y)$ in $\\Bbb R^2$ with $x^2 + y^2 < 1$.\n\nA geodesic is defined as either a diameter of the open unit disc or a circular arc contained within the disc that is orthogonal to the boundary of the disc.\n\nThe following diagram shows the hyperbolic plane with two geodesics; one is a diameter and the other is a circular arc.\n\nLet $\\mathcal V(N)$ be the set of points $(x, y)$ such that $x^2 + y^2 \\lt 1$ and $x, y$ are both rational numbers with denominator not exceeding $N$.\n\nLet $T(N)$ be the number of ordered triples $(P, Q, R)$ such that $P, Q, R$ are three different points in $\\mathcal V(N)$ and there is a hyperbolic line passing through all of them.\n\nFor example, $T(2) = 24$ and $T(3) = 1296$.\n\nFind $T(12)$.", "raw_html": "

    \nThe hyperbolic plane can be represented by the open unit disc, namely the set of points $(x, y)$ in $\\Bbb R^2$ with $x^2 + y^2 < 1$.

    \n\n

    \nA geodesic is defined as either a diameter of the open unit disc or a circular arc contained within the disc that is orthogonal to the boundary of the disc.
    \nThe following diagram shows the hyperbolic plane with two geodesics; one is a diameter and the other is a circular arc.

    \n
    \"0972_hyperbolic.png\"
    \n\n

    \nLet $\\mathcal V(N)$ be the set of points $(x, y)$ such that $x^2 + y^2 \\lt 1$ and $x, y$ are both rational numbers with denominator not exceeding $N$.

    \n\n

    \nLet $T(N)$ be the number of ordered triples $(P, Q, R)$ such that $P, Q, R$ are three different points in $\\mathcal V(N)$ and there is a hyperbolic line passing through all of them.
    \nFor example, $T(2) = 24$ and $T(3) = 1296$.

    \n\n

    \nFind $T(12)$.

    ", "url": "https://projecteuler.net/problem=972", "answer": "3575508"} {"id": 973, "problem": "A game is played with $n$ cards.\nAt the start the cards are dealt out onto a table to get $n$ piles of size one.\n\nEach round proceeds as follows:\n\n- Select a pile at random and pick it up.\n\n- Randomly choose a pile from the table and add the top card of the picked-up pile to it.\n\n- Redistribute any remaining cards from the picked-up pile by dealing them into new single-card piles.\n\nThe game ends when all cards are in a single pile.\n\nAt the end of each round a score is obtained by bitwise-XORing the size of each pile. The score is summed across the rounds. Let $X(n)$ be the expected total score at the end of the game.\n\nYou are given $X(2) = 2$, $X(4) = 14$ and $X(10) = 1418$.\n\nFind $X(10^4)$. Give your answer modulo $10^9+7$.", "raw_html": "

    \nA game is played with $n$ cards.\nAt the start the cards are dealt out onto a table to get $n$ piles of size one.

    \n\n

    \nEach round proceeds as follows:

    \n
      \n
    1. Select a pile at random and pick it up.
    2. \n
    3. Randomly choose a pile from the table and add the top card of the picked-up pile to it.
    4. \n
    5. Redistribute any remaining cards from the picked-up pile by dealing them into new single-card piles.
    \n\n

    \nThe game ends when all cards are in a single pile.

    \n\n

    \nAt the end of each round a score is obtained by bitwise-XORing the size of each pile. The score is summed across the rounds. Let $X(n)$ be the expected total score at the end of the game.

    \n\n

    \nYou are given $X(2) = 2$, $X(4) = 14$ and $X(10) = 1418$.

    \n\n

    \nFind $X(10^4)$. Give your answer modulo $10^9+7$.

    ", "url": "https://projecteuler.net/problem=973", "answer": "427278142"} {"id": 974, "problem": "A very odd number is a number which contains only odd digits and is divisible by $105$.\nFurther each odd digit occurs an odd number of times.\n\nDefine $\\Theta (n)$ be the $n$th very odd number, then $\\Theta (1) = 1117935$ and $\\Theta(10^3) = 11137955115$.\n\nFind $\\Theta(10^{16})$.", "raw_html": "

    \nA very odd number is a number which contains only odd digits and is divisible by $105$.\nFurther each odd digit occurs an odd number of times.

    \n\n

    \nDefine $\\Theta (n)$ be the $n$th very odd number, then $\\Theta (1) = 1117935$ and $\\Theta(10^3) = 11137955115$.

    \n\n

    \nFind $\\Theta(10^{16})$.

    ", "url": "https://projecteuler.net/problem=974", "answer": "13313751171933973557517973175"} {"id": 975, "problem": "Given a pair $(a,b)$ of coprime odd positive integers, define the function\n$$H_{a,b}(x)=\\frac{1}{2}-\\frac{1}{2(a+b)}\\Bigl(b\\cos(a\\pi x)+a\\cos(b\\pi x)\\Bigr)\n$$It can be seen that $H_{a,b}(0)=0$, $H_{a,b}(1)=1$, and $0 < H_{a,b}(x) < 1$ for all $x$ strictly between $0$ and $1$.\n\nGiven two such pairs $(a,b)$ and $(c,d)$, paths of infinitesimal width traverse the unit cube internally through every point $(x,y,z)\\in [0,1]^3$ such that $z=H_{a,b}(x)=H_{c,d}(y)$. Remarkably, it can be shown that the point $(0,0,0)$ is always connected to the opposite corner $(1,1,1)$. Furthermore, with the additional condition $\\gcd(a+b,c+d)\\in\\{2,4\\}$, it can be shown that there is exactly one path connecting the two points.\n\nShown above are two examples, as viewed from above the cube. That is, we see the paths projected onto the $xy$-plane, with corresponding $z$ values indicated with varying colour. In the second example some paths are coloured grey to indicate that, while they exist, they do not form part of the path from $(0,0,0)$ to $(1,1,1)$.\n\nDefine $F(a, b, c, d)$ to be the sum of the absolute changes in height (or $z$-coordinate) over all uphill and downhill sections of the path from $(0,0,0)$ to $(1,1,1)$. In the first example above, the path climbs $\\approx4.00886$ over eleven uphill sections, and descends $\\approx3.00886$ over ten downhill sections, giving $F(3,5,3,7)\\approx7.01772$. You are also given $F(7,17,9,19)\\approx 26.79578$.\n\nLet $G(m, n)$ be the sum of $F(p,q,p,2q-p)$ over all pairs $(p,q)$ of primes, $m\\leq p < q\\leq n$. You are given $G(3, 20)\\approx463.80866$.\n\nFind $G(500,1000)$ giving your answer rounded to five digits after the decimal point.", "raw_html": "

    \nGiven a pair $(a,b)$ of coprime odd positive integers, define the function\n$$H_{a,b}(x)=\\frac{1}{2}-\\frac{1}{2(a+b)}\\Bigl(b\\cos(a\\pi x)+a\\cos(b\\pi x)\\Bigr)\n$$It can be seen that $H_{a,b}(0)=0$, $H_{a,b}(1)=1$, and $0 < H_{a,b}(x) < 1$ for all $x$ strictly between $0$ and $1$.\n

    \nGiven two such pairs $(a,b)$ and $(c,d)$, paths of infinitesimal width traverse the unit cube internally through every point $(x,y,z)\\in [0,1]^3$ such that $z=H_{a,b}(x)=H_{c,d}(y)$. Remarkably, it can be shown that the point $(0,0,0)$ is always connected to the opposite corner $(1,1,1)$. Furthermore, with the additional condition $\\gcd(a+b,c+d)\\in\\{2,4\\}$, it can be shown that there is exactly one path connecting the two points.\n

    \n
    \"0975_examples.png\"
    \n

    \nShown above are two examples, as viewed from above the cube. That is, we see the paths projected onto the $xy$-plane, with corresponding $z$ values indicated with varying colour. In the second example some paths are coloured grey to indicate that, while they exist, they do not form part of the path from $(0,0,0)$ to $(1,1,1)$.\n

    \n

    \nDefine $F(a, b, c, d)$ to be the sum of the absolute changes in height (or $z$-coordinate) over all uphill and downhill sections of the path from $(0,0,0)$ to $(1,1,1)$. In the first example above, the path climbs $\\approx4.00886$ over eleven uphill sections, and descends $\\approx3.00886$ over ten downhill sections, giving $F(3,5,3,7)\\approx7.01772$. You are also given $F(7,17,9,19)\\approx 26.79578$.\n

    \n

    \nLet $G(m, n)$ be the sum of $F(p,q,p,2q-p)$ over all pairs $(p,q)$ of primes, $m\\leq p < q\\leq n$. You are given $G(3, 20)\\approx463.80866$.\n

    \nFind $G(500,1000)$ giving your answer rounded to five digits after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=975", "answer": "88597366.47748"} {"id": 976, "problem": "Two players X and O play a game with $k$ strips of squares of lengths $n_1,\\dots,n_k$, originally all blank.\n\nStarting with X, they make moves in turn. At X's turn, X draws an \"X\" symbol; at O's turn, O draws an \"O\" symbol.\n\nThe symbol must be drawn in one blank square with either red or blue pen, subject to the following restrictions:\n\n- two symbols in adjacent squares on one strip must be different symbols and must have different colour;\n\n- if there is at least one blank strip, then one must draw on a blank strip.\n\nWhoever does not have a valid move loses the game.\n\nLet $P(K, N)$ be the number of tuples $(n_1,\\dots,n_k)$ such that $1 \\leq k \\leq K$, $1\\leq n_1\\leq\\cdots\\leq n_k\\leq N$ and that X has a winning strategy to the corresponding game.\n\nFor example, $P(2, 4)=7$ and $P(5, 10) = 901$.\n\nFind $P(10^7, 10^7)\\bmod 1234567891$.", "raw_html": "

    \nTwo players X and O play a game with $k$ strips of squares of lengths $n_1,\\dots,n_k$, originally all blank.

    \n\n

    \nStarting with X, they make moves in turn. At X's turn, X draws an \"X\" symbol; at O's turn, O draws an \"O\" symbol.
    \nThe symbol must be drawn in one blank square with either red or blue pen, subject to the following restrictions:

    \n
      \n
    1. two symbols in adjacent squares on one strip must be different symbols and must have different colour;
    2. \n
    3. if there is at least one blank strip, then one must draw on a blank strip.
    \n

    \nWhoever does not have a valid move loses the game.

    \n\n

    \nLet $P(K, N)$ be the number of tuples $(n_1,\\dots,n_k)$ such that $1 \\leq k \\leq K$, $1\\leq n_1\\leq\\cdots\\leq n_k\\leq N$ and that X has a winning strategy to the corresponding game.
    \nFor example, $P(2, 4)=7$ and $P(5, 10) = 901$.

    \n\n

    \nFind $P(10^7, 10^7)\\bmod 1234567891$.

    ", "url": "https://projecteuler.net/problem=976", "answer": "675608326"} {"id": 977, "problem": "For a positive integer $n$, let $F(n)$ denote the number of functions $f$ from the set $S_n=\\{1,2,\\dots,n\\}$ to itself such that $f^{(x)}(y)=f^{(y)}(x)$ for any $x,y$ in $S_n$. Here $f^{(k)}$ denotes the $k$-th iterated composition of $f$, e.g. $f^{(2)}(x)=f(f(x))$.\n\nFor example, $F(3)=8$, $F(7)=174$, $F(100)=570271270297640131$.\n\nFind $F(10^6) \\bmod (10^9+7)$.", "raw_html": "

    For a positive integer $n$, let $F(n)$ denote the number of functions $f$ from the set $S_n=\\{1,2,\\dots,n\\}$ to itself such that $f^{(x)}(y)=f^{(y)}(x)$ for any $x,y$ in $S_n$. Here $f^{(k)}$ denotes the $k$-th iterated composition of $f$, e.g. $f^{(2)}(x)=f(f(x))$.

    \n\n

    For example, $F(3)=8$, $F(7)=174$, $F(100)=570271270297640131$.

    \n\n

    Find $F(10^6) \\bmod (10^9+7)$.

    ", "url": "https://projecteuler.net/problem=977", "answer": "537945304"} {"id": 978, "problem": "In this problem we consider a random walk on the integers $\\mathbb{Z}$, in which our position at time $t$ is denoted as $X_t$.\n\nAt time $0$ we start at position $0$. That is, $X_0=0$.\n\nAt time $1$ we jump to position $1$. That is, $X_1=1$.\n\nThereafter, at time $t=2,3,\\dots$ we make a jump of size $|X_{t-2}|$ in either the positive or negative direction, with probability $1/2$ each way. If $X_{t-2}=0$ we stay put at time $t$.\n\nAt $t=5$ we find our position $X_5$ has the following distribution:\n$$\nX_5=\\begin{cases}\n-1\\quad&\\text{with probability }3/8\\\\\n1\\quad&\\text{with probability }3/8\\\\\n3\\quad&\\text{with probability }1/8\\\\\n5\\quad&\\text{with probability }1/8\\\\\n\\end{cases}\n$$\nThe standard deviation $\\sigma$ of a random variable $X$ with mean $\\mu$ is defined as\n$$\n\\sigma=\\sqrt{\\mathbb{E}[X^2]-\\mu^2}\n$$\nFurthermore the skewness of $X$ is defined as\n$$\n\\text{Skew}(X)=\\mathbb{E}\\biggl[\\Bigl(\\frac{X-\\mu}{\\sigma}\\Bigr)^3\\biggr]\n$$\nFor $X_5$, which has mean $1$ and standard deviation $2$, we find $\\text{Skew}(X_5)=0.75$. You are also given $\\text{Skew}(X_{10})\\approx2.50997097$.\n\nFind $\\text{Skew}(X_{50})$. Give your answer rounded to eight digits after the decimal point.", "raw_html": "

    \nIn this problem we consider a random walk on the integers $\\mathbb{Z}$, in which our position at time $t$ is denoted as $X_t$.\n

    \n

    \nAt time $0$ we start at position $0$. That is, $X_0=0$.
    \nAt time $1$ we jump to position $1$. That is, $X_1=1$.
    \nThereafter, at time $t=2,3,\\dots$ we make a jump of size $|X_{t-2}|$ in either the positive or negative direction, with probability $1/2$ each way. If $X_{t-2}=0$ we stay put at time $t$.\n

    \n

    \nAt $t=5$ we find our position $X_5$ has the following distribution:\n$$\nX_5=\\begin{cases}\n-1\\quad&\\text{with probability }3/8\\\\\n1\\quad&\\text{with probability }3/8\\\\\n3\\quad&\\text{with probability }1/8\\\\\n5\\quad&\\text{with probability }1/8\\\\\n\\end{cases}\n$$\nThe standard deviation $\\sigma$ of a random variable $X$ with mean $\\mu$ is defined as\n$$\n\\sigma=\\sqrt{\\mathbb{E}[X^2]-\\mu^2}\n$$\nFurthermore the skewness of $X$ is defined as\n$$\n\\text{Skew}(X)=\\mathbb{E}\\biggl[\\Bigl(\\frac{X-\\mu}{\\sigma}\\Bigr)^3\\biggr]\n$$\nFor $X_5$, which has mean $1$ and standard deviation $2$, we find $\\text{Skew}(X_5)=0.75$. You are also given $\\text{Skew}(X_{10})\\approx2.50997097$.\n

    \n

    \nFind $\\text{Skew}(X_{50})$. Give your answer rounded to eight digits after the decimal point.\n

    ", "url": "https://projecteuler.net/problem=978", "answer": "254.54470757"} {"id": 979, "problem": "The hyperbolic plane, represented by the open unit disc, can be tiled by heptagons. Every tile is a hyperbolic heptagon (i.e. it has seven edges which are segments of geodesics in the hyperbolic plane) and every vertex is shared by three tiles.\n\nPlease refer to Problem 972 for some of the definitions.\n\nThe diagram below shows an illustration of this tiling.\n\nNow, a hyperbolic frog starts from one of the heptagons, as shown in the diagram. At each step, it can jump to any one of the seven adjacent tiles.\n\nDefine $F(n)$ to be the number of paths the frog can trace so that after $n$ steps it lands back at the starting tile.\n\nYou are given $F(4) = 119$.\n\nFind $F(20)$.", "raw_html": "

    The hyperbolic plane, represented by the open unit disc, can be tiled by heptagons. Every tile is a hyperbolic heptagon (i.e. it has seven edges which are segments of geodesics in the hyperbolic plane) and every vertex is shared by three tiles.
    \nPlease refer to Problem 972 for some of the definitions.

    \n\n

    The diagram below shows an illustration of this tiling.

    \n
    \"0979_heptagons_frog.png\"
    \n\n

    Now, a hyperbolic frog starts from one of the heptagons, as shown in the diagram. At each step, it can jump to any one of the seven adjacent tiles.

    \n\n

    Define $F(n)$ to be the number of paths the frog can trace so that after $n$ steps it lands back at the starting tile.
    \nYou are given $F(4) = 119$.

    \n\n

    Find $F(20)$.

    ", "url": "https://projecteuler.net/problem=979", "answer": "189306828278449"} {"id": 980, "problem": "Starting from an empty string, we want to build a string with letters \"x\", \"y\", \"z\". At each step, one of the following operations is performed:\n\n- insert two consecutive identical letters \"xx\", \"yy\" or \"zz\" anywhere into the string;\n\n- replace one letter in the string with two consecutive letters, according to the rule: \"x\" $\\to$ \"yz\", \"y\" $\\to$ \"zx\", \"z\" $\\to$ \"xy\";\n\n- exchange two consecutive different letters in the string, e.g. \"xy\" $\\to$ \"yx\", \"zx\" $\\to$ \"xz\", etc.\n\nA string is called neutral if it is possible to produce the string from the empty string after an even number of steps.\n\nWe define a sequence $(a_n)_{n \\ge 0}$: $a_0=88\\,888\\,888$ and $a_n=(8888\\cdot a_{n-1})\\bmod 888\\,888\\,883$ for $n \\gt 0$.\n\nLet $b_n = a_n \\bmod 3$. For each $i \\ge 0$, a string $c(i)$ of length $50$ is defined by translating the finite sequence $b_{50i},b_{50i+1},\\dots,b_{50i+49}$ via the rule: $0 \\to$ \"x\", $1 \\to$ \"y\", $2 \\to$ \"z\".\n\nLet $F(N)$ be the number of ordered pairs $(i, j)$ with $0 \\le i, j \\lt N$ such that the concatenated string $c(i)c(j)$ is neutral.\n\nFor example, $F(10) = 13$ and $F(100) = 1224$.\n\nFind $F(10^6)$.", "raw_html": "

    \nStarting from an empty string, we want to build a string with letters \"x\", \"y\", \"z\". At each step, one of the following operations is performed:

    \n
      \n
    • insert two consecutive identical letters \"xx\", \"yy\" or \"zz\" anywhere into the string;
    • \n
    • replace one letter in the string with two consecutive letters, according to the rule: \"x\" $\\to$ \"yz\", \"y\" $\\to$ \"zx\", \"z\" $\\to$ \"xy\";
    • \n
    • exchange two consecutive different letters in the string, e.g. \"xy\" $\\to$ \"yx\", \"zx\" $\\to$ \"xz\", etc.
    \n

    \nA string is called neutral if it is possible to produce the string from the empty string after an even number of steps.

    \n\n

    \nWe define a sequence $(a_n)_{n \\ge 0}$: $a_0=88\\,888\\,888$ and $a_n=(8888\\cdot a_{n-1})\\bmod 888\\,888\\,883$ for $n \\gt 0$.

    \n\n

    \nLet $b_n = a_n \\bmod 3$. For each $i \\ge 0$, a string $c(i)$ of length $50$ is defined by translating the finite sequence $b_{50i},b_{50i+1},\\dots,b_{50i+49}$ via the rule: $0 \\to$ \"x\", $1 \\to$ \"y\", $2 \\to$ \"z\".

    \n\n

    \nLet $F(N)$ be the number of ordered pairs $(i, j)$ with $0 \\le i, j \\lt N$ such that the concatenated string $c(i)c(j)$ is neutral.
    \nFor example, $F(10) = 13$ and $F(100) = 1224$.

    \n\n

    \nFind $F(10^6)$.

    ", "url": "https://projecteuler.net/problem=980", "answer": "124999683766"} {"id": 981, "problem": "Starting from an empty string, we want to build a string with letters \"x\", \"y\", \"z\". At each step, one of the following operations is performed:\n\n- insert two consecutive identical letters \"xx\", \"yy\" or \"zz\" anywhere into the string;\n\n- replace one letter in the string with two consecutive letters, according to the rule: \"x\" $\\to$ \"yz\", \"y\" $\\to$ \"zx\", \"z\" $\\to$ \"xy\";\n\n- exchange two consecutive different letters in the string, e.g. \"xy\" $\\to$ \"yx\", \"zx\" $\\to$ \"xz\", etc.\n\nA string is called neutral if it is possible to produce the string from the empty string after an even number of steps.\n\nLet $N(X, Y, Z)$ be the number of neutral strings which contain $X$ copies of \"x\", $Y$ copies of \"y\" and $Z$ copies of \"z\".\n\nFor example, $N(2, 2, 2) = 42$ and $N(8, 8, 8) = 4732773210$.\n\nFind the sum of $N(i^3, j^3, k^3)$ for $0 \\le i, j, k \\lt 88$. Give your answer modulo $888\\,888\\,883$.", "raw_html": "

    \nStarting from an empty string, we want to build a string with letters \"x\", \"y\", \"z\". At each step, one of the following operations is performed:

    \n
      \n
    • insert two consecutive identical letters \"xx\", \"yy\" or \"zz\" anywhere into the string;
    • \n
    • replace one letter in the string with two consecutive letters, according to the rule: \"x\" $\\to$ \"yz\", \"y\" $\\to$ \"zx\", \"z\" $\\to$ \"xy\";
    • \n
    • exchange two consecutive different letters in the string, e.g. \"xy\" $\\to$ \"yx\", \"zx\" $\\to$ \"xz\", etc.
    \n

    \nA string is called neutral if it is possible to produce the string from the empty string after an even number of steps.

    \n

    \nLet $N(X, Y, Z)$ be the number of neutral strings which contain $X$ copies of \"x\", $Y$ copies of \"y\" and $Z$ copies of \"z\".
    \nFor example, $N(2, 2, 2) = 42$ and $N(8, 8, 8) = 4732773210$.

    \n

    \nFind the sum of $N(i^3, j^3, k^3)$ for $0 \\le i, j, k \\lt 88$. Give your answer modulo $888\\,888\\,883$.

    ", "url": "https://projecteuler.net/problem=981", "answer": "794963735"}