SHARE
TWEET

Project Euler Answers < 200000000

a guest Aug 2nd, 2015 4,702 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Attribution-Non-Commercial-Share Alike 2.0, Attribution to Kyle Keen at kmkeen.com/local-euler/
  2.  
  3.  
  4. Project Euler is protected under
  5. Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales
  6.  
  7. ^sup and [sub] are frequently use for subscripts/superscripts.
  8. Many symbols are utf8, my apologies if you are on a 7-bit TTY.
  9.  
  10. Solutions are hashed with md5sum
  11. echo -n 'myanswer' | md5sum
  12.  
  13.  
  14.  
  15. generated on 2014-6-29 at 15:46
  16.  
  17.  
  18.  
  19. Problem 1
  20. =========
  21.  
  22.  
  23.    If we list all the natural numbers below 10 that are multiples of 3 or 5,
  24.    we get 3, 5, 6 and 9. The sum of these multiples is 23.
  25.  
  26.    Find the sum of all the multiples of 3 or 5 below 1000.
  27.  
  28.    
  29.    Answer: 233168
  30.  
  31.  
  32. Problem 2
  33. =========
  34.  
  35.  
  36.    Each new term in the Fibonacci sequence is generated by adding the
  37.    previous two terms. By starting with 1 and 2, the first 10 terms will be:
  38.  
  39.                      1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
  40.  
  41.    By considering the terms in the Fibonacci sequence whose values do not
  42.    exceed four million, find the sum of the even-valued terms.
  43.  
  44.    
  45.    Answer: 4613732
  46.  
  47.  
  48. Problem 3
  49. =========
  50.  
  51.  
  52.    The prime factors of 13195 are 5, 7, 13 and 29.
  53.  
  54.    What is the largest prime factor of the number 600851475143 ?
  55.  
  56.    
  57.    Answer: 6857
  58.  
  59.  
  60. Problem 4
  61. =========
  62.  
  63.  
  64.    A palindromic number reads the same both ways. The largest palindrome made
  65.    from the product of two 2-digit numbers is 9009 = 91 × 99.
  66.  
  67.    Find the largest palindrome made from the product of two 3-digit numbers.
  68.  
  69.    
  70.    Answer: 906609
  71.  
  72.  
  73. Problem 5
  74. =========
  75.  
  76.  
  77.    2520 is the smallest number that can be divided by each of the numbers
  78.    from 1 to 10 without any remainder.
  79.  
  80.    What is the smallest positive number that is evenly divisible by all of
  81.    the numbers from 1 to 20?
  82.  
  83.    
  84.    Answer: 232792560
  85.  
  86.  
  87. Problem 6
  88. =========
  89.  
  90.  
  91.    The sum of the squares of the first ten natural numbers is,
  92.  
  93.                           1^2 + 2^2 + ... + 10^2 = 385
  94.  
  95.    The square of the sum of the first ten natural numbers is,
  96.  
  97.                        (1 + 2 + ... + 10)^2 = 55^2 = 3025
  98.  
  99.    Hence the difference between the sum of the squares of the first ten
  100.    natural numbers and the square of the sum is 3025 − 385 = 2640.
  101.  
  102.    Find the difference between the sum of the squares of the first one
  103.    hundred natural numbers and the square of the sum.
  104.  
  105.    
  106.    Answer: 25164150
  107.  
  108.  
  109. Problem 7
  110. =========
  111.  
  112.  
  113.    By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
  114.    that the 6th prime is 13.
  115.  
  116.    What is the 10 001st prime number?
  117.  
  118.    
  119.    Answer: 104743
  120.  
  121.  
  122. Problem 8
  123. =========
  124.  
  125.  
  126.    The four adjacent digits in the 1000-digit number that have the greatest
  127.    product are 9 × 9 × 8 × 9 = 5832.
  128.  
  129.                73167176531330624919225119674426574742355349194934
  130.                96983520312774506326239578318016984801869478851843
  131.                85861560789112949495459501737958331952853208805511
  132.                12540698747158523863050715693290963295227443043557
  133.                66896648950445244523161731856403098711121722383113
  134.                62229893423380308135336276614282806444486645238749
  135.                30358907296290491560440772390713810515859307960866
  136.                70172427121883998797908792274921901699720888093776
  137.                65727333001053367881220235421809751254540594752243
  138.                52584907711670556013604839586446706324415722155397
  139.                53697817977846174064955149290862569321978468622482
  140.                83972241375657056057490261407972968652414535100474
  141.                82166370484403199890008895243450658541227588666881
  142.                16427171479924442928230863465674813919123162824586
  143.                17866458359124566529476545682848912883142607690042
  144.                24219022671055626321111109370544217506941658960408
  145.                07198403850962455444362981230987879927244284909188
  146.                84580156166097919133875499200524063689912560717606
  147.                05886116467109405077541002256983155200055935729725
  148.                71636269561882670428252483600823257530420752963450
  149.  
  150.    Find the thirteen adjacent digits in the 1000-digit number that have the
  151.    greatest product. What is the value of this product?
  152.  
  153.    
  154.    Answer: 23514624000
  155.  
  156.  
  157. Problem 9
  158. =========
  159.  
  160.  
  161.    A Pythagorean triplet is a set of three natural numbers, a < b < c, for
  162.    which,
  163.  
  164.                                 a^2 + b^2 = c^2
  165.  
  166.    For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
  167.  
  168.    There exists exactly one Pythagorean triplet for which a + b + c = 1000.
  169.    Find the product abc.
  170.  
  171.    
  172.    Answer: 31875000
  173.  
  174.  
  175. Problem 10
  176. ==========
  177.  
  178.  
  179.    The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
  180.  
  181.    Find the sum of all the primes below two million.
  182.  
  183.    
  184.    Answer: 142913828922
  185.  
  186.  
  187. Problem 11
  188. ==========
  189.  
  190.  
  191.    In the 20×20 grid below, four numbers along a diagonal line have been
  192.    marked in red.
  193.  
  194.           08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
  195.           49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
  196.           81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
  197.           52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
  198.           22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
  199.           24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
  200.           32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
  201.           67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
  202.           24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
  203.           21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
  204.           78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
  205.           16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
  206.           86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
  207.           19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
  208.           04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
  209.           88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
  210.           04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
  211.           20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
  212.           20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
  213.           01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
  214.  
  215.    The product of these numbers is 26 × 63 × 78 × 14 = 1788696.
  216.  
  217.    What is the greatest product of four adjacent numbers in the same
  218.    direction (up, down, left, right, or diagonally) in the 20×20 grid?
  219.  
  220.    
  221.    Answer: 70600674
  222.  
  223.  
  224. Problem 12
  225. ==========
  226.  
  227.  
  228.    The sequence of triangle numbers is generated by adding the natural
  229.    numbers. So the 7^th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 =
  230.    28. The first ten terms would be:
  231.  
  232.                     1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
  233.  
  234.    Let us list the factors of the first seven triangle numbers:
  235.  
  236.       1: 1
  237.       3: 1,3
  238.       6: 1,2,3,6
  239.      10: 1,2,5,10
  240.      15: 1,3,5,15
  241.      21: 1,3,7,21
  242.      28: 1,2,4,7,14,28
  243.  
  244.    We can see that 28 is the first triangle number to have over five
  245.    divisors.
  246.  
  247.    What is the value of the first triangle number to have over five hundred
  248.    divisors?
  249.  
  250.    
  251.    Answer: 76576500
  252.  
  253.  
  254. Problem 13
  255. ==========
  256.  
  257.  
  258.    Work out the first ten digits of the sum of the following one-hundred
  259.    50-digit numbers.
  260.  
  261.                37107287533902102798797998220837590246510135740250
  262.                46376937677490009712648124896970078050417018260538
  263.                74324986199524741059474233309513058123726617309629
  264.                91942213363574161572522430563301811072406154908250
  265.                23067588207539346171171980310421047513778063246676
  266.                89261670696623633820136378418383684178734361726757
  267.                28112879812849979408065481931592621691275889832738
  268.                44274228917432520321923589422876796487670272189318
  269.                47451445736001306439091167216856844588711603153276
  270.                70386486105843025439939619828917593665686757934951
  271.                62176457141856560629502157223196586755079324193331
  272.                64906352462741904929101432445813822663347944758178
  273.                92575867718337217661963751590579239728245598838407
  274.                58203565325359399008402633568948830189458628227828
  275.                80181199384826282014278194139940567587151170094390
  276.                35398664372827112653829987240784473053190104293586
  277.                86515506006295864861532075273371959191420517255829
  278.                71693888707715466499115593487603532921714970056938
  279.                54370070576826684624621495650076471787294438377604
  280.                53282654108756828443191190634694037855217779295145
  281.                36123272525000296071075082563815656710885258350721
  282.                45876576172410976447339110607218265236877223636045
  283.                17423706905851860660448207621209813287860733969412
  284.                81142660418086830619328460811191061556940512689692
  285.                51934325451728388641918047049293215058642563049483
  286.                62467221648435076201727918039944693004732956340691
  287.                15732444386908125794514089057706229429197107928209
  288.                55037687525678773091862540744969844508330393682126
  289.                18336384825330154686196124348767681297534375946515
  290.                80386287592878490201521685554828717201219257766954
  291.                78182833757993103614740356856449095527097864797581
  292.                16726320100436897842553539920931837441497806860984
  293.                48403098129077791799088218795327364475675590848030
  294.                87086987551392711854517078544161852424320693150332
  295.                59959406895756536782107074926966537676326235447210
  296.                69793950679652694742597709739166693763042633987085
  297.                41052684708299085211399427365734116182760315001271
  298.                65378607361501080857009149939512557028198746004375
  299.                35829035317434717326932123578154982629742552737307
  300.                94953759765105305946966067683156574377167401875275
  301.                88902802571733229619176668713819931811048770190271
  302.                25267680276078003013678680992525463401061632866526
  303.                36270218540497705585629946580636237993140746255962
  304.                24074486908231174977792365466257246923322810917141
  305.                91430288197103288597806669760892938638285025333403
  306.                34413065578016127815921815005561868836468420090470
  307.                23053081172816430487623791969842487255036638784583
  308.                11487696932154902810424020138335124462181441773470
  309.                63783299490636259666498587618221225225512486764533
  310.                67720186971698544312419572409913959008952310058822
  311.                95548255300263520781532296796249481641953868218774
  312.                76085327132285723110424803456124867697064507995236
  313.                37774242535411291684276865538926205024910326572967
  314.                23701913275725675285653248258265463092207058596522
  315.                29798860272258331913126375147341994889534765745501
  316.                18495701454879288984856827726077713721403798879715
  317.                38298203783031473527721580348144513491373226651381
  318.                34829543829199918180278916522431027392251122869539
  319.                40957953066405232632538044100059654939159879593635
  320.                29746152185502371307642255121183693803580388584903
  321.                41698116222072977186158236678424689157993532961922
  322.                62467957194401269043877107275048102390895523597457
  323.                23189706772547915061505504953922979530901129967519
  324.                86188088225875314529584099251203829009407770775672
  325.                11306739708304724483816533873502340845647058077308
  326.                82959174767140363198008187129011875491310547126581
  327.                97623331044818386269515456334926366572897563400500
  328.                42846280183517070527831839425882145521227251250327
  329.                55121603546981200581762165212827652751691296897789
  330.                32238195734329339946437501907836945765883352399886
  331.                75506164965184775180738168837861091527357929701337
  332.                62177842752192623401942399639168044983993173312731
  333.                32924185707147349566916674687634660915035914677504
  334.                99518671430235219628894890102423325116913619626622
  335.                73267460800591547471830798392868535206946944540724
  336.                76841822524674417161514036427982273348055556214818
  337.                97142617910342598647204516893989422179826088076852
  338.                87783646182799346313767754307809363333018982642090
  339.                10848802521674670883215120185883543223812876952786
  340.                71329612474782464538636993009049310363619763878039
  341.                62184073572399794223406235393808339651327408011116
  342.                66627891981488087797941876876144230030984490851411
  343.                60661826293682836764744779239180335110989069790714
  344.                85786944089552990653640447425576083659976645795096
  345.                66024396409905389607120198219976047599490197230297
  346.                64913982680032973156037120041377903785566085089252
  347.                16730939319872750275468906903707539413042652315011
  348.                94809377245048795150954100921645863754710598436791
  349.                78639167021187492431995700641917969777599028300699
  350.                15368713711936614952811305876380278410754449733078
  351.                40789923115535562561142322423255033685442488917353
  352.                44889911501440648020369068063960672322193204149535
  353.                41503128880339536053299340368006977710650566631954
  354.                81234880673210146739058568557934581403627822703280
  355.                82616570773948327592232845941706525094512325230608
  356.                22918802058777319719839450180888072429661980811197
  357.                77158542502016545090413245809786882778948721859617
  358.                72107838435069186155435662884062257473692284509516
  359.                20849603980134001723930671666823555245252804609722
  360.                53503534226472524250874054075591789781264330331690
  361.    
  362.    Answer: 5537376230
  363.  
  364.  
  365. Problem 14
  366. ==========
  367.  
  368.  
  369.    The following iterative sequence is defined for the set of positive
  370.    integers:
  371.  
  372.    n → n/2 (n is even)
  373.    n → 3n + 1 (n is odd)
  374.  
  375.    Using the rule above and starting with 13, we generate the following
  376.    sequence:
  377.  
  378.                    13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
  379.  
  380.    It can be seen that this sequence (starting at 13 and finishing at 1)
  381.    contains 10 terms. Although it has not been proved yet (Collatz Problem),
  382.    it is thought that all starting numbers finish at 1.
  383.  
  384.    Which starting number, under one million, produces the longest chain?
  385.  
  386.    NOTE: Once the chain starts the terms are allowed to go above one million.
  387.  
  388.    
  389.    Answer: 837799
  390.  
  391.  
  392. Problem 15
  393. ==========
  394.  
  395.  
  396.    Starting in the top left corner of a 2×2 grid, and only being able to move
  397.    to the right and down, there are exactly 6 routes to the bottom right
  398.    corner.
  399.  
  400.    How many such routes are there through a 20×20 grid?
  401.  
  402.    
  403.    p_015.gif
  404.    Answer: 137846528820
  405.  
  406.  
  407. Problem 16
  408. ==========
  409.  
  410.  
  411.    2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
  412.  
  413.    What is the sum of the digits of the number 2^1000?
  414.  
  415.    
  416.    Answer: 1366
  417.  
  418.  
  419. Problem 17
  420. ==========
  421.  
  422.  
  423.    If the numbers 1 to 5 are written out in words: one, two, three, four,
  424.    five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total.
  425.  
  426.    If all the numbers from 1 to 1000 (one thousand) inclusive were written
  427.    out in words, how many letters would be used?
  428.  
  429.    NOTE: Do not count spaces or hyphens. For example, 342 (three hundred and
  430.    forty-two) contains 23 letters and 115 (one hundred and fifteen) contains
  431.    20 letters. The use of "and" when writing out numbers is in compliance
  432.    with British usage.
  433.  
  434.    
  435.    Answer: 21124
  436.  
  437.  
  438. Problem 18
  439. ==========
  440.  
  441.  
  442.    By starting at the top of the triangle below and moving to adjacent
  443.    numbers on the row below, the maximum total from top to bottom is 23.
  444.  
  445.                                        3
  446.                                       7 4
  447.                                      2 4 6
  448.                                     8 5 9 3
  449.  
  450.    That is, 3 + 7 + 4 + 9 = 23.
  451.  
  452.    Find the maximum total from top to bottom of the triangle below:
  453.  
  454.                                        75
  455.                                      95 64
  456.                                     17 47 82
  457.                                   18 35 87 10
  458.                                  20 04 82 47 65
  459.                                19 01 23 75 03 34
  460.                               88 02 77 73 07 63 67
  461.                             99 65 04 28 06 16 70 92
  462.                            41 41 26 56 83 40 80 70 33
  463.                          41 48 72 33 47 32 37 16 94 29
  464.                         53 71 44 65 25 43 91 52 97 51 14
  465.                       70 11 33 28 77 73 17 78 39 68 17 57
  466.                      91 71 52 38 17 14 91 43 58 50 27 29 48
  467.                    63 66 04 68 89 53 67 30 73 16 69 87 40 31
  468.                   04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
  469.  
  470.    NOTE: As there are only 16384 routes, it is possible to solve this problem
  471.    by trying every route. However, [1]Problem 67, is the same challenge with
  472.    a triangle containing one-hundred rows; it cannot be solved by brute
  473.    force, and requires a clever method! ;o)
  474.  
  475.  
  476.    Visible links
  477.    1. problem=67
  478.    Answer: 1074
  479.  
  480.  
  481. Problem 19
  482. ==========
  483.  
  484.  
  485.    You are given the following information, but you may prefer to do some
  486.    research for yourself.
  487.  
  488.      • 1 Jan 1900 was a Monday.
  489.      • Thirty days has September,
  490.        April, June and November.
  491.        All the rest have thirty-one,
  492.        Saving February alone,
  493.        Which has twenty-eight, rain or shine.
  494.        And on leap years, twenty-nine.
  495.      • A leap year occurs on any year evenly divisible by 4, but not on a
  496.        century unless it is divisible by 400.
  497.  
  498.    How many Sundays fell on the first of the month during the twentieth
  499.    century (1 Jan 1901 to 31 Dec 2000)?
  500.  
  501.    
  502.    Answer: 171
  503.  
  504.  
  505. Problem 20
  506. ==========
  507.  
  508.  
  509.    n! means n × (n − 1) × ... × 3 × 2 × 1
  510.  
  511.    For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
  512.    and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 =
  513.    27.
  514.  
  515.    Find the sum of the digits in the number 100!
  516.  
  517.    
  518.    Answer: 648
  519.  
  520.  
  521. Problem 21
  522. ==========
  523.  
  524.  
  525.    Let d(n) be defined as the sum of proper divisors of n (numbers less than
  526.    n which divide evenly into n).
  527.    If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair
  528.    and each of a and b are called amicable numbers.
  529.  
  530.    For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22,
  531.    44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1,
  532.    2, 4, 71 and 142; so d(284) = 220.
  533.  
  534.    Evaluate the sum of all the amicable numbers under 10000.
  535.  
  536.    
  537.    Answer: 31626
  538.  
  539.  
  540. Problem 22
  541. ==========
  542.  
  543.  
  544.    Using [1]names.txt, a 46K text file containing over five-thousand first
  545.    names, begin by sorting it into alphabetical order. Then working out the
  546.    alphabetical value for each name, multiply this value by its alphabetical
  547.    position in the list to obtain a name score.
  548.  
  549.    For example, when the list is sorted into alphabetical order, COLIN, which
  550.    is worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So,
  551.    COLIN would obtain a score of 938 × 53 = 49714.
  552.  
  553.    What is the total of all the name scores in the file?
  554.  
  555.  
  556.    Visible links
  557.    1. names.txt
  558.    Answer: 871198282
  559.  
  560.  
  561. Problem 23
  562. ==========
  563.  
  564.  
  565.    A perfect number is a number for which the sum of its proper divisors is
  566.    exactly equal to the number. For example, the sum of the proper divisors
  567.    of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect
  568.    number.
  569.  
  570.    A number n is called deficient if the sum of its proper divisors is less
  571.    than n and it is called abundant if this sum exceeds n.
  572.  
  573.    As 12 is the smallest abundant number, 1 + 2 + 3 + 4 + 6 = 16, the
  574.    smallest number that can be written as the sum of two abundant numbers is
  575.    24. By mathematical analysis, it can be shown that all integers greater
  576.    than 28123 can be written as the sum of two abundant numbers. However,
  577.    this upper limit cannot be reduced any further by analysis even though it
  578.    is known that the greatest number that cannot be expressed as the sum of
  579.    two abundant numbers is less than this limit.
  580.  
  581.    Find the sum of all the positive integers which cannot be written as the
  582.    sum of two abundant numbers.
  583.  
  584.    
  585.    Answer: 4179871
  586.  
  587.  
  588. Problem 24
  589. ==========
  590.  
  591.  
  592.    A permutation is an ordered arrangement of objects. For example, 3124 is
  593.    one possible permutation of the digits 1, 2, 3 and 4. If all of the
  594.    permutations are listed numerically or alphabetically, we call it
  595.    lexicographic order. The lexicographic permutations of 0, 1 and 2 are:
  596.  
  597.                        012   021   102   120   201   210
  598.  
  599.    What is the millionth lexicographic permutation of the digits 0, 1, 2, 3,
  600.    4, 5, 6, 7, 8 and 9?
  601.  
  602.    
  603.    Answer: 7f155b45cb3f0a6e518d59ec348bff84
  604.  
  605.  
  606. Problem 25
  607. ==========
  608.  
  609.  
  610.    The Fibonacci sequence is defined by the recurrence relation:
  611.  
  612.      F[n] = F[n−1] + F[n−2], where F[1] = 1 and F[2] = 1.
  613.  
  614.    Hence the first 12 terms will be:
  615.  
  616.      F[1] = 1
  617.      F[2] = 1
  618.      F[3] = 2
  619.      F[4] = 3
  620.      F[5] = 5
  621.      F[6] = 8
  622.      F[7] = 13
  623.      F[8] = 21
  624.      F[9] = 34
  625.      F[10] = 55
  626.      F[11] = 89
  627.      F[12] = 144
  628.  
  629.    The 12th term, F[12], is the first term to contain three digits.
  630.  
  631.    What is the first term in the Fibonacci sequence to contain 1000 digits?
  632.  
  633.    
  634.    Answer: 4782
  635.  
  636.  
  637. Problem 26
  638. ==========
  639.  
  640.  
  641.    A unit fraction contains 1 in the numerator. The decimal representation of
  642.    the unit fractions with denominators 2 to 10 are given:
  643.  
  644.      1/2  =  0.5
  645.      1/3  =  0.(3)
  646.      1/4  =  0.25
  647.      1/5  =  0.2
  648.      1/6  =  0.1(6)
  649.      1/7  =  0.(142857)
  650.      1/8  =  0.125
  651.      1/9  =  0.(1)
  652.      1/10 =  0.1
  653.  
  654.    Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can
  655.    be seen that 1/7 has a 6-digit recurring cycle.
  656.  
  657.    Find the value of d < 1000 for which ^1/[d] contains the longest recurring
  658.    cycle in its decimal fraction part.
  659.  
  660.    
  661.    Answer: 983
  662.  
  663.  
  664. Problem 27
  665. ==========
  666.  
  667.  
  668.    Euler discovered the remarkable quadratic formula:
  669.  
  670.                                   n² + n + 41
  671.  
  672.    It turns out that the formula will produce 40 primes for the consecutive
  673.    values n = 0 to 39. However, when n = 40, 40^2 + 40 + 41 = 40(40 + 1) + 41
  674.    is divisible by 41, and certainly when n = 41, 41² + 41 + 41 is clearly
  675.    divisible by 41.
  676.  
  677.    The incredible formula  n² − 79n + 1601 was discovered, which produces 80
  678.    primes for the consecutive values n = 0 to 79. The product of the
  679.    coefficients, −79 and 1601, is −126479.
  680.  
  681.    Considering quadratics of the form:
  682.  
  683.      n² + an + b, where |a| < 1000 and |b| < 1000
  684.  
  685.      where |n| is the modulus/absolute value of n
  686.      e.g. |11| = 11 and |−4| = 4
  687.  
  688.    Find the product of the coefficients, a and b, for the quadratic
  689.    expression that produces the maximum number of primes for consecutive
  690.    values of n, starting with n = 0.
  691.  
  692.    
  693.    Answer: 69d9e3218fd7abb6ff453ea96505183d
  694.  
  695.  
  696. Problem 28
  697. ==========
  698.  
  699.  
  700.    Starting with the number 1 and moving to the right in a clockwise
  701.    direction a 5 by 5 spiral is formed as follows:
  702.  
  703.                                  21 22 23 24 25
  704.                                  20  7  8  9 10
  705.                                  19  6  1  2 11
  706.                                  18  5  4  3 12
  707.                                  17 16 15 14 13
  708.  
  709.    It can be verified that the sum of the numbers on the diagonals is 101.
  710.  
  711.    What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral
  712.    formed in the same way?
  713.  
  714.    
  715.    Answer: 0d53425bd7c5bf9919df3718c8e49fa6
  716.  
  717.  
  718. Problem 29
  719. ==========
  720.  
  721.  
  722.    Consider all integer combinations of a^b for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
  723.  
  724.      2^2=4, 2^3=8, 2^4=16, 2^5=32
  725.      3^2=9, 3^3=27, 3^4=81, 3^5=243
  726.      4^2=16, 4^3=64, 4^4=256, 4^5=1024
  727.      5^2=25, 5^3=125, 5^4=625, 5^5=3125
  728.  
  729.    If they are then placed in numerical order, with any repeats removed, we
  730.    get the following sequence of 15 distinct terms:
  731.  
  732.         4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
  733.  
  734.    How many distinct terms are in the sequence generated by a^b for 2 ≤ a ≤
  735.    100 and 2 ≤ b ≤ 100?
  736.  
  737.    
  738.    Answer: 9183
  739.  
  740.  
  741. Problem 30
  742. ==========
  743.  
  744.  
  745.    Surprisingly there are only three numbers that can be written as the sum
  746.    of fourth powers of their digits:
  747.  
  748.      1634 = 1^4 + 6^4 + 3^4 + 4^4
  749.      8208 = 8^4 + 2^4 + 0^4 + 8^4
  750.      9474 = 9^4 + 4^4 + 7^4 + 4^4
  751.  
  752.    As 1 = 1^4 is not a sum it is not included.
  753.  
  754.    The sum of these numbers is 1634 + 8208 + 9474 = 19316.
  755.  
  756.    Find the sum of all the numbers that can be written as the sum of fifth
  757.    powers of their digits.
  758.  
  759.    
  760.    Answer: 443839
  761.  
  762.  
  763. Problem 31
  764. ==========
  765.  
  766.  
  767.    In England the currency is made up of pound, £, and pence, p, and there
  768.    are eight coins in general circulation:
  769.  
  770.      1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
  771.  
  772.    It is possible to make £2 in the following way:
  773.  
  774.      1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
  775.  
  776.    How many different ways can £2 be made using any number of coins?
  777.  
  778.    
  779.    Answer: 73682
  780.  
  781.  
  782. Problem 32
  783. ==========
  784.  
  785.  
  786.    We shall say that an n-digit number is pandigital if it makes use of all
  787.    the digits 1 to n exactly once; for example, the 5-digit number, 15234, is
  788.    1 through 5 pandigital.
  789.  
  790.    The product 7254 is unusual, as the identity, 39 × 186 = 7254, containing
  791.    multiplicand, multiplier, and product is 1 through 9 pandigital.
  792.  
  793.    Find the sum of all products whose multiplicand/multiplier/product
  794.    identity can be written as a 1 through 9 pandigital.
  795.  
  796.    HINT: Some products can be obtained in more than one way so be sure to
  797.    only include it once in your sum.
  798.    
  799.    Answer: 45228
  800.  
  801.  
  802. Problem 33
  803. ==========
  804.  
  805.  
  806.    The fraction 49/98 is a curious fraction, as an inexperienced
  807.    mathematician in attempting to simplify it may incorrectly believe that
  808.    49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
  809.  
  810.    We shall consider fractions like, 30/50 = 3/5, to be trivial
  811.    examples.
  812.  
  813.    There are exactly four non-trivial examples of this type of fraction, less
  814.    than one in value, and containing two digits in the numerator and
  815.    denominator.
  816.  
  817.    If the product of these four fractions is given in its lowest common
  818.    terms, find the value of the denominator.
  819.  
  820.    
  821.    Answer: 100
  822.  
  823.  
  824. Problem 34
  825. ==========
  826.  
  827.  
  828.    145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
  829.  
  830.    Find the sum of all numbers which are equal to the sum of the factorial of
  831.    their digits.
  832.  
  833.    Note: as 1! = 1 and 2! = 2 are not sums they are not included.
  834.  
  835.    
  836.    Answer: 40730
  837.  
  838.  
  839. Problem 35
  840. ==========
  841.  
  842.  
  843.    The number, 197, is called a circular prime because all rotations of the
  844.    digits: 197, 971, and 719, are themselves prime.
  845.  
  846.    There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37,
  847.    71, 73, 79, and 97.
  848.  
  849.    How many circular primes are there below one million?
  850.  
  851.    
  852.    Answer: 55
  853.  
  854.  
  855. Problem 36
  856. ==========
  857.  
  858.  
  859.    The decimal number, 585 = 1001001001[2] (binary), is palindromic in both
  860.    bases.
  861.  
  862.    Find the sum of all numbers, less than one million, which are palindromic
  863.    in base 10 and base 2.
  864.  
  865.    (Please note that the palindromic number, in either base, may not include
  866.    leading zeros.)
  867.  
  868.    
  869.    Answer: 872187
  870.  
  871.  
  872. Problem 37
  873. ==========
  874.  
  875.  
  876.    The number 3797 has an interesting property. Being prime itself, it is
  877.    possible to continuously remove digits from left to right, and remain
  878.    prime at each stage: 3797, 797, 97, and 7. Similarly we can work from
  879.    right to left: 3797, 379, 37, and 3.
  880.  
  881.    Find the sum of the only eleven primes that are both truncatable from left
  882.    to right and right to left.
  883.  
  884.    NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.
  885.  
  886.    
  887.    Answer: 748317
  888.  
  889.  
  890. Problem 38
  891. ==========
  892.  
  893.  
  894.    Take the number 192 and multiply it by each of 1, 2, and 3:
  895.  
  896.      192 × 1 = 192
  897.      192 × 2 = 384
  898.      192 × 3 = 576
  899.  
  900.    By concatenating each product we get the 1 to 9 pandigital, 192384576. We
  901.    will call 192384576 the concatenated product of 192 and (1,2,3)
  902.  
  903.    The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4,
  904.    and 5, giving the pandigital, 918273645, which is the concatenated product
  905.    of 9 and (1,2,3,4,5).
  906.  
  907.    What is the largest 1 to 9 pandigital 9-digit number that can be formed as
  908.    the concatenated product of an integer with (1,2, ... , n) where n > 1?
  909.  
  910.    
  911.    Answer: f2a29ede8dc9fae7926dc7a4357ac25e
  912.  
  913.  
  914. Problem 39
  915. ==========
  916.  
  917.  
  918.    If p is the perimeter of a right angle triangle with integral length
  919.    sides, {a,b,c}, there are exactly three solutions for p = 120.
  920.  
  921.    {20,48,52}, {24,45,51}, {30,40,50}
  922.  
  923.    For which value of p ≤ 1000, is the number of solutions maximised?
  924.  
  925.    
  926.    Answer: 840
  927.  
  928.  
  929. Problem 40
  930. ==========
  931.  
  932.  
  933.    An irrational decimal fraction is created by concatenating the positive
  934.    integers:
  935.  
  936.                      0.123456789101112131415161718192021...
  937.  
  938.    It can be seen that the 12^th digit of the fractional part is 1.
  939.  
  940.    If d[n] represents the n^th digit of the fractional part, find the value
  941.    of the following expression.
  942.  
  943.       d[1] × d[10] × d[100] × d[1000] × d[10000] × d[100000] × d[1000000]
  944.  
  945.    
  946.    Answer: 210
  947.  
  948.  
  949. Problem 41
  950. ==========
  951.  
  952.  
  953.    We shall say that an n-digit number is pandigital if it makes use of all
  954.    the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital
  955.    and is also prime.
  956.  
  957.    What is the largest n-digit pandigital prime that exists?
  958.  
  959.    
  960.    Answer: 7652413
  961.  
  962.  
  963. Problem 42
  964. ==========
  965.  
  966.  
  967.    The n^th term of the sequence of triangle numbers is given by, t[n] =
  968.    ½n(n+1); so the first ten triangle numbers are:
  969.  
  970.                     1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
  971.  
  972.    By converting each letter in a word to a number corresponding to its
  973.    alphabetical position and adding these values we form a word value. For
  974.    example, the word value for SKY is 19 + 11 + 25 = 55 = t[10]. If the word
  975.    value is a triangle number then we shall call the word a triangle word.
  976.  
  977.    Using [1]words.txt, a 16K text file containing nearly two-thousand common
  978.    English words, how many are triangle words?
  979.  
  980.  
  981.    Visible links
  982.    1. words.txt
  983.    Answer: 162
  984.  
  985.  
  986. Problem 43
  987. ==========
  988.  
  989.  
  990.    The number, 1406357289, is a 0 to 9 pandigital number because it is made
  991.    up of each of the digits 0 to 9 in some order, but it also has a rather
  992.    interesting sub-string divisibility property.
  993.  
  994.    Let d[1] be the 1^st digit, d[2] be the 2^nd digit, and so on. In this
  995.    way, we note the following:
  996.  
  997.      • d[2]d[3]d[4]=406 is divisible by 2
  998.      • d[3]d[4]d[5]=063 is divisible by 3
  999.      • d[4]d[5]d[6]=635 is divisible by 5
  1000.      • d[5]d[6]d[7]=357 is divisible by 7
  1001.      • d[6]d[7]d[8]=572 is divisible by 11
  1002.      • d[7]d[8]d[9]=728 is divisible by 13
  1003.      • d[8]d[9]d[10]=289 is divisible by 17
  1004.  
  1005.    Find the sum of all 0 to 9 pandigital numbers with this property.
  1006.  
  1007.    
  1008.    Answer: 115253b7721af0fdff25cd391dfc70cf
  1009.  
  1010.  
  1011. Problem 44
  1012. ==========
  1013.  
  1014.  
  1015.    Pentagonal numbers are generated by the formula, P[n]=n(3n−1)/2. The first
  1016.    ten pentagonal numbers are:
  1017.  
  1018.                   1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...
  1019.  
  1020.    It can be seen that P[4] + P[7] = 22 + 70 = 92 = P[8]. However, their
  1021.    difference, 70 − 22 = 48, is not pentagonal.
  1022.  
  1023.    Find the pair of pentagonal numbers, P[j] and P[k], for which their sum
  1024.    and difference are pentagonal and D = |P[k] − P[j]| is minimised; what is
  1025.    the value of D?
  1026.  
  1027.    
  1028.    Answer: 5482660
  1029.  
  1030.  
  1031. Problem 45
  1032. ==========
  1033.  
  1034.  
  1035.    Triangle, pentagonal, and hexagonal numbers are generated by the following
  1036.    formulae:
  1037.  
  1038.    Triangle     T[n]=n(n+1)/2    1, 3, 6, 10, 15, ...
  1039.    Pentagonal   P[n]=n(3n−1)/2   1, 5, 12, 22, 35, ...
  1040.    Hexagonal    H[n]=n(2n−1)     1, 6, 15, 28, 45, ...
  1041.  
  1042.    It can be verified that T[285] = P[165] = H[143] = 40755.
  1043.  
  1044.    Find the next triangle number that is also pentagonal and hexagonal.
  1045.  
  1046.    
  1047.    Answer: 30dfe3e3b286add9d12e493ca7be63fc
  1048.  
  1049.  
  1050. Problem 46
  1051. ==========
  1052.  
  1053.  
  1054.    It was proposed by Christian Goldbach that every odd composite number can
  1055.    be written as the sum of a prime and twice a square.
  1056.  
  1057.    9 = 7 + 2×1^2
  1058.    15 = 7 + 2×2^2
  1059.    21 = 3 + 2×3^2
  1060.    25 = 7 + 2×3^2
  1061.    27 = 19 + 2×2^2
  1062.    33 = 31 + 2×1^2
  1063.  
  1064.    It turns out that the conjecture was false.
  1065.  
  1066.    What is the smallest odd composite that cannot be written as the sum of a
  1067.    prime and twice a square?
  1068.  
  1069.    
  1070.    Answer: 5777
  1071.  
  1072.  
  1073. Problem 47
  1074. ==========
  1075.  
  1076.  
  1077.    The first two consecutive numbers to have two distinct prime factors are:
  1078.  
  1079.    14 = 2 × 7
  1080.    15 = 3 × 5
  1081.  
  1082.    The first three consecutive numbers to have three distinct prime factors
  1083.    are:
  1084.  
  1085.    644 = 2² × 7 × 23
  1086.    645 = 3 × 5 × 43
  1087.    646 = 2 × 17 × 19.
  1088.  
  1089.    Find the first four consecutive integers to have four distinct prime
  1090.    factors. What is the first of these numbers?
  1091.  
  1092.    
  1093.    Answer: 134043
  1094.  
  1095.  
  1096. Problem 48
  1097. ==========
  1098.  
  1099.  
  1100.    The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317.
  1101.  
  1102.    Find the last ten digits of the series, 1^1 + 2^2 + 3^3 + ... + 1000^1000.
  1103.  
  1104.    
  1105.    Answer: 0829124724747ae1c65da8cae5263346
  1106.  
  1107.  
  1108. Problem 49
  1109. ==========
  1110.  
  1111.  
  1112.    The arithmetic sequence, 1487, 4817, 8147, in which each of the terms
  1113.    increases by 3330, is unusual in two ways: (i) each of the three terms are
  1114.    prime, and, (ii) each of the 4-digit numbers are permutations of one
  1115.    another.
  1116.  
  1117.    There are no arithmetic sequences made up of three 1-, 2-, or 3-digit
  1118.    primes, exhibiting this property, but there is one other 4-digit
  1119.    increasing sequence.
  1120.  
  1121.    What 12-digit number do you form by concatenating the three terms in this
  1122.    sequence?
  1123.  
  1124.    
  1125.    Answer: 0b99933d3e2a9addccbb663d46cbb592
  1126.  
  1127.  
  1128. Problem 50
  1129. ==========
  1130.  
  1131.  
  1132.    The prime 41, can be written as the sum of six consecutive primes:
  1133.  
  1134.                           41 = 2 + 3 + 5 + 7 + 11 + 13
  1135.  
  1136.    This is the longest sum of consecutive primes that adds to a prime below
  1137.    one-hundred.
  1138.  
  1139.    The longest sum of consecutive primes below one-thousand that adds to a
  1140.    prime, contains 21 terms, and is equal to 953.
  1141.  
  1142.    Which prime, below one-million, can be written as the sum of the most
  1143.    consecutive primes?
  1144.  
  1145.    
  1146.    Answer: 997651
  1147.  
  1148.  
  1149. Problem 51
  1150. ==========
  1151.  
  1152.  
  1153.    By replacing the 1^st digit of the 2-digit number *3, it turns out that
  1154.    six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all
  1155.    prime.
  1156.  
  1157.    By replacing the 3^rd and 4^th digits of 56**3 with the same digit, this
  1158.    5-digit number is the first example having seven primes among the ten
  1159.    generated numbers, yielding the family: 56003, 56113, 56333, 56443, 56663,
  1160.    56773, and 56993. Consequently 56003, being the first member of this
  1161.    family, is the smallest prime with this property.
  1162.  
  1163.    Find the smallest prime which, by replacing part of the number (not
  1164.    necessarily adjacent digits) with the same digit, is part of an eight
  1165.    prime value family.
  1166.  
  1167.    
  1168.    Answer: 121313
  1169.  
  1170.  
  1171. Problem 52
  1172. ==========
  1173.  
  1174.  
  1175.    It can be seen that the number, 125874, and its double, 251748, contain
  1176.    exactly the same digits, but in a different order.
  1177.  
  1178.    Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x,
  1179.    contain the same digits.
  1180.  
  1181.    
  1182.    Answer: 142857
  1183.  
  1184.  
  1185. Problem 53
  1186. ==========
  1187.  
  1188.  
  1189.    There are exactly ten ways of selecting three from five, 12345:
  1190.  
  1191.               123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
  1192.  
  1193.    In combinatorics, we use the notation, ^5C[3] = 10.
  1194.  
  1195.    In general,
  1196.  
  1197.       ^nC[r] =    n!    ,where r ≤ n, n! = n×(n−1)×...×3×2×1, and 0! = 1.
  1198.                r!(n−r)!
  1199.  
  1200.    It is not until n = 23, that a value exceeds one-million: ^23C[10] =
  1201.    1144066.
  1202.  
  1203.    How many, not necessarily distinct, values of  ^nC[r], for 1 ≤ n ≤ 100,
  1204.    are greater than one-million?
  1205.  
  1206.    
  1207.    Answer: 4075
  1208.  
  1209.  
  1210. Problem 54
  1211. ==========
  1212.  
  1213.  
  1214.    In the card game poker, a hand consists of five cards and are ranked, from
  1215.    lowest to highest, in the following way:
  1216.  
  1217.      • High Card: Highest value card.
  1218.      • One Pair: Two cards of the same value.
  1219.      • Two Pairs: Two different pairs.
  1220.      • Three of a Kind: Three cards of the same value.
  1221.      • Straight: All cards are consecutive values.
  1222.      • Flush: All cards of the same suit.
  1223.      • Full House: Three of a kind and a pair.
  1224.      • Four of a Kind: Four cards of the same value.
  1225.      • Straight Flush: All cards are consecutive values of same suit.
  1226.      • Royal Flush: Ten, Jack, Queen, King, Ace, in same suit.
  1227.  
  1228.    The cards are valued in the order:
  1229.    2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, Ace.
  1230.  
  1231.    If two players have the same ranked hands then the rank made up of the
  1232.    highest value wins; for example, a pair of eights beats a pair of fives
  1233.    (see example 1 below). But if two ranks tie, for example, both players
  1234.    have a pair of queens, then highest cards in each hand are compared (see
  1235.    example 4 below); if the highest cards tie then the next highest cards are
  1236.    compared, and so on.
  1237.  
  1238.    Consider the following five hands dealt to two players:
  1239.  
  1240.            Hand   Player 1            Player 2              Winner
  1241.            1      5H 5C 6S 7S KD      2C 3S 8S 8D TD        Player 2
  1242.                   Pair of Fives       Pair of Eights
  1243.            2      5D 8C 9S JS AC      2C 5C 7D 8S QH        Player 1
  1244.                   Highest card Ace    Highest card Queen
  1245.            3      2D 9C AS AH AC      3D 6D 7D TD QD        Player 2
  1246.                   Three Aces          Flush with Diamonds
  1247.                   4D 6S 9H QH QC      3D 6D 7H QD QS
  1248.            4      Pair of Queens      Pair of Queens        Player 1
  1249.                   Highest card Nine   Highest card Seven
  1250.                   2H 2D 4C 4D 4S      3C 3D 3S 9S 9D
  1251.            5      Full House          Full House            Player 1
  1252.                   With Three Fours    with Three Threes
  1253.  
  1254.    The file, [1]poker.txt, contains one-thousand random hands dealt to two
  1255.    players. Each line of the file contains ten cards (separated by a single
  1256.    space): the first five are Player 1's cards and the last five are Player
  1257.    2's cards. You can assume that all hands are valid (no invalid characters
  1258.    or repeated cards), each player's hand is in no specific order, and in
  1259.    each hand there is a clear winner.
  1260.  
  1261.    How many hands does Player 1 win?
  1262.  
  1263.  
  1264.    Visible links
  1265.    1. poker.txt
  1266.    Answer: 376
  1267.  
  1268.  
  1269. Problem 55
  1270. ==========
  1271.  
  1272.  
  1273.    If we take 47, reverse and add, 47 + 74 = 121, which is palindromic.
  1274.  
  1275.    Not all numbers produce palindromes so quickly. For example,
  1276.  
  1277.    349 + 943 = 1292,
  1278.    1292 + 2921 = 4213
  1279.    4213 + 3124 = 7337
  1280.  
  1281.    That is, 349 took three iterations to arrive at a palindrome.
  1282.  
  1283.    Although no one has proved it yet, it is thought that some numbers, like
  1284.    196, never produce a palindrome. A number that never forms a palindrome
  1285.    through the reverse and add process is called a Lychrel number. Due to the
  1286.    theoretical nature of these numbers, and for the purpose of this problem,
  1287.    we shall assume that a number is Lychrel until proven otherwise. In
  1288.    addition you are given that for every number below ten-thousand, it will
  1289.    either (i) become a palindrome in less than fifty iterations, or, (ii) no
  1290.    one, with all the computing power that exists, has managed so far to map
  1291.    it to a palindrome. In fact, 10677 is the first number to be shown to
  1292.    require over fifty iterations before producing a palindrome:
  1293.    4668731596684224866951378664 (53 iterations, 28-digits).
  1294.  
  1295.    Surprisingly, there are palindromic numbers that are themselves Lychrel
  1296.    numbers; the first example is 4994.
  1297.  
  1298.    How many Lychrel numbers are there below ten-thousand?
  1299.  
  1300.    NOTE: Wording was modified slightly on 24 April 2007 to emphasise the
  1301.    theoretical nature of Lychrel numbers.
  1302.  
  1303.    
  1304.    Answer: 249
  1305.  
  1306.  
  1307. Problem 56
  1308. ==========
  1309.  
  1310.  
  1311.    A googol (10^100) is a massive number: one followed by one-hundred zeros;
  1312.    100^100 is almost unimaginably large: one followed by two-hundred zeros.
  1313.    Despite their size, the sum of the digits in each number is only 1.
  1314.  
  1315.    Considering natural numbers of the form, a^b, where a, b < 100, what is
  1316.    the maximum digital sum?
  1317.  
  1318.    
  1319.    Answer: 972
  1320.  
  1321.  
  1322. Problem 57
  1323. ==========
  1324.  
  1325.  
  1326.    It is possible to show that the square root of two can be expressed as an
  1327.    infinite continued fraction.
  1328.  
  1329.               √ 2 = 1 + 1/(2 + 1/(2 + 1/(2 + ... ))) = 1.414213...
  1330.  
  1331.    By expanding this for the first four iterations, we get:
  1332.  
  1333.    1 + 1/2 = 3/2 = 1.5
  1334.    1 + 1/(2 + 1/2) = 7/5 = 1.4
  1335.    1 + 1/(2 + 1/(2 + 1/2)) = 17/12 = 1.41666...
  1336.    1 + 1/(2 + 1/(2 + 1/(2 + 1/2))) = 41/29 = 1.41379...
  1337.  
  1338.    The next three expansions are 99/70, 239/169, and 577/408, but the eighth
  1339.    expansion, 1393/985, is the first example where the number of digits in
  1340.    the numerator exceeds the number of digits in the denominator.
  1341.  
  1342.    In the first one-thousand expansions, how many fractions contain a
  1343.    numerator with more digits than denominator?
  1344.  
  1345.    
  1346.    Answer: 153
  1347.  
  1348.  
  1349. Problem 58
  1350. ==========
  1351.  
  1352.  
  1353.    Starting with 1 and spiralling anticlockwise in the following way, a
  1354.    square spiral with side length 7 is formed.
  1355.  
  1356.                               37 36 35 34 33 32 31
  1357.                               38 17 16 15 14 13 30
  1358.                               39 18  5  4  3 12 29
  1359.                               40 19  6  1  2 11 28
  1360.                               41 20  7  8  9 10 27
  1361.                               42 21 22 23 24 25 26
  1362.                               43 44 45 46 47 48 49
  1363.  
  1364.    It is interesting to note that the odd squares lie along the bottom right
  1365.    diagonal, but what is more interesting is that 8 out of the 13 numbers
  1366.    lying along both diagonals are prime; that is, a ratio of 8/13 ≈ 62%.
  1367.  
  1368.    If one complete new layer is wrapped around the spiral above, a square
  1369.    spiral with side length 9 will be formed. If this process is continued,
  1370.    what is the side length of the square spiral for which the ratio of primes
  1371.    along both diagonals first falls below 10%?
  1372.  
  1373.    
  1374.    Answer: 26241
  1375.  
  1376.  
  1377. Problem 59
  1378. ==========
  1379.  
  1380.  
  1381.    Each character on a computer is assigned a unique code and the preferred
  1382.    standard is ASCII (American Standard Code for Information Interchange).
  1383.    For example, uppercase A = 65, asterisk (*) = 42, and lowercase k = 107.
  1384.  
  1385.    A modern encryption method is to take a text file, convert the bytes to
  1386.    ASCII, then XOR each byte with a given value, taken from a secret key. The
  1387.    advantage with the XOR function is that using the same encryption key on
  1388.    the cipher text, restores the plain text; for example, 65 XOR 42 = 107,
  1389.    then 107 XOR 42 = 65.
  1390.  
  1391.    For unbreakable encryption, the key is the same length as the plain text
  1392.    message, and the key is made up of random bytes. The user would keep the
  1393.    encrypted message and the encryption key in different locations, and
  1394.    without both "halves", it is impossible to decrypt the message.
  1395.  
  1396.    Unfortunately, this method is impractical for most users, so the modified
  1397.    method is to use a password as a key. If the password is shorter than the
  1398.    message, which is likely, the key is repeated cyclically throughout the
  1399.    message. The balance for this method is using a sufficiently long password
  1400.    key for security, but short enough to be memorable.
  1401.  
  1402.    Your task has been made easy, as the encryption key consists of three
  1403.    lower case characters. Using [1]cipher1.txt, a file containing the
  1404.    encrypted ASCII codes, and the knowledge that the plain text must contain
  1405.    common English words, decrypt the message and find the sum of the ASCII
  1406.    values in the original text.
  1407.  
  1408.  
  1409.    Visible links
  1410.    1. cipher1.txt
  1411.    Answer: 107359
  1412.  
  1413.  
  1414. Problem 60
  1415. ==========
  1416.  
  1417.  
  1418.    The primes 3, 7, 109, and 673, are quite remarkable. By taking any two
  1419.    primes and concatenating them in any order the result will always be
  1420.    prime. For example, taking 7 and 109, both 7109 and 1097 are prime. The
  1421.    sum of these four primes, 792, represents the lowest sum for a set of four
  1422.    primes with this property.
  1423.  
  1424.    Find the lowest sum for a set of five primes for which any two primes
  1425.    concatenate to produce another prime.
  1426.  
  1427.    
  1428.    Answer: 26033
  1429.  
  1430.  
  1431. Problem 61
  1432. ==========
  1433.  
  1434.  
  1435.    Triangle, square, pentagonal, hexagonal, heptagonal, and octagonal numbers
  1436.    are all figurate (polygonal) numbers and are generated by the following
  1437.    formulae:
  1438.  
  1439.    Triangle     P[3,n]=n(n+1)/2    1, 3, 6, 10, 15, ...
  1440.    Square       P[4,n]=n^2         1, 4, 9, 16, 25, ...
  1441.    Pentagonal   P[5,n]=n(3n−1)/2   1, 5, 12, 22, 35, ...
  1442.    Hexagonal    P[6,n]=n(2n−1)     1, 6, 15, 28, 45, ...
  1443.    Heptagonal   P[7,n]=n(5n−3)/2   1, 7, 18, 34, 55, ...
  1444.    Octagonal    P[8,n]=n(3n−2)     1, 8, 21, 40, 65, ...
  1445.  
  1446.    The ordered set of three 4-digit numbers: 8128, 2882, 8281, has three
  1447.    interesting properties.
  1448.  
  1449.     1. The set is cyclic, in that the last two digits of each number is the
  1450.        first two digits of the next number (including the last number with
  1451.        the first).
  1452.     2. Each polygonal type: triangle (P[3,127]=8128), square (P[4,91]=8281),
  1453.        and pentagonal (P[5,44]=2882), is represented by a different number in
  1454.        the set.
  1455.     3. This is the only set of 4-digit numbers with this property.
  1456.  
  1457.    Find the sum of the only ordered set of six cyclic 4-digit numbers for
  1458.    which each polygonal type: triangle, square, pentagonal, hexagonal,
  1459.    heptagonal, and octagonal, is represented by a different number in the
  1460.    set.
  1461.  
  1462.    
  1463.    Answer: 28684
  1464.  
  1465.  
  1466. Problem 62
  1467. ==========
  1468.  
  1469.  
  1470.    The cube, 41063625 (345^3), can be permuted to produce two other cubes:
  1471.    56623104 (384^3) and 66430125 (405^3). In fact, 41063625 is the smallest
  1472.    cube which has exactly three permutations of its digits which are also
  1473.    cube.
  1474.  
  1475.    Find the smallest cube for which exactly five permutations of its digits
  1476.    are cube.
  1477.  
  1478.    
  1479.    Answer: 8f46b522b5401b8b6df99a7410eea44b
  1480.  
  1481.  
  1482. Problem 63
  1483. ==========
  1484.  
  1485.  
  1486.    The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the
  1487.    9-digit number, 134217728=8^9, is a ninth power.
  1488.  
  1489.    How many n-digit positive integers exist which are also an nth power?
  1490.  
  1491.    
  1492.    Answer: 49
  1493.  
  1494.  
  1495. Problem 64
  1496. ==========
  1497.  
  1498.  
  1499.    All square roots are periodic when written as continued fractions and can
  1500.    be written in the form:
  1501.  
  1502.    √N = a[0] +            1
  1503.                a[1] +         1
  1504.                       a[2] +     1
  1505.                              a[3] + ...
  1506.  
  1507.    For example, let us consider √23:
  1508.  
  1509.    √23 = 4 + √23 — 4 = 4 +    1    = 4 +       1
  1510.                               1           1 +  √23 – 3
  1511.                             √23—4                 7
  1512.  
  1513.    If we continue we would get the following expansion:
  1514.  
  1515.    √23 = 4 +          1
  1516.              1 +        1
  1517.                  3 +      1
  1518.                      1 +    1
  1519.                          8 + ...
  1520.  
  1521.    The process can be summarised as follows:
  1522.  
  1523.    a[0] = 4,     1    =   √23+4    = 1 +  √23—3
  1524.                √23—4        7               7
  1525.    a[1] = 1,     7    =  7(√23+3)  = 3 +  √23—3
  1526.                √23—3        14              2
  1527.    a[2] = 3,     2    =  2(√23+3)  = 1 +  √23—4
  1528.                √23—3        14              7
  1529.    a[3] = 1,     7    =  7(√23+4)  = 8 +  √23—4
  1530.                √23—4        7
  1531.    a[4] = 8,     1    =   √23+4    = 1 +  √23—3
  1532.                √23—4        7               7
  1533.    a[5] = 1,     7    =  7(√23+3)  = 3 +  √23—3
  1534.                √23—3        14              2
  1535.    a[6] = 3,     2    =  2(√23+3)  = 1 +  √23—4
  1536.                √23—3        14              7
  1537.    a[7] = 1,     7    =  7(√23+4)  = 8 +  √23—4
  1538.                √23—4        7
  1539.  
  1540.    It can be seen that the sequence is repeating. For conciseness, we use the
  1541.    notation √23 = [4;(1,3,1,8)], to indicate that the block (1,3,1,8) repeats
  1542.    indefinitely.
  1543.  
  1544.    The first ten continued fraction representations of (irrational) square
  1545.    roots are:
  1546.  
  1547.    √2=[1;(2)], period=1
  1548.    √3=[1;(1,2)], period=2
  1549.    √5=[2;(4)], period=1
  1550.    √6=[2;(2,4)], period=2
  1551.    √7=[2;(1,1,1,4)], period=4
  1552.    √8=[2;(1,4)], period=2
  1553.    √10=[3;(6)], period=1
  1554.    √11=[3;(3,6)], period=2
  1555.    √12= [3;(2,6)], period=2
  1556.    √13=[3;(1,1,1,1,6)], period=5
  1557.  
  1558.    Exactly four continued fractions, for N ≤ 13, have an odd period.
  1559.  
  1560.    How many continued fractions for N ≤ 10000 have an odd period?
  1561.  
  1562.    
  1563.    Answer: 1322
  1564.  
  1565.  
  1566. Problem 65
  1567. ==========
  1568.  
  1569.  
  1570.    The square root of 2 can be written as an infinite continued fraction.
  1571.  
  1572.    √2 = 1 +          1
  1573.             2 +        1
  1574.                 2 +      1
  1575.                     2 +    1
  1576.                         2 + ...
  1577.  
  1578.    The infinite continued fraction can be written, √2 = [1;(2)], (2)
  1579.    indicates that 2 repeats ad infinitum. In a similar way, √23 =
  1580.    [4;(1,3,1,8)].
  1581.  
  1582.    It turns out that the sequence of partial values of continued fractions
  1583.    for square roots provide the best rational approximations. Let us consider
  1584.    the convergents for √2.
  1585.  
  1586.    1 + 1 = 3/2
  1587.        2  
  1588.  
  1589.    1 +   1   = 7/5
  1590.        2 + 1
  1591.            2  
  1592.  
  1593.    1 +     1     = 17/12
  1594.        2 +   1    
  1595.            2 + 1  
  1596.                2  
  1597.  
  1598.    1 +       1       = 41/29
  1599.        2 +     1
  1600.            2 +   1    
  1601.                2 + 1  
  1602.                    2  
  1603.  
  1604.    Hence the sequence of the first ten convergents for √2 are:
  1605.  
  1606.    1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985, 3363/2378,
  1607.    ...
  1608.  
  1609.    What is most surprising is that the important mathematical constant,
  1610.    e = [2; 1,2,1, 1,4,1, 1,6,1 , ... , 1,2k,1, ...].
  1611.  
  1612.    The first ten terms in the sequence of convergents for e are:
  1613.  
  1614.    2, 3, 8/3, 11/4, 19/7, 87/32, 106/39, 193/71, 1264/465, 1457/536, ...
  1615.  
  1616.    The sum of digits in the numerator of the 10^th convergent is 1+4+5+7=17.
  1617.  
  1618.    Find the sum of digits in the numerator of the 100^th convergent of the
  1619.    continued fraction for e.
  1620.  
  1621.    
  1622.    Answer: 272
  1623.  
  1624.  
  1625. Problem 66
  1626. ==========
  1627.  
  1628.  
  1629.    Consider quadratic Diophantine equations of the form:
  1630.  
  1631.                                  x^2 – Dy^2 = 1
  1632.  
  1633.    For example, when D=13, the minimal solution in x is 649^2 – 13×180^2 = 1.
  1634.  
  1635.    It can be assumed that there are no solutions in positive integers when D
  1636.    is square.
  1637.  
  1638.    By finding minimal solutions in x for D = {2, 3, 5, 6, 7}, we obtain the
  1639.    following:
  1640.  
  1641.    3^2 – 2×2^2 = 1
  1642.    2^2 – 3×1^2 = 1
  1643.    9^2 – 5×4^2 = 1
  1644.    5^2 – 6×2^2 = 1
  1645.    8^2 – 7×3^2 = 1
  1646.  
  1647.    Hence, by considering minimal solutions in x for D ≤ 7, the largest x is
  1648.    obtained when D=5.
  1649.  
  1650.    Find the value of D ≤ 1000 in minimal solutions of x for which the largest
  1651.    value of x is obtained.
  1652.  
  1653.    
  1654.    Answer: 661
  1655.  
  1656.  
  1657. Problem 67
  1658. ==========
  1659.  
  1660.  
  1661.    By starting at the top of the triangle below and moving to adjacent
  1662.    numbers on the row below, the maximum total from top to bottom is 23.
  1663.  
  1664.                                        3
  1665.                                       7 4
  1666.                                      2 4 6
  1667.                                     8 5 9 3
  1668.  
  1669.    That is, 3 + 7 + 4 + 9 = 23.
  1670.  
  1671.    Find the maximum total from top to bottom in [1]triangle.txt, a 15K text
  1672.    file containing a triangle with one-hundred rows.
  1673.  
  1674.    NOTE: This is a much more difficult version of [2]Problem 18. It is not
  1675.    possible to try every route to solve this problem, as there are 2^99
  1676.    altogether! If you could check one trillion (10^12) routes every second it
  1677.    would take over twenty billion years to check them all. There is an
  1678.    efficient algorithm to solve it. ;o)
  1679.  
  1680.  
  1681.    Visible links
  1682.    1. triangle.txt
  1683.    2. problem=18
  1684.    Answer: 7273
  1685.  
  1686.  
  1687. Problem 68
  1688. ==========
  1689.  
  1690.  
  1691.    Consider the following "magic" 3-gon ring, filled with the numbers 1 to 6,
  1692.    and each line adding to nine.
  1693.  
  1694.    Working clockwise, and starting from the group of three with the
  1695.    numerically lowest external node (4,3,2 in this example), each solution
  1696.    can be described uniquely. For example, the above solution can be
  1697.    described by the set: 4,3,2; 6,2,1; 5,1,3.
  1698.  
  1699.    It is possible to complete the ring with four different totals: 9, 10, 11,
  1700.    and 12. There are eight solutions in total.
  1701.  
  1702.            Total          Solution Set
  1703.            9              4,2,3; 5,3,1; 6,1,2
  1704.            9              4,3,2; 6,2,1; 5,1,3
  1705.            10             2,3,5; 4,5,1; 6,1,3
  1706.            10             2,5,3; 6,3,1; 4,1,5
  1707.            11             1,4,6; 3,6,2; 5,2,4
  1708.            11             1,6,4; 5,4,2; 3,2,6
  1709.            12             1,5,6; 2,6,4; 3,4,5
  1710.            12             1,6,5; 3,5,4; 2,4,6
  1711.  
  1712.    By concatenating each group it is possible to form 9-digit strings; the
  1713.    maximum string for a 3-gon ring is 432621513.
  1714.  
  1715.    Using the numbers 1 to 10, and depending on arrangements, it is possible
  1716.    to form 16- and 17-digit strings. What is the maximum 16-digit string for
  1717.    a "magic" 5-gon ring?
  1718.  
  1719.    
  1720.    p_068_1.gif
  1721.    p_068_2.gif
  1722.    Answer: 26227442c6fed0292a528ac3790175be
  1723.  
  1724.  
  1725. Problem 69
  1726. ==========
  1727.  
  1728.  
  1729.    Euler's Totient function, φ(n) [sometimes called the phi function], is
  1730.    used to determine the number of numbers less than n which are relatively
  1731.    prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine
  1732.    and relatively prime to nine, φ(9)=6.
  1733.  
  1734.    ┌────┬──────────────────┬──────┬───────────┐
  1735.    │ n  │ Relatively Prime │ φ(n) │ n/φ(n)    │
  1736.    ├────┼──────────────────┼──────┼───────────┤
  1737.    │ 2  │ 1                │ 1    │ 2         │
  1738.    ├────┼──────────────────┼──────┼───────────┤
  1739.    │ 3  │ 1,2              │ 2    │ 1.5       │
  1740.    ├────┼──────────────────┼──────┼───────────┤
  1741.    │ 4  │ 1,3              │ 2    │ 2         │
  1742.    ├────┼──────────────────┼──────┼───────────┤
  1743.    │ 5  │ 1,2,3,4          │ 4    │ 1.25      │
  1744.    ├────┼──────────────────┼──────┼───────────┤
  1745.    │ 6  │ 1,5              │ 2    │ 3         │
  1746.    ├────┼──────────────────┼──────┼───────────┤
  1747.    │ 7  │ 1,2,3,4,5,6      │ 6    │ 1.1666... │
  1748.    ├────┼──────────────────┼──────┼───────────┤
  1749.    │ 8  │ 1,3,5,7          │ 4    │ 2         │
  1750.    ├────┼──────────────────┼──────┼───────────┤
  1751.    │ 9  │ 1,2,4,5,7,8      │ 6    │ 1.5       │
  1752.    ├────┼──────────────────┼──────┼───────────┤
  1753.    │ 10 │ 1,3,7,9          │ 4    │ 2.5       │
  1754.    └────┴──────────────────┴──────┴───────────┘
  1755.  
  1756.    It can be seen that n=6 produces a maximum n/φ(n) for n ≤ 10.
  1757.  
  1758.    Find the value of n ≤ 1,000,000 for which n/φ(n) is a maximum.
  1759.  
  1760.    
  1761.    Answer: 510510
  1762.  
  1763.  
  1764. Problem 70
  1765. ==========
  1766.  
  1767.  
  1768.    Euler's Totient function, φ(n) [sometimes called the phi function], is
  1769.    used to determine the number of positive numbers less than or equal to n
  1770.    which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are
  1771.    all less than nine and relatively prime to nine, φ(9)=6.
  1772.    The number 1 is considered to be relatively prime to every positive
  1773.    number, so φ(1)=1.
  1774.  
  1775.    Interestingly, φ(87109)=79180, and it can be seen that 87109 is a
  1776.    permutation of 79180.
  1777.  
  1778.    Find the value of n, 1 < n < 10^7, for which φ(n) is a permutation of n
  1779.    and the ratio n/φ(n) produces a minimum.
  1780.  
  1781.    
  1782.    Answer: 8319823
  1783.  
  1784.  
  1785. Problem 71
  1786. ==========
  1787.  
  1788.  
  1789.    Consider the fraction, n/d, where n and d are positive integers. If n<d
  1790.    and HCF(n,d)=1, it is called a reduced proper fraction.
  1791.  
  1792.    If we list the set of reduced proper fractions for d ≤ 8 in ascending
  1793.    order of size, we get:
  1794.  
  1795.    1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3,
  1796.                           5/7, 3/4, 4/5, 5/6, 6/7, 7/8
  1797.  
  1798.    It can be seen that 2/5 is the fraction immediately to the left of 3/7.
  1799.  
  1800.    By listing the set of reduced proper fractions for d ≤ 1,000,000 in
  1801.    ascending order of size, find the numerator of the fraction immediately to
  1802.    the left of 3/7.
  1803.  
  1804.    
  1805.    Answer: 428570
  1806.  
  1807.  
  1808. Problem 72
  1809. ==========
  1810.  
  1811.  
  1812.    Consider the fraction, n/d, where n and d are positive integers. If n<d
  1813.    and HCF(n,d)=1, it is called a reduced proper fraction.
  1814.  
  1815.    If we list the set of reduced proper fractions for d ≤ 8 in ascending
  1816.    order of size, we get:
  1817.  
  1818.    1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3,
  1819.                           5/7, 3/4, 4/5, 5/6, 6/7, 7/8
  1820.  
  1821.    It can be seen that there are 21 elements in this set.
  1822.  
  1823.    How many elements would be contained in the set of reduced proper
  1824.    fractions for d ≤ 1,000,000?
  1825.  
  1826.    
  1827.    Answer: 0384fb529dc651fe0f460acff3e9ac5d
  1828.  
  1829.  
  1830. Problem 73
  1831. ==========
  1832.  
  1833.  
  1834.    Consider the fraction, n/d, where n and d are positive integers. If n<d
  1835.    and HCF(n,d)=1, it is called a reduced proper fraction.
  1836.  
  1837.    If we list the set of reduced proper fractions for d ≤ 8 in ascending
  1838.    order of size, we get:
  1839.  
  1840.    1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3,
  1841.                           5/7, 3/4, 4/5, 5/6, 6/7, 7/8
  1842.  
  1843.    It can be seen that there are 3 fractions between 1/3 and 1/2.
  1844.  
  1845.    How many fractions lie between 1/3 and 1/2 in the sorted set of reduced
  1846.    proper fractions for d ≤ 12,000?
  1847.  
  1848.    
  1849.    Answer: 7295372
  1850.  
  1851.  
  1852. Problem 74
  1853. ==========
  1854.  
  1855.  
  1856.    The number 145 is well known for the property that the sum of the
  1857.    factorial of its digits is equal to 145:
  1858.  
  1859.    1! + 4! + 5! = 1 + 24 + 120 = 145
  1860.  
  1861.    Perhaps less well known is 169, in that it produces the longest chain of
  1862.    numbers that link back to 169; it turns out that there are only three such
  1863.    loops that exist:
  1864.  
  1865.    169 → 363601 → 1454 → 169
  1866.    871 → 45361 → 871
  1867.    872 → 45362 → 872
  1868.  
  1869.    It is not difficult to prove that EVERY starting number will eventually
  1870.    get stuck in a loop. For example,
  1871.  
  1872.    69 → 363600 → 1454 → 169 → 363601 (→ 1454)
  1873.    78 → 45360 → 871 → 45361 (→ 871)
  1874.    540 → 145 (→ 145)
  1875.  
  1876.    Starting with 69 produces a chain of five non-repeating terms, but the
  1877.    longest non-repeating chain with a starting number below one million is
  1878.    sixty terms.
  1879.  
  1880.    How many chains, with a starting number below one million, contain exactly
  1881.    sixty non-repeating terms?
  1882.  
  1883.    
  1884.    Answer: 402
  1885.  
  1886.  
  1887. Problem 75
  1888. ==========
  1889.  
  1890.  
  1891.    It turns out that 12 cm is the smallest length of wire that can be bent to
  1892.    form an integer sided right angle triangle in exactly one way, but there
  1893.    are many more examples.
  1894.  
  1895.    12 cm: (3,4,5)
  1896.    24 cm: (6,8,10)
  1897.    30 cm: (5,12,13)
  1898.    36 cm: (9,12,15)
  1899.    40 cm: (8,15,17)
  1900.    48 cm: (12,16,20)
  1901.  
  1902.    In contrast, some lengths of wire, like 20 cm, cannot be bent to form an
  1903.    integer sided right angle triangle, and other lengths allow more than one
  1904.    solution to be found; for example, using 120 cm it is possible to form
  1905.    exactly three different integer sided right angle triangles.
  1906.  
  1907.    120 cm: (30,40,50), (20,48,52), (24,45,51)
  1908.  
  1909.    Given that L is the length of the wire, for how many values of L ≤
  1910.    1,500,000 can exactly one integer sided right angle triangle be formed?
  1911.  
  1912.    
  1913.    Answer: 161667
  1914.  
  1915.  
  1916. Problem 76
  1917. ==========
  1918.  
  1919.  
  1920.    It is possible to write five as a sum in exactly six different ways:
  1921.  
  1922.    4 + 1
  1923.    3 + 2
  1924.    3 + 1 + 1
  1925.    2 + 2 + 1
  1926.    2 + 1 + 1 + 1
  1927.    1 + 1 + 1 + 1 + 1
  1928.  
  1929.    How many different ways can one hundred be written as a sum of at least
  1930.    two positive integers?
  1931.  
  1932.    
  1933.    Answer: 190569291
  1934.  
  1935.  
  1936. Problem 77
  1937. ==========
  1938.  
  1939.  
  1940.    It is possible to write ten as the sum of primes in exactly five different
  1941.    ways:
  1942.  
  1943.    7 + 3
  1944.    5 + 5
  1945.    5 + 3 + 2
  1946.    3 + 3 + 2 + 2
  1947.    2 + 2 + 2 + 2 + 2
  1948.  
  1949.    What is the first value which can be written as the sum of primes in over
  1950.    five thousand different ways?
  1951.  
  1952.    
  1953.    Answer: 71
  1954.  
  1955.  
  1956. Problem 78
  1957. ==========
  1958.  
  1959.  
  1960.    Let p(n) represent the number of different ways in which n coins can be
  1961.    separated into piles. For example, five coins can separated into piles in
  1962.    exactly seven different ways, so p(5)=7.
  1963.  
  1964.                                OOOOO
  1965.  
  1966.                                OOOO   O
  1967.  
  1968.                                OOO   OO
  1969.  
  1970.                                OOO   O   O
  1971.  
  1972.                                OO   OO   O
  1973.  
  1974.                                OO   O   O   O
  1975.  
  1976.                                O   O   O   O   O
  1977.  
  1978.    Find the least value of n for which p(n) is divisible by one million.
  1979.  
  1980.    
  1981.    Answer: 55374
  1982.  
  1983.  
  1984. Problem 79
  1985. ==========
  1986.  
  1987.  
  1988.    A common security method used for online banking is to ask the user for
  1989.    three random characters from a passcode. For example, if the passcode was
  1990.    531278, they may ask for the 2nd, 3rd, and 5th characters; the expected
  1991.    reply would be: 317.
  1992.  
  1993.    The text file, [1]keylog.txt, contains fifty successful login attempts.
  1994.  
  1995.    Given that the three characters are always asked for in order, analyse the
  1996.    file so as to determine the shortest possible secret passcode of unknown
  1997.    length.
  1998.  
  1999.  
  2000.    Visible links
  2001.    1. keylog.txt
  2002.    Answer: 73162890
  2003.  
  2004.  
  2005. Problem 80
  2006. ==========
  2007.  
  2008.  
  2009.    It is well known that if the square root of a natural number is not an
  2010.    integer, then it is irrational. The decimal expansion of such square roots
  2011.    is infinite without any repeating pattern at all.
  2012.  
  2013.    The square root of two is 1.41421356237309504880..., and the digital sum
  2014.    of the first one hundred decimal digits is 475.
  2015.  
  2016.    For the first one hundred natural numbers, find the total of the digital
  2017.    sums of the first one hundred decimal digits for all the irrational square
  2018.    roots.
  2019.  
  2020.    
  2021.    Answer: 40886
  2022.  
  2023.  
  2024. Problem 81
  2025. ==========
  2026.  
  2027.  
  2028.    In the 5 by 5 matrix below, the minimal path sum from the top left to the
  2029.    bottom right, by only moving to the right and down, is indicated in bold
  2030.    red and is equal to 2427.
  2031.  
  2032.                               131 673 234 103 18
  2033.                               201 96  342 965 150
  2034.                               630 803 746 422 111
  2035.                               537 699 497 121 956
  2036.                               805 732 524 37  331
  2037.  
  2038.    Find the minimal path sum, in [1]matrix.txt, a 31K text file containing a
  2039.    80 by 80 matrix, from the top left to the bottom right by only moving
  2040.    right and down.
  2041.  
  2042.  
  2043.    Visible links
  2044.    1. matrix.txt
  2045.    Answer: 427337
  2046.  
  2047.  
  2048. Problem 82
  2049. ==========
  2050.  
  2051.  
  2052.    NOTE: This problem is a more challenging version of [1]Problem 81.
  2053.  
  2054.    The minimal path sum in the 5 by 5 matrix below, by starting in any cell
  2055.    in the left column and finishing in any cell in the right column, and only
  2056.    moving up, down, and right, is indicated in red and bold; the sum is equal
  2057.    to 994.
  2058.  
  2059.                               131 673 234 103 18
  2060.                               201 96  342 965 150
  2061.                               630 803 746 422 111
  2062.                               537 699 497 121 956
  2063.                               805 732 524 37  331
  2064.  
  2065.    Find the minimal path sum, in [2]matrix.txt, a 31K text file containing a
  2066.    80 by 80 matrix, from the left column to the right column.
  2067.  
  2068.  
  2069.    Visible links
  2070.    1. problem=81
  2071.    2. matrix.txt
  2072.    Answer: 260324
  2073.  
  2074.  
  2075. Problem 83
  2076. ==========
  2077.  
  2078.  
  2079.    NOTE: This problem is a significantly more challenging version of
  2080.    [1]Problem 81.
  2081.  
  2082.    In the 5 by 5 matrix below, the minimal path sum from the top left to the
  2083.    bottom right, by moving left, right, up, and down, is indicated in bold
  2084.    red and is equal to 2297.
  2085.  
  2086.                               131 673 234 103 18
  2087.                               201 96  342 965 150
  2088.                               630 803 746 422 111
  2089.                               537 699 497 121 956
  2090.                               805 732 524 37  331
  2091.  
  2092.    Find the minimal path sum, in [2]matrix.txt, a 31K text file containing a
  2093.    80 by 80 matrix, from the top left to the bottom right by moving left,
  2094.    right, up, and down.
  2095.  
  2096.  
  2097.    Visible links
  2098.    1. problem=81
  2099.    2. matrix.txt
  2100.    Answer: 425185
  2101.  
  2102.  
  2103. Problem 84
  2104. ==========
  2105.  
  2106.  
  2107.    In the game, Monopoly, the standard board is set up in the following way:
  2108.  
  2109.                 GO   A1  CC1  A2  T1  R1  B1  CH1  B2   B3  JAIL
  2110.                 H2                                          C1
  2111.                 T2                                          U1
  2112.                 H1                                          C2
  2113.                 CH3                                         C3
  2114.                 R4                                          R2
  2115.                 G3                                          D1
  2116.                 CC3                                         CC2
  2117.                 G2                                          D2
  2118.                 G1                                          D3
  2119.                 G2J  F3  U2   F2  F1  R3  E3  E2   CH2  E1  FP
  2120.  
  2121.    A player starts on the GO square and adds the scores on two 6-sided dice
  2122.    to determine the number of squares they advance in a clockwise direction.
  2123.    Without any further rules we would expect to visit each square with equal
  2124.    probability: 2.5%. However, landing on G2J (Go To Jail), CC (community
  2125.    chest), and CH (chance) changes this distribution.
  2126.  
  2127.    In addition to G2J, and one card from each of CC and CH, that orders the
  2128.    player to go directly to jail, if a player rolls three consecutive
  2129.    doubles, they do not advance the result of their 3rd roll. Instead they
  2130.    proceed directly to jail.
  2131.  
  2132.    At the beginning of the game, the CC and CH cards are shuffled. When a
  2133.    player lands on CC or CH they take a card from the top of the respective
  2134.    pile and, after following the instructions, it is returned to the bottom
  2135.    of the pile. There are sixteen cards in each pile, but for the purpose of
  2136.    this problem we are only concerned with cards that order a movement; any
  2137.    instruction not concerned with movement will be ignored and the player
  2138.    will remain on the CC/CH square.
  2139.  
  2140.      • Community Chest (2/16 cards):
  2141.  
  2142.          1. Advance to GO
  2143.          2. Go to JAIL
  2144.  
  2145.      • Chance (10/16 cards):
  2146.  
  2147.          1. Advance to GO
  2148.          2. Go to JAIL
  2149.          3. Go to C1
  2150.          4. Go to E3
  2151.          5. Go to H2
  2152.          6. Go to R1
  2153.          7. Go to next R (railway company)
  2154.          8. Go to next R
  2155.          9. Go to next U (utility company)
  2156.         10. Go back 3 squares.
  2157.  
  2158.    The heart of this problem concerns the likelihood of visiting a particular
  2159.    square. That is, the probability of finishing at that square after a roll.
  2160.    For this reason it should be clear that, with the exception of G2J for
  2161.    which the probability of finishing on it is zero, the CH squares will have
  2162.    the lowest probabilities, as 5/8 request a movement to another square, and
  2163.    it is the final square that the player finishes at on each roll that we
  2164.    are interested in. We shall make no distinction between "Just Visiting"
  2165.    and being sent to JAIL, and we shall also ignore the rule about requiring
  2166.    a double to "get out of jail", assuming that they pay to get out on their
  2167.    next turn.
  2168.  
  2169.    By starting at GO and numbering the squares sequentially from 00 to 39 we
  2170.    can concatenate these two-digit numbers to produce strings that correspond
  2171.    with sets of squares.
  2172.  
  2173.    Statistically it can be shown that the three most popular squares, in
  2174.    order, are JAIL (6.24%) = Square 10, E3 (3.18%) = Square 24, and GO
  2175.    (3.09%) = Square 00. So these three most popular squares can be listed
  2176.    with the six-digit modal string: 102400.
  2177.  
  2178.    If, instead of using two 6-sided dice, two 4-sided dice are used, find the
  2179.    six-digit modal string.
  2180.  
  2181.    
  2182.    Answer: 101524
  2183.  
  2184.  
  2185. Problem 85
  2186. ==========
  2187.  
  2188.  
  2189.    By counting carefully it can be seen that a rectangular grid measuring 3
  2190.    by 2 contains eighteen rectangles:
  2191.  
  2192.    Although there exists no rectangular grid that contains exactly two
  2193.    million rectangles, find the area of the grid with the nearest solution.
  2194.  
  2195.    
  2196.    p_085.gif
  2197.    Answer: 2772
  2198.  
  2199.  
  2200. Problem 86
  2201. ==========
  2202.  
  2203.  
  2204.    A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3,
  2205.    and a fly, F, sits in the opposite corner. By travelling on the surfaces
  2206.    of the room the shortest "straight line" distance from S to F is 10 and
  2207.    the path is shown on the diagram.
  2208.  
  2209.    However, there are up to three "shortest" path candidates for any given
  2210.    cuboid and the shortest route doesn't always have integer length.
  2211.  
  2212.    By considering all cuboid rooms with integer dimensions, up to a maximum
  2213.    size of M by M by M, there are exactly 2060 cuboids for which the shortest
  2214.    route has integer length when M=100, and this is the least value of M for
  2215.    which the number of solutions first exceeds two thousand; the number of
  2216.    solutions is 1975 when M=99.
  2217.  
  2218.    Find the least value of M such that the number of solutions first exceeds
  2219.    one million.
  2220.  
  2221.    
  2222.    p_086.gif
  2223.    Answer: 1818
  2224.  
  2225.  
  2226. Problem 87
  2227. ==========
  2228.  
  2229.  
  2230.    The smallest number expressible as the sum of a prime square, prime cube,
  2231.    and prime fourth power is 28. In fact, there are exactly four numbers
  2232.    below fifty that can be expressed in such a way:
  2233.  
  2234.    28 = 2^2 + 2^3 + 2^4
  2235.    33 = 3^2 + 2^3 + 2^4
  2236.    49 = 5^2 + 2^3 + 2^4
  2237.    47 = 2^2 + 3^3 + 2^4
  2238.  
  2239.    How many numbers below fifty million can be expressed as the sum of a
  2240.    prime square, prime cube, and prime fourth power?
  2241.  
  2242.    
  2243.    Answer: 1097343
  2244.  
  2245.  
  2246. Problem 88
  2247. ==========
  2248.  
  2249.  
  2250.    A natural number, N, that can be written as the sum and product of a given
  2251.    set of at least two natural numbers, {a[1], a[2], ... , a[k]} is called a
  2252.    product-sum number: N = a[1] + a[2] + ... + a[k] = a[1] × a[2] × ... ×
  2253.    a[k].
  2254.  
  2255.    For example, 6 = 1 + 2 + 3 = 1 × 2 × 3.
  2256.  
  2257.    For a given set of size, k, we shall call the smallest N with this
  2258.    property a minimal product-sum number. The minimal product-sum numbers for
  2259.    sets of size, k = 2, 3, 4, 5, and 6 are as follows.
  2260.  
  2261.    k=2: 4 = 2 × 2 = 2 + 2
  2262.    k=3: 6 = 1 × 2 × 3 = 1 + 2 + 3
  2263.    k=4: 8 = 1 × 1 × 2 × 4 = 1 + 1 + 2 + 4
  2264.    k=5: 8 = 1 × 1 × 2 × 2 × 2 = 1 + 1 + 2 + 2 + 2
  2265.    k=6: 12 = 1 × 1 × 1 × 1 × 2 × 6 = 1 + 1 + 1 + 1 + 2 + 6
  2266.  
  2267.    Hence for 2≤k≤6, the sum of all the minimal product-sum numbers is
  2268.    4+6+8+12 = 30; note that 8 is only counted once in the sum.
  2269.  
  2270.    In fact, as the complete set of minimal product-sum numbers for 2≤k≤12 is
  2271.    {4, 6, 8, 12, 15, 16}, the sum is 61.
  2272.  
  2273.    What is the sum of all the minimal product-sum numbers for 2≤k≤12000?
  2274.  
  2275.    
  2276.    Answer: 7587457
  2277.  
  2278.  
  2279. Problem 89
  2280. ==========
  2281.  
  2282.  
  2283.    The rules for writing Roman numerals allow for many ways of writing each
  2284.    number (see [1]About Roman Numerals...). However, there is always a "best"
  2285.    way of writing a particular number.
  2286.  
  2287.    For example, the following represent all of the legitimate ways of writing
  2288.    the number sixteen:
  2289.  
  2290.    IIIIIIIIIIIIIIII
  2291.    VIIIIIIIIIII
  2292.    VVIIIIII
  2293.    XIIIIII
  2294.    VVVI
  2295.    XVI
  2296.  
  2297.    The last example being considered the most efficient, as it uses the least
  2298.    number of numerals.
  2299.  
  2300.    The 11K text file, [2]roman.txt, contains one thousand numbers written in
  2301.    valid, but not necessarily minimal, Roman numerals; that is, they are
  2302.    arranged in descending units and obey the subtractive pair rule (see
  2303.    [3]About Roman Numerals... for the definitive rules for this problem).
  2304.  
  2305.    Find the number of characters saved by writing each of these in their
  2306.    minimal form.
  2307.  
  2308.    Note: You can assume that all the Roman numerals in the file contain no
  2309.    more than four consecutive identical units.
  2310.  
  2311.  
  2312.    Visible links
  2313.    1. about=roman_numerals
  2314.    2. roman.txt
  2315.    3. about=roman_numerals
  2316.    Answer: 743
  2317.  
  2318.  
  2319. Problem 90
  2320. ==========
  2321.  
  2322.  
  2323.    Each of the six faces on a cube has a different digit (0 to 9) written on
  2324.    it; the same is done to a second cube. By placing the two cubes
  2325.    side-by-side in different positions we can form a variety of 2-digit
  2326.    numbers.
  2327.  
  2328.    For example, the square number 64 could be formed:
  2329.  
  2330.    In fact, by carefully choosing the digits on both cubes it is possible to
  2331.    display all of the square numbers below one-hundred: 01, 04, 09, 16, 25,
  2332.    36, 49, 64, and 81.
  2333.  
  2334.    For example, one way this can be achieved is by placing {0, 5, 6, 7, 8, 9}
  2335.    on one cube and {1, 2, 3, 4, 8, 9} on the other cube.
  2336.  
  2337.    However, for this problem we shall allow the 6 or 9 to be turned
  2338.    upside-down so that an arrangement like {0, 5, 6, 7, 8, 9} and {1, 2, 3,
  2339.    4, 6, 7} allows for all nine square numbers to be displayed; otherwise it
  2340.    would be impossible to obtain 09.
  2341.  
  2342.    In determining a distinct arrangement we are interested in the digits on
  2343.    each cube, not the order.
  2344.  
  2345.    {1, 2, 3, 4, 5, 6} is equivalent to {3, 6, 4, 1, 2, 5}
  2346.    {1, 2, 3, 4, 5, 6} is distinct from {1, 2, 3, 4, 5, 9}
  2347.  
  2348.    But because we are allowing 6 and 9 to be reversed, the two distinct sets
  2349.    in the last example both represent the extended set {1, 2, 3, 4, 5, 6, 9}
  2350.    for the purpose of forming 2-digit numbers.
  2351.  
  2352.    How many distinct arrangements of the two cubes allow for all of the
  2353.    square numbers to be displayed?
  2354.  
  2355.    
  2356.    p_090.gif
  2357.    Answer: 1217
  2358.  
  2359.  
  2360. Problem 91
  2361. ==========
  2362.  
  2363.  
  2364.    The points P (x[1], y[1]) and Q (x[2], y[2]) are plotted at integer
  2365.    co-ordinates and are joined to the origin, O(0,0), to form ΔOPQ.
  2366.  
  2367.    There are exactly fourteen triangles containing a right angle that can be
  2368.    formed when each co-ordinate lies between 0 and 2 inclusive; that is,
  2369.    0 ≤ x[1], y[1], x[2], y[2] ≤ 2.
  2370.  
  2371.    Given that 0 ≤ x[1], y[1], x[2], y[2] ≤ 50, how many right triangles can
  2372.    be formed?
  2373.  
  2374.    
  2375.    p_091_1.gif
  2376.    p_091_2.gif
  2377.    Answer: 14234
  2378.  
  2379.  
  2380. Problem 92
  2381. ==========
  2382.  
  2383.  
  2384.    A number chain is created by continuously adding the square of the digits
  2385.    in a number to form a new number until it has been seen before.
  2386.  
  2387.    For example,
  2388.  
  2389.    44 → 32 → 13 → 10 → 1 → 1
  2390.    85 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89
  2391.  
  2392.    Therefore any chain that arrives at 1 or 89 will become stuck in an
  2393.    endless loop. What is most amazing is that EVERY starting number will
  2394.    eventually arrive at 1 or 89.
  2395.  
  2396.    How many starting numbers below ten million will arrive at 89?
  2397.  
  2398.    
  2399.    Answer: 8581146
  2400.  
  2401.  
  2402. Problem 93
  2403. ==========
  2404.  
  2405.  
  2406.    By using each of the digits from the set, {1, 2, 3, 4}, exactly once, and
  2407.    making use of the four arithmetic operations (+, −, *, /) and
  2408.    brackets/parentheses, it is possible to form different positive integer
  2409.    targets.
  2410.  
  2411.    For example,
  2412.  
  2413.    8 = (4 * (1 + 3)) / 2
  2414.    14 = 4 * (3 + 1 / 2)
  2415.    19 = 4 * (2 + 3) − 1
  2416.    36 = 3 * 4 * (2 + 1)
  2417.  
  2418.    Note that concatenations of the digits, like 12 + 34, are not allowed.
  2419.  
  2420.    Using the set, {1, 2, 3, 4}, it is possible to obtain thirty-one different
  2421.    target numbers of which 36 is the maximum, and each of the numbers 1 to 28
  2422.    can be obtained before encountering the first non-expressible number.
  2423.  
  2424.    Find the set of four distinct digits, a < b < c < d, for which the longest
  2425.    set of consecutive positive integers, 1 to n, can be obtained, giving your
  2426.    answer as a string: abcd.
  2427.  
  2428.    
  2429.    Answer: 1258
  2430.  
  2431.  
  2432. Problem 94
  2433. ==========
  2434.  
  2435.  
  2436.    It is easily proved that no equilateral triangle exists with integral
  2437.    length sides and integral area. However, the almost equilateral triangle
  2438.    5-5-6 has an area of 12 square units.
  2439.  
  2440.    We shall define an almost equilateral triangle to be a triangle for which
  2441.    two sides are equal and the third differs by no more than one unit.
  2442.  
  2443.    Find the sum of the perimeters of all almost equilateral triangles with
  2444.    integral side lengths and area and whose perimeters do not exceed one
  2445.    billion (1,000,000,000).
  2446.  
  2447.    
  2448.    Answer: 3218c6bb59f2539ec39ad4bf37c10913
  2449.  
  2450.  
  2451. Problem 95
  2452. ==========
  2453.  
  2454.  
  2455.    The proper divisors of a number are all the divisors excluding the number
  2456.    itself. For example, the proper divisors of 28 are 1, 2, 4, 7, and 14. As
  2457.    the sum of these divisors is equal to 28, we call it a perfect number.
  2458.  
  2459.    Interestingly the sum of the proper divisors of 220 is 284 and the sum of
  2460.    the proper divisors of 284 is 220, forming a chain of two numbers. For
  2461.    this reason, 220 and 284 are called an amicable pair.
  2462.  
  2463.    Perhaps less well known are longer chains. For example, starting with
  2464.    12496, we form a chain of five numbers:
  2465.  
  2466.              12496 → 14288 → 15472 → 14536 → 14264 (→ 12496 → ...)
  2467.  
  2468.    Since this chain returns to its starting point, it is called an amicable
  2469.    chain.
  2470.  
  2471.    Find the smallest member of the longest amicable chain with no element
  2472.    exceeding one million.
  2473.  
  2474.    
  2475.    Answer: 14316
  2476.  
  2477.  
  2478. Problem 96
  2479. ==========
  2480.  
  2481.  
  2482.    Su Doku (Japanese meaning number place) is the name given to a popular
  2483.    puzzle concept. Its origin is unclear, but credit must be attributed to
  2484.    Leonhard Euler who invented a similar, and much more difficult, puzzle
  2485.    idea called Latin Squares. The objective of Su Doku puzzles, however, is
  2486.    to replace the blanks (or zeros) in a 9 by 9 grid in such that each row,
  2487.    column, and 3 by 3 box contains each of the digits 1 to 9. Below is an
  2488.    example of a typical starting puzzle grid and its solution grid.
  2489.  
  2490.           ┌───────┬───────┬───────┐         ┌───────┬───────┬───────┐
  2491.           │ 0 0 3 │ 0 2 0 │ 6 0 0 │         │ 4 8 3 │ 9 2 1 │ 6 5 7 │
  2492.           │ 9 0 0 │ 3 0 5 │ 0 0 1 │         │ 9 6 7 │ 3 4 5 │ 8 2 1 │
  2493.           │ 0 0 1 │ 8 0 6 │ 4 0 0 │         │ 2 5 1 │ 8 7 6 │ 4 9 3 │
  2494.           ├───────┼───────┼───────┤         ├───────┼───────┼───────┤
  2495.           │ 0 0 8 │ 1 0 2 │ 9 0 0 │         │ 5 4 8 │ 1 3 2 │ 9 7 6 │
  2496.           │ 7 0 0 │ 0 0 0 │ 0 0 8 │         │ 7 2 9 │ 5 6 4 │ 1 3 8 │
  2497.           │ 0 0 6 │ 7 0 8 │ 2 0 0 │         │ 1 3 6 │ 7 9 8 │ 2 4 5 │
  2498.           ├───────┼───────┼───────┤         ├───────┼───────┼───────┤
  2499.           │ 0 0 2 │ 6 0 9 │ 5 0 0 │         │ 3 7 2 │ 6 8 9 │ 5 1 4 │
  2500.           │ 8 0 0 │ 2 0 3 │ 0 0 9 │         │ 8 1 4 │ 2 5 3 │ 7 6 9 │
  2501.           │ 0 0 5 │ 0 1 0 │ 3 0 0 │         │ 6 9 5 │ 4 1 7 │ 3 8 2 │
  2502.           └───────┴───────┴───────┘         └───────┴───────┴───────┘
  2503.  
  2504.    A well constructed Su Doku puzzle has a unique solution and can be solved
  2505.    by logic, although it may be necessary to employ "guess and test" methods
  2506.    in order to eliminate options (there is much contested opinion over this).
  2507.    The complexity of the search determines the difficulty of the puzzle; the
  2508.    example above is considered easy because it can be solved by straight
  2509.    forward direct deduction.
  2510.  
  2511.    The 6K text file, [1]sudoku.txt, contains fifty different Su Doku puzzles
  2512.    ranging in difficulty, but all with unique solutions (the first puzzle in
  2513.    the file is the example above).
  2514.  
  2515.    By solving all fifty puzzles find the sum of the 3-digit numbers found in
  2516.    the top left corner of each solution grid; for example, 483 is the 3-digit
  2517.    number found in the top left corner of the solution grid above.
  2518.  
  2519.  
  2520.    Visible links
  2521.    1. sudoku.txt
  2522.    Answer: 24702
  2523.  
  2524.  
  2525. Problem 97
  2526. ==========
  2527.  
  2528.  
  2529.    The first known prime found to exceed one million digits was discovered in
  2530.    1999, and is a Mersenne prime of the form 2^6972593−1; it contains exactly
  2531.    2,098,960 digits. Subsequently other Mersenne primes, of the form 2^p−1,
  2532.    have been found which contain more digits.
  2533.  
  2534.    However, in 2004 there was found a massive non-Mersenne prime which
  2535.    contains 2,357,207 digits: 28433×2^7830457+1.
  2536.  
  2537.    Find the last ten digits of this prime number.
  2538.  
  2539.    
  2540.    Answer: 68c8c919526039022b923a72d5cc12b1
  2541.  
  2542.  
  2543. Problem 98
  2544. ==========
  2545.  
  2546.  
  2547.    By replacing each of the letters in the word CARE with 1, 2, 9, and 6
  2548.    respectively, we form a square number: 1296 = 36^2. What is remarkable is
  2549.    that, by using the same digital substitutions, the anagram, RACE, also
  2550.    forms a square number: 9216 = 96^2. We shall call CARE (and RACE) a square
  2551.    anagram word pair and specify further that leading zeroes are not
  2552.    permitted, neither may a different letter have the same digital value as
  2553.    another letter.
  2554.  
  2555.    Using [1]words.txt, a 16K text file containing nearly two-thousand common
  2556.    English words, find all the square anagram word pairs (a palindromic word
  2557.    is NOT considered to be an anagram of itself).
  2558.  
  2559.    What is the largest square number formed by any member of such a pair?
  2560.  
  2561.    NOTE: All anagrams formed must be contained in the given text file.
  2562.  
  2563.  
  2564.    Visible links
  2565.    1. words.txt
  2566.    Answer: 18769
  2567.  
  2568.  
  2569. Problem 99
  2570. ==========
  2571.  
  2572.  
  2573.    Comparing two numbers written in index form like 2^11 and 3^7 is not
  2574.    difficult, as any calculator would confirm that 2^11 = 2048 < 3^7 = 2187.
  2575.  
  2576.    However, confirming that 632382^518061 > 519432^525806 would be much more
  2577.    difficult, as both numbers contain over three million digits.
  2578.  
  2579.    Using [1]base_exp.txt, a 22K text file containing one thousand lines with
  2580.    a base/exponent pair on each line, determine which line number has the
  2581.    greatest numerical value.
  2582.  
  2583.    NOTE: The first two lines in the file represent the numbers in the example
  2584.    given above.
  2585.  
  2586.  
  2587.    Visible links
  2588.    1. base_exp.txt
  2589.    Answer: 709
  2590.  
  2591.  
  2592. Problem 100
  2593. ===========
  2594.  
  2595.  
  2596.    If a box contains twenty-one coloured discs, composed of fifteen blue
  2597.    discs and six red discs, and two discs were taken at random, it can be
  2598.    seen that the probability of taking two blue discs, P(BB) =
  2599.    (15/21)×(14/20) = 1/2.
  2600.  
  2601.    The next such arrangement, for which there is exactly 50% chance of taking
  2602.    two blue discs at random, is a box containing eighty-five blue discs and
  2603.    thirty-five red discs.
  2604.  
  2605.    By finding the first arrangement to contain over 10^12 = 1,000,000,000,000
  2606.    discs in total, determine the number of blue discs that the box would
  2607.    contain.
  2608.  
  2609.    
  2610.    Answer: 21156e3acc4ca35b7a318c541a0648d5
  2611.  
  2612.  
  2613. Problem 101
  2614. ===========
  2615.  
  2616.  
  2617.    If we are presented with the first k terms of a sequence it is impossible
  2618.    to say with certainty the value of the next term, as there are infinitely
  2619.    many polynomial functions that can model the sequence.
  2620.  
  2621.    As an example, let us consider the sequence of cube numbers. This is
  2622.    defined by the generating function,
  2623.    u[n] = n^3: 1, 8, 27, 64, 125, 216, ...
  2624.  
  2625.    Suppose we were only given the first two terms of this sequence. Working
  2626.    on the principle that "simple is best" we should assume a linear
  2627.    relationship and predict the next term to be 15 (common difference 7).
  2628.    Even if we were presented with the first three terms, by the same
  2629.    principle of simplicity, a quadratic relationship should be assumed.
  2630.  
  2631.    We shall define OP(k, n) to be the n^th term of the optimum polynomial
  2632.    generating function for the first k terms of a sequence. It should be
  2633.    clear that OP(k, n) will accurately generate the terms of the sequence for
  2634.    n ≤ k, and potentially the first incorrect term (FIT) will be OP(k, k+1);
  2635.    in which case we shall call it a bad OP (BOP).
  2636.  
  2637.    As a basis, if we were only given the first term of sequence, it would be
  2638.    most sensible to assume constancy; that is, for n ≥ 2, OP(1, n) = u[1].
  2639.  
  2640.    Hence we obtain the following OPs for the cubic sequence:
  2641.  
  2642.    OP(1, n) = 1               1, 1, 1, 1, ...
  2643.    OP(2, n) = 7n−6            1, 8, 15, ...
  2644.    OP(3, n) = 6n^2−11n+6      1, 8, 27, 58, ...
  2645.    OP(4, n) = n^3             1, 8, 27, 64, 125, ...
  2646.  
  2647.    Clearly no BOPs exist for k ≥ 4.
  2648.  
  2649.    By considering the sum of FITs generated by the BOPs (indicated in red
  2650.    above), we obtain 1 + 15 + 58 = 74.
  2651.  
  2652.    Consider the following tenth degree polynomial generating function:
  2653.  
  2654.       u[n] = 1 − n + n^2 − n^3 + n^4 − n^5 + n^6 − n^7 + n^8 − n^9 + n^10
  2655.  
  2656.    Find the sum of FITs for the BOPs.
  2657.  
  2658.    
  2659.    Answer: d382b0cc25e82446da83d3a792e1cd27
  2660.  
  2661.  
  2662. Problem 102
  2663. ===========
  2664.  
  2665.  
  2666.    Three distinct points are plotted at random on a Cartesian plane, for
  2667.    which -1000 ≤ x, y ≤ 1000, such that a triangle is formed.
  2668.  
  2669.    Consider the following two triangles:
  2670.  
  2671.                      A(-340,495), B(-153,-910), C(835,-947)
  2672.  
  2673.                      X(-175,41), Y(-421,-714), Z(574,-645)
  2674.  
  2675.    It can be verified that triangle ABC contains the origin, whereas triangle
  2676.    XYZ does not.
  2677.  
  2678.    Using [1]triangles.txt, a 27K text file containing the co-ordinates of one
  2679.    thousand "random" triangles, find the number of triangles for which the
  2680.    interior contains the origin.
  2681.  
  2682.    NOTE: The first two examples in the file represent the triangles in the
  2683.    example given above.
  2684.  
  2685.  
  2686.    Visible links
  2687.    1. triangles.txt
  2688.    Answer: 228
  2689.  
  2690.  
  2691. Problem 103
  2692. ===========
  2693.  
  2694.  
  2695.    Let S(A) represent the sum of elements in set A of size n. We shall call
  2696.    it a special sum set if for any two non-empty disjoint subsets, B and C,
  2697.    the following properties are true:
  2698.  
  2699.    i. S(B) ≠ S(C); that is, sums of subsets cannot be equal.
  2700.    ii. If B contains more elements than C then S(B) > S(C).
  2701.  
  2702.    If S(A) is minimised for a given n, we shall call it an optimum special
  2703.    sum set. The first five optimum special sum sets are given below.
  2704.  
  2705.    n = 1: {1}
  2706.    n = 2: {1, 2}
  2707.    n = 3: {2, 3, 4}
  2708.    n = 4: {3, 5, 6, 7}
  2709.    n = 5: {6, 9, 11, 12, 13}
  2710.  
  2711.    It seems that for a given optimum set, A = {a[1], a[2], ... , a[n]}, the
  2712.    next optimum set is of the form B = {b, a[1]+b, a[2]+b, ... ,a[n]+b},
  2713.    where b is the "middle" element on the previous row.
  2714.  
  2715.    By applying this "rule" we would expect the optimum set for n = 6 to be A
  2716.    = {11, 17, 20, 22, 23, 24}, with S(A) = 117. However, this is not the
  2717.    optimum set, as we have merely applied an algorithm to provide a near
  2718.    optimum set. The optimum set for n = 6 is A = {11, 18, 19, 20, 22, 25},
  2719.    with S(A) = 115 and corresponding set string: 111819202225.
  2720.  
  2721.    Given that A is an optimum special sum set for n = 7, find its set string.
  2722.  
  2723.    NOTE: This problem is related to [1]Problem 105 and [2]Problem 106.
  2724.  
  2725.  
  2726.    Visible links
  2727.    1. problem=105
  2728.    2. problem=106
  2729.    Answer: af8c238336c2a79bb81a24b3fef3330d
  2730.  
  2731.  
  2732. Problem 104
  2733. ===========
  2734.  
  2735.  
  2736.    The Fibonacci sequence is defined by the recurrence relation:
  2737.  
  2738.      F[n] = F[n−1] + F[n−2], where F[1] = 1 and F[2] = 1.
  2739.  
  2740.    It turns out that F[541], which contains 113 digits, is the first
  2741.    Fibonacci number for which the last nine digits are 1-9 pandigital
  2742.    (contain all the digits 1 to 9, but not necessarily in order). And
  2743.    F[2749], which contains 575 digits, is the first Fibonacci number for
  2744.    which the first nine digits are 1-9 pandigital.
  2745.  
  2746.    Given that F[k] is the first Fibonacci number for which the first nine
  2747.    digits AND the last nine digits are 1-9 pandigital, find k.
  2748.  
  2749.    
  2750.    Answer: 329468
  2751.  
  2752.  
  2753. Problem 105
  2754. ===========
  2755.  
  2756.  
  2757.    Let S(A) represent the sum of elements in set A of size n. We shall call
  2758.    it a special sum set if for any two non-empty disjoint subsets, B and C,
  2759.    the following properties are true:
  2760.  
  2761.    i. S(B) ≠ S(C); that is, sums of subsets cannot be equal.
  2762.    ii. If B contains more elements than C then S(B) > S(C).
  2763.  
  2764.    For example, {81, 88, 75, 42, 87, 84, 86, 65} is not a special sum set
  2765.    because 65 + 87 + 88 = 75 + 81 + 84, whereas {157, 150, 164, 119, 79, 159,
  2766.    161, 139, 158} satisfies both rules for all possible subset pair
  2767.    combinations and S(A) = 1286.
  2768.  
  2769.    Using [1]sets.txt (right click and "Save Link/Target As..."), a 4K text
  2770.    file with one-hundred sets containing seven to twelve elements (the two
  2771.    examples given above are the first two sets in the file), identify all the
  2772.    special sum sets, A[1], A[2], ..., A[k], and find the value of S(A[1]) +
  2773.    S(A[2]) + ... + S(A[k]).
  2774.  
  2775.    NOTE: This problem is related to [2]Problem 103 and [3]Problem 106.
  2776.  
  2777.  
  2778.    Visible links
  2779.    1. sets.txt
  2780.    2. problem=103
  2781.    3. problem=106
  2782.    Answer: 73702
  2783.  
  2784.  
  2785. Problem 106
  2786. ===========
  2787.  
  2788.  
  2789.    Let S(A) represent the sum of elements in set A of size n. We shall call
  2790.    it a special sum set if for any two non-empty disjoint subsets, B and C,
  2791.    the following properties are true:
  2792.  
  2793.    i. S(B) ≠ S(C); that is, sums of subsets cannot be equal.
  2794.    ii. If B contains more elements than C then S(B) > S(C).
  2795.  
  2796.    For this problem we shall assume that a given set contains n strictly
  2797.    increasing elements and it already satisfies the second rule.
  2798.  
  2799.    Surprisingly, out of the 25 possible subset pairs that can be obtained
  2800.    from a set for which n = 4, only 1 of these pairs need to be tested for
  2801.    equality (first rule). Similarly, when n = 7, only 70 out of the 966
  2802.    subset pairs need to be tested.
  2803.  
  2804.    For n = 12, how many of the 261625 subset pairs that can be obtained need
  2805.    to be tested for equality?
  2806.  
  2807.    NOTE: This problem is related to [1]Problem 103 and [2]Problem 105.
  2808.  
  2809.  
  2810.    Visible links
  2811.    1. problem=103
  2812.    2. problem=105
  2813.    Answer: 21384
  2814.  
  2815.  
  2816. Problem 107
  2817. ===========
  2818.  
  2819.  
  2820.    The following undirected network consists of seven vertices and twelve
  2821.    edges with a total weight of 243.
  2822.  
  2823.    The same network can be represented by the matrix below.
  2824.  
  2825.                   ┌──────┬────┬────┬────┬────┬────┬────┬────┐
  2826.                   │      │ A  │ B  │ C  │ D  │ E  │ F  │ G  │
  2827.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2828.                   │ A    │ -  │ 16 │ 12 │ 21 │ -  │ -  │ -  │
  2829.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2830.                   │ B    │ 16 │ -  │ -  │ 17 │ 20 │ -  │ -  │
  2831.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2832.                   │ C    │ 12 │ -  │ -  │ 28 │ -  │ 31 │ -  │
  2833.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2834.                   │ D    │ 21 │ 17 │ 28 │ -  │ 18 │ 19 │ 23 │
  2835.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2836.                   │ E    │ -  │ 20 │ -  │ 18 │ -  │ -  │ 11 │
  2837.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2838.                   │ F    │ -  │ -  │ 31 │ 19 │ -  │ -  │ 27 │
  2839.                   ├──────┼────┼────┼────┼────┼────┼────┼────┤
  2840.                   │ G    │ -  │ -  │ -  │ 23 │ 11 │ 27 │ -  │
  2841.                   └──────┴────┴────┴────┴────┴────┴────┴────┘
  2842.  
  2843.    However, it is possible to optimise the network by removing some edges and
  2844.    still ensure that all points on the network remain connected. The network
  2845.    which achieves the maximum saving is shown below. It has a weight of 93,
  2846.    representing a saving of 243 − 93 = 150 from the original network.
  2847.  
  2848.    Using [1]network.txt, a 6K text file containing a network with forty
  2849.    vertices, and given in matrix form, find the maximum saving which can be
  2850.    achieved by removing redundant edges whilst ensuring that the network
  2851.    remains connected.
  2852.  
  2853.  
  2854.    Visible links
  2855.    1. network.txt
  2856.    p_107_1.gif
  2857.    p_107_2.gif
  2858.    Answer: 259679
  2859.  
  2860.  
  2861. Problem 108
  2862. ===========
  2863.  
  2864.  
  2865.    In the following equation x, y, and n are positive integers.
  2866.  
  2867.                                    1   1   1
  2868.                                    ─ + ─ = ─
  2869.                                    x   y   n
  2870.  
  2871.    For n = 4 there are exactly three distinct solutions:
  2872.  
  2873.                                    1   1    1
  2874.                                    ─ + ─  = ─
  2875.                                    5   20   4
  2876.                                    1   1    1
  2877.                                    ─ + ─  = ─
  2878.                                    6   12   4
  2879.                                    1   1    1
  2880.                                    ─ + ─  = ─
  2881.                                    8   8    4
  2882.  
  2883.    What is the least value of n for which the number of distinct solutions
  2884.    exceeds one-thousand?
  2885.  
  2886.    NOTE: This problem is an easier version of [1]Problem 110; it is strongly
  2887.    advised that you solve this one first.
  2888.  
  2889.  
  2890.    Visible links
  2891.    1. problem=110
  2892.    Answer: 180180
  2893.  
  2894.  
  2895. Problem 109
  2896. ===========
  2897.  
  2898.  
  2899.    In the game of darts a player throws three darts at a target board which
  2900.    is split into twenty equal sized sections numbered one to twenty.
  2901.  
  2902.    The score of a dart is determined by the number of the region that the
  2903.    dart lands in. A dart landing outside the red/green outer ring scores
  2904.    zero. The black and cream regions inside this ring represent single
  2905.    scores. However, the red/green outer ring and middle ring score double and
  2906.    treble scores respectively.
  2907.  
  2908.    At the centre of the board are two concentric circles called the bull
  2909.    region, or bulls-eye. The outer bull is worth 25 points and the inner bull
  2910.    is a double, worth 50 points.
  2911.  
  2912.    There are many variations of rules but in the most popular game the
  2913.    players will begin with a score 301 or 501 and the first player to reduce
  2914.    their running total to zero is a winner. However, it is normal to play a
  2915.    "doubles out" system, which means that the player must land a double
  2916.    (including the double bulls-eye at the centre of the board) on their final
  2917.    dart to win; any other dart that would reduce their running total to one
  2918.    or lower means the score for that set of three darts is "bust".
  2919.  
  2920.    When a player is able to finish on their current score it is called a
  2921.    "checkout" and the highest checkout is 170: T20 T20 D25 (two treble 20s
  2922.    and double bull).
  2923.  
  2924.    There are exactly eleven distinct ways to checkout on a score of 6:
  2925.  
  2926.                                    ┌──┬──┬──┐
  2927.                                    │D3│  │  │
  2928.                                    ├──┼──┼──┤
  2929.                                    │D1│D2│  │
  2930.                                    ├──┼──┼──┤
  2931.                                    │S2│D2│  │
  2932.                                    ├──┼──┼──┤
  2933.                                    │D2│D1│  │
  2934.                                    ├──┼──┼──┤
  2935.                                    │S4│D1│  │
  2936.                                    ├──┼──┼──┤
  2937.                                    │S1│S1│D2│
  2938.                                    ├──┼──┼──┤
  2939.                                    │S1│T1│D1│
  2940.                                    ├──┼──┼──┤
  2941.                                    │S1│S3│D1│
  2942.                                    ├──┼──┼──┤
  2943.                                    │D1│D1│D1│
  2944.                                    ├──┼──┼──┤
  2945.                                    │D1│S2│D1│
  2946.                                    ├──┼──┼──┤
  2947.                                    │S2│S2│D1│
  2948.                                    └──┴──┴──┘
  2949.  
  2950.    Note that D1 D2 is considered different to D2 D1 as they finish on
  2951.    different doubles. However, the combination S1 T1 D1 is considered the
  2952.    same as T1 S1 D1.
  2953.  
  2954.    In addition we shall not include misses in considering combinations; for
  2955.    example, D3 is the same as 0 D3 and 0 0 D3.
  2956.  
  2957.    Incredibly there are 42336 distinct ways of checking out in total.
  2958.  
  2959.    How many distinct ways can a player checkout with a score less than 100?
  2960.  
  2961.    
  2962.    p_109.gif
  2963.    Answer: 38182
  2964.  
  2965.  
  2966. Problem 110
  2967. ===========
  2968.  
  2969.  
  2970.    In the following equation x, y, and n are positive integers.
  2971.  
  2972.                                    1   1   1
  2973.                                    ─ + ─ = ─
  2974.                                    x   y   n
  2975.  
  2976.    It can be verified that when n = 1260 there are 113 distinct solutions and
  2977.    this is the least value of n for which the total number of distinct
  2978.    solutions exceeds one hundred.
  2979.  
  2980.    What is the least value of n for which the number of distinct solutions
  2981.    exceeds four million?
  2982.  
  2983.    NOTE: This problem is a much more difficult version of [1]Problem 108 and
  2984.    as it is well beyond the limitations of a brute force approach it requires
  2985.    a clever implementation.
  2986.  
  2987.  
  2988.    Visible links
  2989.    1. problem=108
  2990.    Answer: 591a7a92f10322866e6a02f3b2386a1c
  2991.  
  2992.  
  2993. Problem 111
  2994. ===========
  2995.  
  2996.  
  2997.    Considering 4-digit primes containing repeated digits it is clear that
  2998.    they cannot all be the same: 1111 is divisible by 11, 2222 is divisible by
  2999.    22, and so on. But there are nine 4-digit primes containing three ones:
  3000.  
  3001.               1117, 1151, 1171, 1181, 1511, 1811, 2111, 4111, 8111
  3002.  
  3003.    We shall say that M(n, d) represents the maximum number of repeated digits
  3004.    for an n-digit prime where d is the repeated digit, N(n, d) represents the
  3005.    number of such primes, and S(n, d) represents the sum of these primes.
  3006.  
  3007.    So M(4, 1) = 3 is the maximum number of repeated digits for a 4-digit
  3008.    prime where one is the repeated digit, there are N(4, 1) = 9 such primes,
  3009.    and the sum of these primes is S(4, 1) = 22275. It turns out that for d =
  3010.    0, it is only possible to have M(4, 0) = 2 repeated digits, but there are
  3011.    N(4, 0) = 13 such cases.
  3012.  
  3013.    In the same way we obtain the following results for 4-digit primes.
  3014.  
  3015.                    ┌──────────┬─────────┬─────────┬─────────┐
  3016.                    │ Digit, d │ M(4, d) │ N(4, d) │ S(4, d) │
  3017.                    ├──────────┼─────────┼─────────┼─────────┤
  3018.                    │ 0        │ 2       │ 13      │ 67061   │
  3019.                    ├──────────┼─────────┼─────────┼─────────┤
  3020.                    │ 1        │ 3       │ 9       │ 22275   │
  3021.                    ├──────────┼─────────┼─────────┼─────────┤
  3022.                    │ 2        │ 3       │ 1       │ 2221    │
  3023.                    ├──────────┼─────────┼─────────┼─────────┤
  3024.                    │ 3        │ 3       │ 12      │ 46214   │
  3025.                    ├──────────┼─────────┼─────────┼─────────┤
  3026.                    │ 4        │ 3       │ 2       │ 8888    │
  3027.                    ├──────────┼─────────┼─────────┼─────────┤
  3028.                    │ 5        │ 3       │ 1       │ 5557    │
  3029.                    ├──────────┼─────────┼─────────┼─────────┤
  3030.                    │ 6        │ 3       │ 1       │ 6661    │
  3031.                    ├──────────┼─────────┼─────────┼─────────┤
  3032.                    │ 7        │ 3       │ 9       │ 57863   │
  3033.                    ├──────────┼─────────┼─────────┼─────────┤
  3034.                    │ 8        │ 3       │ 1       │ 8887    │
  3035.                    ├──────────┼─────────┼─────────┼─────────┤
  3036.                    │ 9        │ 3       │ 7       │ 48073   │
  3037.                    └──────────┴─────────┴─────────┴─────────┘
  3038.  
  3039.    For d = 0 to 9, the sum of all S(4, d) is 273700.
  3040.  
  3041.    Find the sum of all S(10, d).
  3042.  
  3043.    
  3044.    Answer: cdf4d134a3b0caa10a69e2771ac4fd36
  3045.  
  3046.  
  3047. Problem 112
  3048. ===========
  3049.  
  3050.  
  3051.    Working from left-to-right if no digit is exceeded by the digit to its
  3052.    left it is called an increasing number; for example, 134468.
  3053.  
  3054.    Similarly if no digit is exceeded by the digit to its right it is called a
  3055.    decreasing number; for example, 66420.
  3056.  
  3057.    We shall call a positive integer that is neither increasing nor decreasing
  3058.    a "bouncy" number; for example, 155349.
  3059.  
  3060.    Clearly there cannot be any bouncy numbers below one-hundred, but just
  3061.    over half of the numbers below one-thousand (525) are bouncy. In fact, the
  3062.    least number for which the proportion of bouncy numbers first reaches 50%
  3063.    is 538.
  3064.  
  3065.    Surprisingly, bouncy numbers become more and more common and by the time
  3066.    we reach 21780 the proportion of bouncy numbers is equal to 90%.
  3067.  
  3068.    Find the least number for which the proportion of bouncy numbers is
  3069.    exactly 99%.
  3070.  
  3071.    
  3072.    Answer: 1587000
  3073.  
  3074.  
  3075. Problem 113
  3076. ===========
  3077.  
  3078.  
  3079.    Working from left-to-right if no digit is exceeded by the digit to its
  3080.    left it is called an increasing number; for example, 134468.
  3081.  
  3082.    Similarly if no digit is exceeded by the digit to its right it is called a
  3083.    decreasing number; for example, 66420.
  3084.  
  3085.    We shall call a positive integer that is neither increasing nor decreasing
  3086.    a "bouncy" number; for example, 155349.
  3087.  
  3088.    As n increases, the proportion of bouncy numbers below n increases such
  3089.    that there are only 12951 numbers below one-million that are not bouncy
  3090.    and only 277032 non-bouncy numbers below 10^10.
  3091.  
  3092.    How many numbers below a googol (10^100) are not bouncy?
  3093.  
  3094.    
  3095.    Answer: a9e504ee704c87f9bddad6d3ffe39532
  3096.  
  3097.  
  3098. Problem 114
  3099. ===========
  3100.  
  3101.  
  3102.    A row measuring seven units in length has red blocks with a minimum length
  3103.    of three units placed on it, such that any two red blocks (which are
  3104.    allowed to be different lengths) are separated by at least one black
  3105.    square. There are exactly seventeen ways of doing this.
  3106.  
  3107.                           ┌┬┬┬┬┬┬┐  ┌──┬┬┬┬┐  ┌┬──┬┬┬┐
  3108.                           └┴┴┴┴┴┴┘  └──┴┴┴┴┘  └┴──┴┴┴┘
  3109.                           ┌┬┬──┬┬┐  ┌┬┬┬──┬┐  ┌┬┬┬┬──┐
  3110.                           └┴┴──┴┴┘  └┴┴┴──┴┘  └┴┴┴┴──┘
  3111.                           ┌──┬┬──┐  ┌───┬┬┬┐  ┌┬───┬┬┐
  3112.                           └──┴┴──┘  └───┴┴┴┘  └┴───┴┴┘
  3113.                           ┌┬┬───┬┐  ┌┬┬┬───┐  ┌────┬┬┐
  3114.                           └┴┴───┴┘  └┴┴┴───┘  └────┴┴┘
  3115.                           ┌┬────┬┐  ┌┬┬────┐  ┌─────┬┐
  3116.                           └┴────┴┘  └┴┴────┘  └─────┴┘
  3117.                           ┌┬─────┐  ┌──────┐   
  3118.                           └┴─────┘  └──────┘
  3119.  
  3120.    How many ways can a row measuring fifty units in length be filled?
  3121.  
  3122.    NOTE: Although the example above does not lend itself to the possibility,
  3123.    in general it is permitted to mix block sizes. For example, on a row
  3124.    measuring eight units in length you could use red (3), black (1), and red
  3125.    (4).
  3126.  
  3127.    
  3128.    Answer: de48ca72bf252a8be7e0aad762eadcf8
  3129.  
  3130.  
  3131. Problem 115
  3132. ===========
  3133.  
  3134.  
  3135.    NOTE: This is a more difficult version of [1]Problem 114.
  3136.  
  3137.    A row measuring n units in length has red blocks with a minimum length of
  3138.    m units placed on it, such that any two red blocks (which are allowed to
  3139.    be different lengths) are separated by at least one black square.
  3140.  
  3141.    Let the fill-count function, F(m, n), represent the number of ways that a
  3142.    row can be filled.
  3143.  
  3144.    For example, F(3, 29) = 673135 and F(3, 30) = 1089155.
  3145.  
  3146.    That is, for m = 3, it can be seen that n = 30 is the smallest value for
  3147.    which the fill-count function first exceeds one million.
  3148.  
  3149.    In the same way, for m = 10, it can be verified that F(10, 56) = 880711
  3150.    and F(10, 57) = 1148904, so n = 57 is the least value for which the
  3151.    fill-count function first exceeds one million.
  3152.  
  3153.    For m = 50, find the least value of n for which the fill-count function
  3154.    first exceeds one million.
  3155.  
  3156.  
  3157.    Visible links
  3158.    1. problem=114
  3159.    Answer: 168
  3160.  
  3161.  
  3162. Problem 116
  3163. ===========
  3164.  
  3165.  
  3166.    A row of five black square tiles is to have a number of its tiles replaced
  3167.    with coloured oblong tiles chosen from red (length two), green (length
  3168.    three), or blue (length four).
  3169.  
  3170.    If red tiles are chosen there are exactly seven ways this can be done.
  3171.  
  3172.                          ┌─╥╥╥┐  ┌╥─╥╥┐  ┌╥╥─╥┐  ┌╥╥╥─┐
  3173.                          └─╨╨╨┘  └╨─╨╨┘  └╨╨─╨┘  └╨╨╨─┘
  3174.  
  3175.                          ┌─╥─╥┐  ┌─╥╥─┐  ┌╥─╥─┐   
  3176.                          └─╨─╨┘  └─╨╨─┘  └╨─╨─┘
  3177.  
  3178.    If green tiles are chosen there are three ways.
  3179.  
  3180.                            ┌──╥╥┐  ┌╥──╥┐  ┌╥╥──┐   
  3181.                            └──╨╨┘  └╨──╨┘  └╨╨──┘
  3182.  
  3183.    And if blue tiles are chosen there are two ways.
  3184.  
  3185.                                  ┌╥───┐  ┌───╥┐
  3186.                                  └╨───┘  └───╨┘
  3187.  
  3188.    Assuming that colours cannot be mixed there are 7 + 3 + 2 = 12 ways of
  3189.    replacing the black tiles in a row measuring five units in length.
  3190.  
  3191.    How many different ways can the black tiles in a row measuring fifty units
  3192.    in length be replaced if colours cannot be mixed and at least one coloured
  3193.    tile must be used?
  3194.  
  3195.    NOTE: This is related to [1]Problem 117.
  3196.  
  3197.  
  3198.    Visible links
  3199.    1. problem=117
  3200.    Answer: c21ca0ec54e6d1646a953a480f68feb4
  3201.  
  3202.  
  3203. Problem 117
  3204. ===========
  3205.  
  3206.  
  3207.    Using a combination of black square tiles and oblong tiles chosen from:
  3208.    red tiles measuring two units, green tiles measuring three units, and blue
  3209.    tiles measuring four units, it is possible to tile a row measuring five
  3210.    units in length in exactly fifteen different ways.
  3211.  
  3212.                          ┌╥╥╥╥┐  ┌─╥╥╥┐  ┌╥─╥╥┐  ┌╥╥─╥┐
  3213.                          └╨╨╨╨┘  └─╨╨╨┘  └╨─╨╨┘  └╨╨─╨┘
  3214.  
  3215.                          ┌╥╥╥─┐  ┌─╥─╥┐  ┌─╥╥─┐  ┌╥─╥─┐
  3216.                          └╨╨╨─┘  └─╨─╨┘  └─╨╨─┘  └╨─╨─┘
  3217.  
  3218.                          ┌──╥╥┐  ┌╥──╥┐  ┌╥╥──┐  ┌─╥──┐
  3219.                          └──╨╨┘  └╨──╨┘  └╨╨──┘  └─╨──┘
  3220.  
  3221.                          ┌──╥─┐  ┌───╥┐  ┌╥───┐   
  3222.                          └──╨─┘  └───╨┘  └╨───┘
  3223.  
  3224.    How many ways can a row measuring fifty units in length be tiled?
  3225.  
  3226.    NOTE: This is related to [1]Problem 116.
  3227.  
  3228.  
  3229.    Visible links
  3230.    1. problem=116
  3231.    Answer: 542612809b3dd08cf518b85450fce8d6
  3232.  
  3233.  
  3234. Problem 118
  3235. ===========
  3236.  
  3237.  
  3238.    Using all of the digits 1 through 9 and concatenating them freely to form
  3239.    decimal integers, different sets can be formed. Interestingly with the set
  3240.    {2,5,47,89,631}, all of the elements belonging to it are prime.
  3241.  
  3242.    How many distinct sets containing each of the digits one through nine
  3243.    exactly once contain only prime elements?
  3244.  
  3245.    
  3246.    Answer: 44680
  3247.  
  3248.  
  3249. Problem 119
  3250. ===========
  3251.  
  3252.  
  3253.    The number 512 is interesting because it is equal to the sum of its digits
  3254.    raised to some power: 5 + 1 + 2 = 8, and 8^3 = 512. Another example of a
  3255.    number with this property is 614656 = 28^4.
  3256.  
  3257.    We shall define a[n] to be the nth term of this sequence and insist that a
  3258.    number must contain at least two digits to have a sum.
  3259.  
  3260.    You are given that a[2] = 512 and a[10] = 614656.
  3261.  
  3262.    Find a[30].
  3263.  
  3264.    
  3265.    Answer: 72fddfa6c52a120892ade628f3819da4
  3266.  
  3267.  
  3268. Problem 120
  3269. ===========
  3270.  
  3271.  
  3272.    Let r be the remainder when (a−1)^n + (a+1)^n is divided by a^2.
  3273.  
  3274.    For example, if a = 7 and n = 3, then r = 42: 6^3 + 8^3 = 728 ≡ 42 mod 49.
  3275.    And as n varies, so too will r, but for a = 7 it turns out that r[max] =
  3276.    42.
  3277.  
  3278.    For 3 ≤ a ≤ 1000, find ∑ r[max].
  3279.  
  3280.    
  3281.    Answer: 0dd05ec40fe11279c2203b72e92a450a
  3282.  
  3283.  
  3284. Problem 121
  3285. ===========
  3286.  
  3287.  
  3288.    A bag contains one red disc and one blue disc. In a game of chance a
  3289.    player takes a disc at random and its colour is noted. After each turn the
  3290.    disc is returned to the bag, an extra red disc is added, and another disc
  3291.    is taken at random.
  3292.  
  3293.    The player pays £1 to play and wins if they have taken more blue discs
  3294.    than red discs at the end of the game.
  3295.  
  3296.    If the game is played for four turns, the probability of a player winning
  3297.    is exactly 11/120, and so the maximum prize fund the banker should
  3298.    allocate for winning in this game would be £10 before they would expect to
  3299.    incur a loss. Note that any payout will be a whole number of pounds and
  3300.    also includes the original £1 paid to play the game, so in the example
  3301.    given the player actually wins £9.
  3302.  
  3303.    Find the maximum prize fund that should be allocated to a single game in
  3304.    which fifteen turns are played.
  3305.  
  3306.    
  3307.    Answer: 2269
  3308.  
  3309.  
  3310. Problem 122
  3311. ===========
  3312.  
  3313.  
  3314.    The most naive way of computing n^15 requires fourteen multiplications:
  3315.  
  3316.    n × n × ... × n = n^15
  3317.  
  3318.    But using a "binary" method you can compute it in six multiplications:
  3319.  
  3320.    n × n = n^2
  3321.    n^2 × n^2 = n^4
  3322.    n^4 × n^4 = n^8
  3323.    n^8 × n^4 = n^12
  3324.    n^12 × n^2 = n^14
  3325.    n^14 × n = n^15
  3326.  
  3327.    However it is yet possible to compute it in only five multiplications:
  3328.  
  3329.    n × n = n^2
  3330.    n^2 × n = n^3
  3331.    n^3 × n^3 = n^6
  3332.    n^6 × n^6 = n^12
  3333.    n^12 × n^3 = n^15
  3334.  
  3335.    We shall define m(k) to be the minimum number of multiplications to
  3336.    compute n^k; for example m(15) = 5.
  3337.  
  3338.    For 1 ≤ k ≤ 200, find ∑ m(k).
  3339.  
  3340.    
  3341.    Answer: 1582
  3342.  
  3343.  
  3344. Problem 123
  3345. ===========
  3346.  
  3347.  
  3348.    Let p[n] be the nth prime: 2, 3, 5, 7, 11, ..., and let r be the remainder
  3349.    when (p[n]−1)^n + (p[n]+1)^n is divided by p[n]^2.
  3350.  
  3351.    For example, when n = 3, p[3] = 5, and 4^3 + 6^3 = 280 ≡ 5 mod 25.
  3352.  
  3353.    The least value of n for which the remainder first exceeds 10^9 is 7037.
  3354.  
  3355.    Find the least value of n for which the remainder first exceeds 10^10.
  3356.  
  3357.    
  3358.    Answer: 21035
  3359.  
  3360.  
  3361. Problem 124
  3362. ===========
  3363.  
  3364.  
  3365.    The radical of n, rad(n), is the product of the distinct prime factors of
  3366.    n. For example, 504 = 2^3 × 3^2 × 7, so rad(504) = 2 × 3 × 7 = 42.
  3367.  
  3368.    If we calculate rad(n) for 1 ≤ n ≤ 10, then sort them on rad(n), and
  3369.    sorting on n if the radical values are equal, we get:
  3370.  
  3371.                             Unsorted       Sorted
  3372.                             n  rad(n)   n  rad(n) k
  3373.                             1    1      1    1    1
  3374.                             2    2      2    2    2
  3375.                             3    3      4    2    3
  3376.                             4    2      8    2    4
  3377.                             5    5      3    3    5
  3378.                             6    6      9    3    6
  3379.                             7    7      5    5    7
  3380.                             8    2      6    6    8
  3381.                             9    3      7    7    9
  3382.                             10   10     10   10   10
  3383.  
  3384.    Let E(k) be the kth element in the sorted n column; for example, E(4) = 8
  3385.    and E(6) = 9.
  3386.  
  3387.    If rad(n) is sorted for 1 ≤ n ≤ 100000, find E(10000).
  3388.  
  3389.    
  3390.    Answer: 21417
  3391.  
  3392.  
  3393. Problem 125
  3394. ===========
  3395.  
  3396.  
  3397.    The palindromic number 595 is interesting because it can be written as the
  3398.    sum of consecutive squares: 6^2 + 7^2 + 8^2 + 9^2 + 10^2 + 11^2 + 12^2.
  3399.  
  3400.    There are exactly eleven palindromes below one-thousand that can be
  3401.    written as consecutive square sums, and the sum of these palindromes is
  3402.    4164. Note that 1 = 0^2 + 1^2 has not been included as this problem is
  3403.    concerned with the squares of positive integers.
  3404.  
  3405.    Find the sum of all the numbers less than 10^8 that are both palindromic
  3406.    and can be written as the sum of consecutive squares.
  3407.  
  3408.    
  3409.    Answer: 1b5635e8ab723e01570ca783129493dd
  3410.  
  3411.  
  3412. Problem 126
  3413. ===========
  3414.  
  3415.  
  3416.    The minimum number of cubes to cover every visible face on a cuboid
  3417.    measuring 3 x 2 x 1 is twenty-two.
  3418.  
  3419.    If we then add a second layer to this solid it would require forty-six
  3420.    cubes to cover every visible face, the third layer would require
  3421.    seventy-eight cubes, and the fourth layer would require one-hundred and
  3422.    eighteen cubes to cover every visible face.
  3423.  
  3424.    However, the first layer on a cuboid measuring 5 x 1 x 1 also requires
  3425.    twenty-two cubes; similarly the first layer on cuboids measuring
  3426.    5 x 3 x 1, 7 x 2 x 1, and 11 x 1 x 1 all contain forty-six cubes.
  3427.  
  3428.    We shall define C(n) to represent the number of cuboids that contain n
  3429.    cubes in one of its layers. So C(22) = 2, C(46) = 4, C(78) = 5, and C(118)
  3430.    = 8.
  3431.  
  3432.    It turns out that 154 is the least value of n for which C(n) = 10.
  3433.  
  3434.    Find the least value of n for which C(n) = 1000.
  3435.  
  3436.    
  3437.    p_126.gif
  3438.    Answer: 18522
  3439.  
  3440.  
  3441. Problem 127
  3442. ===========
  3443.  
  3444.  
  3445.    The radical of n, rad(n), is the product of distinct prime factors of n.
  3446.    For example, 504 = 2^3 × 3^2 × 7, so rad(504) = 2 × 3 × 7 = 42.
  3447.  
  3448.    We shall define the triplet of positive integers (a, b, c) to be an
  3449.    abc-hit if:
  3450.  
  3451.     1. GCD(a, b) = GCD(a, c) = GCD(b, c) = 1
  3452.     2. a < b
  3453.     3. a + b = c
  3454.     4. rad(abc) < c
  3455.  
  3456.    For example, (5, 27, 32) is an abc-hit, because:
  3457.  
  3458.     1. GCD(5, 27) = GCD(5, 32) = GCD(27, 32) = 1
  3459.     2. 5 < 27
  3460.     3. 5 + 27 = 32
  3461.     4. rad(4320) = 30 < 32
  3462.  
  3463.    It turns out that abc-hits are quite rare and there are only thirty-one
  3464.    abc-hits for c < 1000, with ∑c = 12523.
  3465.  
  3466.    Find ∑c for c < 120000.
  3467.  
  3468.    
  3469.    Answer: 18407904
  3470.  
  3471.  
  3472. Problem 128
  3473. ===========
  3474.  
  3475.  
  3476.    A hexagonal tile with number 1 is surrounded by a ring of six hexagonal
  3477.    tiles, starting at "12 o'clock" and numbering the tiles 2 to 7 in an
  3478.    anti-clockwise direction.
  3479.  
  3480.    New rings are added in the same fashion, with the next rings being
  3481.    numbered 8 to 19, 20 to 37, 38 to 61, and so on. The diagram below shows
  3482.    the first three rings.
  3483.  
  3484.    By finding the difference between tile n and each its six neighbours we
  3485.    shall define PD(n) to be the number of those differences which are prime.
  3486.  
  3487.    For example, working clockwise around tile 8 the differences are 12, 29,
  3488.    11, 6, 1, and 13. So PD(8) = 3.
  3489.  
  3490.    In the same way, the differences around tile 17 are 1, 17, 16, 1, 11, and
  3491.    10, hence PD(17) = 2.
  3492.  
  3493.    It can be shown that the maximum value of PD(n) is 3.
  3494.  
  3495.    If all of the tiles for which PD(n) = 3 are listed in ascending order to
  3496.    form a sequence, the 10th tile would be 271.
  3497.  
  3498.    Find the 2000th tile in this sequence.
  3499.  
  3500.    
  3501.    p_128.gif
  3502.    Answer: 93a1925da4792b4fa5d2dbb6ebb7c4a2
  3503.  
  3504.  
  3505. Problem 129
  3506. ===========
  3507.  
  3508.  
  3509.    A number consisting entirely of ones is called a repunit. We shall define
  3510.    R(k) to be a repunit of length k; for example, R(6) = 111111.
  3511.  
  3512.    Given that n is a positive integer and GCD(n, 10) = 1, it can be shown
  3513.    that there always exists a value, k, for which R(k) is divisible by n, and
  3514.    let A(n) be the least such value of k; for example, A(7) = 6 and A(41) =
  3515.    5.
  3516.  
  3517.    The least value of n for which A(n) first exceeds ten is 17.
  3518.  
  3519.    Find the least value of n for which A(n) first exceeds one-million.
  3520.  
  3521.    
  3522.    Answer: 1000023
  3523.  
  3524.  
  3525. Problem 130
  3526. ===========
  3527.  
  3528.  
  3529.    A number consisting entirely of ones is called a repunit. We shall define
  3530.    R(k) to be a repunit of length k; for example, R(6) = 111111.
  3531.  
  3532.    Given that n is a positive integer and GCD(n, 10) = 1, it can be shown
  3533.    that there always exists a value, k, for which R(k) is divisible by n, and
  3534.    let A(n) be the least such value of k; for example, A(7) = 6 and A(41) =
  3535.    5.
  3536.  
  3537.    You are given that for all primes, p > 5, that p − 1 is divisible by A(p).
  3538.    For example, when p = 41, A(41) = 5, and 40 is divisible by 5.
  3539.  
  3540.    However, there are rare composite values for which this is also true; the
  3541.    first five examples being 91, 259, 451, 481, and 703.
  3542.  
  3543.    Find the sum of the first twenty-five composite values of n for which
  3544.    GCD(n, 10) = 1 and n − 1 is divisible by A(n).
  3545.  
  3546.    
  3547.    Answer: 149253
  3548.  
  3549.  
  3550. Problem 131
  3551. ===========
  3552.  
  3553.  
  3554.    There are some prime values, p, for which there exists a positive integer,
  3555.    n, such that the expression n^3 + n^2p is a perfect cube.
  3556.  
  3557.    For example, when p = 19, 8^3 + 8^2×19 = 12^3.
  3558.  
  3559.    What is perhaps most surprising is that for each prime with this property
  3560.    the value of n is unique, and there are only four such primes below
  3561.    one-hundred.
  3562.  
  3563.    How many primes below one million have this remarkable property?
  3564.  
  3565.    
  3566.    Answer: 173
  3567.  
  3568.  
  3569. Problem 132
  3570. ===========
  3571.  
  3572.  
  3573.    A number consisting entirely of ones is called a repunit. We shall define
  3574.    R(k) to be a repunit of length k.
  3575.  
  3576.    For example, R(10) = 1111111111 = 11×41×271×9091, and the sum of these
  3577.    prime factors is 9414.
  3578.  
  3579.    Find the sum of the first forty prime factors of R(10^9).
  3580.  
  3581.    
  3582.    Answer: 843296
  3583.  
  3584.  
  3585. Problem 133
  3586. ===========
  3587.  
  3588.  
  3589.    A number consisting entirely of ones is called a repunit. We shall define
  3590.    R(k) to be a repunit of length k; for example, R(6) = 111111.
  3591.  
  3592.    Let us consider repunits of the form R(10^n).
  3593.  
  3594.    Although R(10), R(100), or R(1000) are not divisible by 17, R(10000) is
  3595.    divisible by 17. Yet there is no value of n for which R(10^n) will divide
  3596.    by 19. In fact, it is remarkable that 11, 17, 41, and 73 are the only four
  3597.    primes below one-hundred that can be a factor of R(10^n).
  3598.  
  3599.    Find the sum of all the primes below one-hundred thousand that will never
  3600.    be a factor of R(10^n).
  3601.  
  3602.    
  3603.    Answer: c1d33d79d08cde65eaa78e4583ea0594
  3604.  
  3605.  
  3606. Problem 134
  3607. ===========
  3608.  
  3609.  
  3610.    Consider the consecutive primes p[1] = 19 and p[2] = 23. It can be
  3611.    verified that 1219 is the smallest number such that the last digits are
  3612.    formed by p[1] whilst also being divisible by p[2].
  3613.  
  3614.    In fact, with the exception of p[1] = 3 and p[2] = 5, for every pair of
  3615.    consecutive primes, p[2] > p[1], there exist values of n for which the
  3616.    last digits are formed by p[1] and n is divisible by p[2]. Let S be the
  3617.    smallest of these values of n.
  3618.  
  3619.    Find ∑ S for every pair of consecutive primes with 5 ≤ p[1] ≤ 1000000.
  3620.  
  3621.    
  3622.    Answer: f12b07460d2586ea47b4d305ae0b0539
  3623.  
  3624.  
  3625. Problem 135
  3626. ===========
  3627.  
  3628.  
  3629.    Given the positive integers, x, y, and z, are consecutive terms of an
  3630.    arithmetic progression, the least value of the positive integer, n, for
  3631.    which the equation, x^2 − y^2 − z^2 = n, has exactly two solutions is n =
  3632.    27:
  3633.  
  3634.                    34^2 − 27^2 − 20^2 = 12^2 − 9^2 − 6^2 = 27
  3635.  
  3636.    It turns out that n = 1155 is the least value which has exactly ten
  3637.    solutions.
  3638.  
  3639.    How many values of n less than one million have exactly ten distinct
  3640.    solutions?
  3641.  
  3642.    
  3643.    Answer: 4989
  3644.  
  3645.  
  3646. Problem 136
  3647. ===========
  3648.  
  3649.  
  3650.    The positive integers, x, y, and z, are consecutive terms of an arithmetic
  3651.    progression. Given that n is a positive integer, the equation, x^2 − y^2 −
  3652.    z^2 = n, has exactly one solution when n = 20:
  3653.  
  3654.                              13^2 − 10^2 − 7^2 = 20
  3655.  
  3656.    In fact there are twenty-five values of n below one hundred for which the
  3657.    equation has a unique solution.
  3658.  
  3659.    How many values of n less than fifty million have exactly one solution?
  3660.  
  3661.    
  3662.    Answer: 2544559
  3663.  
  3664.  
  3665. Problem 137
  3666. ===========
  3667.  
  3668.  
  3669.    Consider the infinite polynomial series A[F](x) = xF[1] + x^2F[2] +
  3670.    x^3F[3] + ..., where F[k] is the kth term in the Fibonacci sequence: 1, 1,
  3671.    2, 3, 5, 8, ... ; that is, F[k] = F[k−1] + F[k−2], F[1] = 1 and F[2] = 1.
  3672.  
  3673.    For this problem we shall be interested in values of x for which A[F](x)
  3674.    is a positive integer.
  3675.  
  3676.    Surprisingly A[F](1/2)  =  (1/2).1 + (1/2)^2.1 + (1/2)^3.2 + (1/2)^4.3 +
  3677.                               (1/2)^5.5 + ...
  3678.                            =  1/2 + 1/4 + 2/8 + 3/16 + 5/32 + ...
  3679.                            =  2
  3680.  
  3681.    The corresponding values of x for the first five natural numbers are shown
  3682.    below.
  3683.  
  3684.                               ┌─────────┬───────┐
  3685.                               │x        │A[F](x)│
  3686.                               ├─────────┼───────┤
  3687.                               │√2−1     │1      │
  3688.                               ├─────────┼───────┤
  3689.                               │1/2      │2      │
  3690.                               ├─────────┼───────┤
  3691.                               │(√13−2)/3│3      │
  3692.                               ├─────────┼───────┤
  3693.                               │(√89−5)/8│4      │
  3694.                               ├─────────┼───────┤
  3695.                               │(√34−3)/5│5      │
  3696.                               └─────────┴───────┘
  3697.  
  3698.    We shall call A[F](x) a golden nugget if x is rational, because they
  3699.    become increasingly rarer; for example, the 10th golden nugget is
  3700.    74049690.
  3701.  
  3702.    Find the 15th golden nugget.
  3703.  
  3704.    
  3705.    Answer: 44845aa0f47ec925a3b43e6460a55e27
  3706.  
  3707.  
  3708. Problem 138
  3709. ===========
  3710.  
  3711.  
  3712.    Consider the isosceles triangle with base length, b = 16, and legs, L =
  3713.    17.
  3714.  
  3715.    By using the Pythagorean theorem it can be seen that the height of the
  3716.    triangle, h = √(17^2 − 8^2) = 15, which is one less than the base length.
  3717.  
  3718.    With b = 272 and L = 305, we get h = 273, which is one more than the base
  3719.    length, and this is the second smallest isosceles triangle with the
  3720.    property that h = b ± 1.
  3721.  
  3722.    Find ∑ L for the twelve smallest isosceles triangles for which h = b ± 1
  3723.    and b, L are positive integers.
  3724.  
  3725.    
  3726.    p_138.gif
  3727.    Answer: f7524f4d0d6d042c0f92a0d6469aff85
  3728.  
  3729.  
  3730. Problem 139
  3731. ===========
  3732.  
  3733.  
  3734.    Let (a, b, c) represent the three sides of a right angle triangle with
  3735.    integral length sides. It is possible to place four such triangles
  3736.    together to form a square with length c.
  3737.  
  3738.    For example, (3, 4, 5) triangles can be placed together to form a 5 by 5
  3739.    square with a 1 by 1 hole in the middle and it can be seen that the 5 by 5
  3740.    square can be tiled with twenty-five 1 by 1 squares.
  3741.  
  3742.    However, if (5, 12, 13) triangles were used then the hole would measure 7
  3743.    by 7 and these could not be used to tile the 13 by 13 square.
  3744.  
  3745.    Given that the perimeter of the right triangle is less than one-hundred
  3746.    million, how many Pythagorean triangles would allow such a tiling to take
  3747.    place?
  3748.  
  3749.    
  3750.    p_139.gif
  3751.    Answer: 10057761
  3752.  
  3753.  
  3754. Problem 140
  3755. ===========
  3756.  
  3757.  
  3758.    Consider the infinite polynomial series A[G](x) = xG[1] + x^2G[2] +
  3759.    x^3G[3] + ..., where G[k] is the kth term of the second order recurrence
  3760.    relation G[k] = G[k−1] + G[k−2], G[1] = 1 and G[2] = 4; that is, 1, 4, 5,
  3761.    9, 14, 23, ... .
  3762.  
  3763.    For this problem we shall be concerned with values of x for which A[G](x)
  3764.    is a positive integer.
  3765.  
  3766.    The corresponding values of x for the first five natural numbers are shown
  3767.    below.
  3768.  
  3769.                              ┌───────────┬───────┐
  3770.                              │x          │A[G](x)│
  3771.                              ├───────────┼───────┤
  3772.                              │(√5−1)/4   │1      │
  3773.                              ├───────────┼───────┤
  3774.                              │2/5        │2      │
  3775.                              ├───────────┼───────┤
  3776.                              │(√22−2)/6  │3      │
  3777.                              ├───────────┼───────┤
  3778.                              │(√137−5)/14│4      │
  3779.                              ├───────────┼───────┤
  3780.                              │1/2        │5      │
  3781.                              └───────────┴───────┘
  3782.  
  3783.    We shall call A[G](x) a golden nugget if x is rational, because they
  3784.    become increasingly rarer; for example, the 20th golden nugget is
  3785.    211345365.
  3786.  
  3787.    Find the sum of the first thirty golden nuggets.
  3788.  
  3789.    
  3790.    Answer: e5d75f96929ba250b2732aad52f3028c
  3791.  
  3792.  
  3793. Problem 141
  3794. ===========
  3795.  
  3796.  
  3797.    A positive integer, n, is divided by d and the quotient and remainder are
  3798.    q and r respectively. In addition d, q, and r are consecutive positive
  3799.    integer terms in a geometric sequence, but not necessarily in that order.
  3800.  
  3801.    For example, 58 divided by 6 has quotient 9 and remainder 4. It can also
  3802.    be seen that 4, 6, 9 are consecutive terms in a geometric sequence (common
  3803.    ratio 3/2).
  3804.    We will call such numbers, n, progressive.
  3805.  
  3806.    Some progressive numbers, such as 9 and 10404 = 102^2, happen to also be
  3807.    perfect squares.
  3808.    The sum of all progressive perfect squares below one hundred thousand is
  3809.    124657.
  3810.  
  3811.    Find the sum of all progressive perfect squares below one trillion
  3812.    (10^12).
  3813.  
  3814.    
  3815.    Answer: 2aaefa1db80951be140183f9e8c0194e
  3816.  
  3817.  
  3818. Problem 142
  3819. ===========
  3820.  
  3821.  
  3822.    Find the smallest x + y + z with integers x > y > z > 0 such that x + y, x
  3823.    − y, x + z, x − z, y + z, y − z are all perfect squares.
  3824.  
  3825.    
  3826.    Answer: 1006193
  3827.  
  3828.  
  3829. Problem 143
  3830. ===========
  3831.  
  3832.  
  3833.    Let ABC be a triangle with all interior angles being less than 120
  3834.    degrees. Let X be any point inside the triangle and let XA = p, XC = q,
  3835.    and XB = r.
  3836.  
  3837.    Fermat challenged Torricelli to find the position of X such that p + q + r
  3838.    was minimised.
  3839.  
  3840.    Torricelli was able to prove that if equilateral triangles AOB, BNC and
  3841.    AMC are constructed on each side of triangle ABC, the circumscribed
  3842.    circles of AOB, BNC, and AMC will intersect at a single point, T, inside
  3843.    the triangle. Moreover he proved that T, called the Torricelli/Fermat
  3844.    point, minimises p + q + r. Even more remarkable, it can be shown that
  3845.    when the sum is minimised, AN = BM = CO = p + q + r and that AN, BM and CO
  3846.    also intersect at T.
  3847.  
  3848.    If the sum is minimised and a, b, c, p, q and r are all positive integers
  3849.    we shall call triangle ABC a Torricelli triangle. For example, a = 399, b
  3850.    = 455, c = 511 is an example of a Torricelli triangle, with p + q + r =
  3851.    784.
  3852.  
  3853.    Find the sum of all distinct values of p + q + r ≤ 120000 for Torricelli
  3854.    triangles.
  3855.  
  3856.    
  3857.    p_143_torricelli.gif
  3858.    Answer: 30758397
  3859.  
  3860.  
  3861. Problem 144
  3862. ===========
  3863.  
  3864.  
  3865.    In laser physics, a "white cell" is a mirror system that acts as a delay
  3866.    line for the laser beam. The beam enters the cell, bounces around on the
  3867.    mirrors, and eventually works its way back out.
  3868.  
  3869.    The specific white cell we will be considering is an ellipse with the
  3870.    equation 4x^2 + y^2 = 100
  3871.  
  3872.    The section corresponding to −0.01 ≤ x ≤ +0.01 at the top is missing,
  3873.    allowing the light to enter and exit through the hole.
  3874.  
  3875.    The light beam in this problem starts at the point (0.0,10.1) just outside
  3876.    the white cell, and the beam first impacts the mirror at (1.4,-9.6).
  3877.  
  3878.    Each time the laser beam hits the surface of the ellipse, it follows the
  3879.    usual law of reflection "angle of incidence equals angle of reflection."
  3880.    That is, both the incident and reflected beams make the same angle with
  3881.    the normal line at the point of incidence.
  3882.  
  3883.    In the figure on the left, the red line shows the first two points of
  3884.    contact between the laser beam and the wall of the white cell; the blue
  3885.    line shows the line tangent to the ellipse at the point of incidence of
  3886.    the first bounce.
  3887.  
  3888.    The slope m of the tangent line at any point (x,y) of the given ellipse
  3889.    is: m = −4x/y
  3890.  
  3891.    The normal line is perpendicular to this tangent line at the point of
  3892.    incidence.
  3893.  
  3894.    The animation on the right shows the first 10 reflections of the beam.
  3895.  
  3896.    How many times does the beam hit the internal surface of the white cell
  3897.    before exiting?
  3898.  
  3899.    
  3900.    p_144_1.gif
  3901.    p_144_2.gif
  3902.    Answer: 354
  3903.  
  3904.  
  3905. Problem 145
  3906. ===========
  3907.  
  3908.  
  3909.    Some positive integers n have the property that the sum [ n + reverse(n) ]
  3910.    consists entirely of odd (decimal) digits. For instance, 36 + 63 = 99 and
  3911.    409 + 904 = 1313. We will call such numbers reversible; so 36, 63, 409,
  3912.    and 904 are reversible. Leading zeroes are not allowed in either n or
  3913.    reverse(n).
  3914.  
  3915.    There are 120 reversible numbers below one-thousand.
  3916.  
  3917.    How many reversible numbers are there below one-billion (10^9)?
  3918.  
  3919.    
  3920.    Answer: 608720
  3921.  
  3922.  
  3923. Problem 146
  3924. ===========
  3925.  
  3926.  
  3927.    The smallest positive integer n for which the numbers n^2+1, n^2+3, n^2+7,
  3928.    n^2+9, n^2+13, and n^2+27 are consecutive primes is 10. The sum of all
  3929.    such integers n below one-million is 1242490.
  3930.  
  3931.    What is the sum of all such integers n below 150 million?
  3932.  
  3933.    
  3934.    Answer: 525bd2bf0e31b0f19b38a1d21f2f6a16
  3935.  
  3936.  
  3937. Problem 147
  3938. ===========
  3939.  
  3940.  
  3941.    In a 3x2 cross-hatched grid, a total of 37 different rectangles could be
  3942.    situated within that grid as indicated in the sketch.
  3943.  
  3944.    There are 5 grids smaller than 3x2, vertical and horizontal dimensions
  3945.    being important, i.e. 1x1, 2x1, 3x1, 1x2 and 2x2. If each of them is
  3946.    cross-hatched, the following number of different rectangles could be
  3947.    situated within those smaller grids:
  3948.  
  3949.    1x1: 1
  3950.    2x1: 4
  3951.    3x1: 8
  3952.    1x2: 4
  3953.    2x2: 18
  3954.  
  3955.    Adding those to the 37 of the 3x2 grid, a total of 72 different rectangles
  3956.    could be situated within 3x2 and smaller grids.
  3957.  
  3958.    How many different rectangles could be situated within 47x43 and smaller
  3959.    grids?
  3960.  
  3961.    
  3962.    p_147.gif
  3963.    Answer: d0fca7d85d4a4df043a2ae5772ea472e
  3964.  
  3965.  
  3966. Problem 148
  3967. ===========
  3968.  
  3969.  
  3970.    We can easily verify that none of the entries in the first seven rows of
  3971.    Pascal's triangle are divisible by 7:
  3972.  
  3973.                                        1
  3974.                                     1     1
  3975.                                  1     2     1
  3976.                               1     3     3     1
  3977.                            1     4     6     4     1
  3978.                         1     5    10    10     5     1
  3979.                      1     6    15    20    15     6     1
  3980.  
  3981.    However, if we check the first one hundred rows, we will find that only
  3982.    2361 of the 5050 entries are not divisible by 7.
  3983.  
  3984.    Find the number of entries which are not divisible by 7 in the first one
  3985.    billion (10^9) rows of Pascal's triangle.
  3986.  
  3987.    
  3988.    Answer: 8a631ab4e3d06baf88299bf4e501b837
  3989.  
  3990.  
  3991. Problem 149
  3992. ===========
  3993.  
  3994.  
  3995.    Looking at the table below, it is easy to verify that the maximum possible
  3996.    sum of adjacent numbers in any direction (horizontal, vertical, diagonal
  3997.    or anti-diagonal) is 16 (= 8 + 7 + 1).
  3998.  
  3999.                              ┌────┬────┬────┬─────┐
  4000.                              │ −2 │ 5  │ 3  │ 2   │
  4001.                              ├────┼────┼────┼─────┤
  4002.                              │ 9  │ −6 │ 5  │ 1   │
  4003.                              ├────┼────┼────┼─────┤
  4004.                              │ 3  │ 2  │ 7  │ 3   │
  4005.                              ├────┼────┼────┼─────┤
  4006.                              │ −1 │ 8  │ −4 │   8 │
  4007.                              └────┴────┴────┴─────┘
  4008.  
  4009.    Now, let us repeat the search, but on a much larger scale:
  4010.  
  4011.    First, generate four million pseudo-random numbers using a specific form
  4012.    of what is known as a "Lagged Fibonacci Generator":
  4013.  
  4014.    For 1 ≤ k ≤ 55, s[k] = [100003 − 200003k + 300007k^3] (modulo 1000000) −
  4015.    500000.
  4016.    For 56 ≤ k ≤ 4000000, s[k] = [s[k−24] + s[k−55] + 1000000] (modulo
  4017.    1000000) − 500000.
  4018.  
  4019.    Thus, s[10] = −393027 and s[100] = 86613.
  4020.  
  4021.    The terms of s are then arranged in a 2000×2000 table, using the first
  4022.    2000 numbers to fill the first row (sequentially), the next 2000 numbers
  4023.    to fill the second row, and so on.
  4024.  
  4025.    Finally, find the greatest sum of (any number of) adjacent entries in any
  4026.    direction (horizontal, vertical, diagonal or anti-diagonal).
  4027.  
  4028.    
  4029.    Answer: 52852124
  4030.  
  4031.  
  4032. Problem 150
  4033. ===========
  4034.  
  4035.  
  4036.    In a triangular array of positive and negative integers, we wish to find a
  4037.    sub-triangle such that the sum of the numbers it contains is the smallest
  4038.    possible.
  4039.  
  4040.    In the example below, it can be easily verified that the marked triangle
  4041.    satisfies this condition having a sum of −42.
  4042.  
  4043.    We wish to make such a triangular array with one thousand rows, so we
  4044.    generate 500500 pseudo-random numbers s[k] in the range ±2^19, using a
  4045.    type of random number generator (known as a Linear Congruential Generator)
  4046.    as follows:
  4047.  
  4048.    t := 0
  4049.    for k = 1 up to k = 500500:
  4050.        t := (615949*t + 797807) modulo 2^20
  4051.        s[k] := t−2^19
  4052.  
  4053.    Thus: s[1] = 273519, s[2] = −153582, s[3] = 450905 etc
  4054.  
  4055.    Our triangular array is then formed using the pseudo-random numbers thus:
  4056.  
  4057.                                       s[1]
  4058.                                    s[2]  s[3]
  4059.                                s[4]  s[5]  s[6] 
  4060.                             s[7]  s[8]  s[9]  s[10]
  4061.                                       ...
  4062.  
  4063.    Sub-triangles can start at any element of the array and extend down as far
  4064.    as we like (taking-in the two elements directly below it from the next
  4065.    row, the three elements directly below from the row after that, and so
  4066.    on).
  4067.    The "sum of a sub-triangle" is defined as the sum of all the elements it
  4068.    contains.
  4069.    Find the smallest possible sub-triangle sum.
  4070.  
  4071.    
  4072.    p_150.gif
  4073.    Answer: 1802939e514020769701c59b422c0498
  4074.  
  4075.  
  4076. Problem 151
  4077. ===========
  4078.  
  4079.  
  4080.    A printing shop runs 16 batches (jobs) every week and each batch requires
  4081.    a sheet of special colour-proofing paper of size A5.
  4082.  
  4083.    Every Monday morning, the foreman opens a new envelope, containing a large
  4084.    sheet of the special paper with size A1.
  4085.  
  4086.    He proceeds to cut it in half, thus getting two sheets of size A2. Then he
  4087.    cuts one of them in half to get two sheets of size A3 and so on until he
  4088.    obtains the A5-size sheet needed for the first batch of the week.
  4089.  
  4090.    All the unused sheets are placed back in the envelope.
  4091.  
  4092.    At the beginning of each subsequent batch, he takes from the envelope one
  4093.    sheet of paper at random. If it is of size A5, he uses it. If it is
  4094.    larger, he repeats the 'cut-in-half' procedure until he has what he needs
  4095.    and any remaining sheets are always placed back in the envelope.
  4096.  
  4097.    Excluding the first and last batch of the week, find the expected number
  4098.    of times (during each week) that the foreman finds a single sheet of paper
  4099.    in the envelope.
  4100.  
  4101.    Give your answer rounded to six decimal places using the format x.xxxxxx .
  4102.  
  4103.    
  4104.    p_151.gif
  4105.    Answer: 0.464399
  4106.  
  4107.  
  4108. Problem 152
  4109. ===========
  4110.  
  4111.  
  4112.    There are several ways to write the number 1/2 as a sum of inverse squares
  4113.    using distinct integers.
  4114.  
  4115.    For instance, the numbers {2,3,4,5,7,12,15,20,28,35} can be used:
  4116.  
  4117.    In fact, only using integers between 2 and 45 inclusive, there are exactly
  4118.    three ways to do it, the remaining two being:
  4119.    {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}.
  4120.  
  4121.    How many ways are there to write the number 1/2 as a sum of inverse
  4122.    squares using distinct integers between 2 and 80 inclusive?
  4123.  
  4124.    
  4125.    p_152_sum.gif
  4126.    Answer: 301
  4127.  
  4128.  
  4129. Problem 153
  4130. ===========
  4131.  
  4132.  
  4133.    As we all know the equation x^2=-1 has no solutions for real x.
  4134.    If we however introduce the imaginary number i this equation has two
  4135.    solutions: x=i and x=-i.
  4136.    If we go a step further the equation (x-3)^2=-4 has two complex solutions:
  4137.    x=3+2i and x=3-2i.
  4138.    x=3+2i and x=3-2i are called each others' complex conjugate.
  4139.    Numbers of the form a+bi are called complex numbers.
  4140.    In general a+bi and a−bi are each other's complex conjugate.
  4141.  
  4142.    A Gaussian Integer is a complex number a+bi such that both a and b are
  4143.    integers.
  4144.    The regular integers are also Gaussian integers (with b=0).
  4145.    To distinguish them from Gaussian integers with b ≠ 0 we call such
  4146.    integers "rational integers."
  4147.    A Gaussian integer is called a divisor of a rational integer n if the
  4148.    result is also a Gaussian integer.
  4149.    If for example we divide 5 by 1+2i we can simplify in the following
  4150.    manner:
  4151.    Multiply numerator and denominator by the complex conjugate of 1+2i: 1−2i.
  4152.    The result is .
  4153.    So 1+2i is a divisor of 5.
  4154.    Note that 1+i is not a divisor of 5 because .
  4155.    Note also that if the Gaussian Integer (a+bi) is a divisor of a rational
  4156.    integer n, then its complex conjugate (a−bi) is also a divisor of n.
  4157.  
  4158.    In fact, 5 has six divisors such that the real part is positive: {1, 1 +
  4159.    2i, 1 − 2i, 2 + i, 2 − i, 5}.
  4160.    The following is a table of all of the divisors for the first five
  4161.    positive rational integers:
  4162.  
  4163.               ┌───┬──────────────────────────────┬───────────────┐
  4164.               │ n │ Gaussian integer divisors    │ Sum s(n) of   │
  4165.               │   │ with positive real part      │ thesedivisors │
  4166.               ├───┼──────────────────────────────┼───────────────┤
  4167.               │ 1 │ 1                            │ 1             │
  4168.               ├───┼──────────────────────────────┼───────────────┤
  4169.               │ 2 │ 1, 1+i, 1-i, 2               │ 5             │
  4170.               ├───┼──────────────────────────────┼───────────────┤
  4171.               │ 3 │ 1, 3                         │ 4             │
  4172.               ├───┼──────────────────────────────┼───────────────┤
  4173.               │ 4 │ 1, 1+i, 1-i, 2, 2+2i, 2-2i,4 │ 13            │
  4174.               ├───┼──────────────────────────────┼───────────────┤
  4175.               │ 5 │ 1, 1+2i, 1-2i, 2+i, 2-i, 5   │ 12            │
  4176.               └───┴──────────────────────────────┴───────────────┘
  4177.  
  4178.    For divisors with positive real parts, then, we have: .
  4179.  
  4180.    For 1 ≤ n ≤ 10^5, ∑ s(n)=17924657155.
  4181.  
  4182.    What is ∑ s(n) for 1 ≤ n ≤ 10^8?
  4183.  
  4184.    
  4185.    p_153_formule1.gif
  4186.    p_153_formule2.gif
  4187.    p_153_formule5.gif
  4188.    p_153_formule6.gif
  4189.    Answer: 08ec9d6e6c2275d37e7a227fb2d1f06f
  4190.  
  4191.  
  4192. Problem 154
  4193. ===========
  4194.  
  4195.  
  4196.    A triangular pyramid is constructed using spherical balls so that each
  4197.    ball rests on exactly three balls of the next lower level.
  4198.  
  4199.    Then, we calculate the number of paths leading from the apex to each
  4200.    position:
  4201.  
  4202.    A path starts at the apex and progresses downwards to any of the three
  4203.    spheres directly below the current position.
  4204.  
  4205.    Consequently, the number of paths to reach a certain position is the sum
  4206.    of the numbers immediately above it (depending on the position, there are
  4207.    up to three numbers above it).
  4208.  
  4209.    The result is Pascal's pyramid and the numbers at each level n are the
  4210.    coefficients of the trinomial expansion (x + y + z)^n.
  4211.  
  4212.    How many coefficients in the expansion of (x + y + z)^200000 are multiples
  4213.    of 10^12?
  4214.  
  4215.    
  4216.    p_154_pyramid.gif
  4217.    Answer: de866633fa075beb3897cbbc8abf2400
  4218.  
  4219.  
  4220. Problem 155
  4221. ===========
  4222.  
  4223.  
  4224.    An electric circuit uses exclusively identical capacitors of the same
  4225.    value C.
  4226.    The capacitors can be connected in series or in parallel to form
  4227.    sub-units, which can then be connected in series or in parallel with other
  4228.    capacitors or other sub-units to form larger sub-units, and so on up to a
  4229.    final circuit.
  4230.  
  4231.    Using this simple procedure and up to n identical capacitors, we can make
  4232.    circuits having a range of different total capacitances. For example,
  4233.    using up to n=3 capacitors of 60 F each, we can obtain the following 7
  4234.    distinct total capacitance values:
  4235.  
  4236.    If we denote by D(n) the number of distinct total capacitance values we
  4237.    can obtain when using up to n equal-valued capacitors and the simple
  4238.    procedure described above, we have: D(1)=1, D(2)=3, D(3)=7 ...
  4239.  
  4240.    Find D(18).
  4241.  
  4242.    Reminder : When connecting capacitors C[1], C[2] etc in parallel, the
  4243.    total capacitance is C[T] = C[1] + C[2] +...,
  4244.    whereas when connecting them in series, the overall capacitance is given
  4245.    by:
  4246.  
  4247.    
  4248.    p_155_capsmu.gif
  4249.    p_155_capacitors1.gif
  4250.    p_155_capsform.gif
  4251.    Answer: 3857447
  4252.  
  4253.  
  4254. Problem 156
  4255. ===========
  4256.  
  4257.  
  4258.    Starting from zero the natural numbers are written down in base 10 like
  4259.    this:
  4260.    0 1 2 3 4 5 6 7 8 9 10 11 12....
  4261.  
  4262.    Consider the digit d=1. After we write down each number n, we will update
  4263.    the number of ones that have occurred and call this number f(n,1). The
  4264.    first values for f(n,1), then, are as follows:
  4265.  
  4266.                                    n  f(n,1)
  4267.                                    0  0
  4268.                                    1  1
  4269.                                    2  1
  4270.                                    3  1
  4271.                                    4  1
  4272.                                    5  1
  4273.                                    6  1
  4274.                                    7  1
  4275.                                    8  1
  4276.                                    9  1
  4277.                                    10 2
  4278.                                    11 4
  4279.                                    12 5
  4280.  
  4281.    Note that f(n,1) never equals 3.
  4282.    So the first two solutions of the equation f(n,1)=n are n=0 and n=1. The
  4283.    next solution is n=199981.
  4284.  
  4285.    In the same manner the function f(n,d) gives the total number of digits d
  4286.    that have been written down after the number n has been written.
  4287.    In fact, for every digit d ≠ 0, 0 is the first solution of the equation
  4288.    f(n,d)=n.
  4289.  
  4290.    Let s(d) be the sum of all the solutions for which f(n,d)=n.
  4291.    You are given that s(1)=22786974071.
  4292.  
  4293.    Find ∑ s(d) for 1 ≤ d ≤ 9.
  4294.  
  4295.    Note: if, for some n, f(n,d)=n for more than one value of d this value of
  4296.    n is counted again for every value of d for which f(n,d)=n.
  4297.  
  4298.    
  4299.    Answer: ac0c6b67ed28cebb02b802e7a204aaee
  4300.  
  4301.  
  4302. Problem 157
  4303. ===========
  4304.  
  4305.  
  4306.    Consider the diophantine equation ^1/[a]+^1/[b]= ^p/[10^n] with a, b, p, n
  4307.    positive integers and a ≤ b.
  4308.    For n=1 this equation has 20 solutions that are listed below:
  4309.  
  4310. 1/1+1/1=20/10   1/1+1/2=15/10  1/1+1/5=12/10  1/1+1/10=11/10 1/2+1/2=10/10
  4311. 1/2+1/5=7/10    1/2+1/10=6/10  1/3+1/6=5/10   1/3+1/15=4/10  1/4+1/4=5/10
  4312. 1/4+1/20=3/10   1/5+1/5=4/10   1/5+1/10=3/10  1/6+1/30=2/10  1/10+1/10=2/10
  4313. 1/11+1/110=1/10 1/12+1/60=1/10 1/14+1/35=1/10 1/15+1/30=1/10 1/20+1/20=1/10
  4314.  
  4315.    How many solutions has this equation for 1 ≤ n ≤ 9?
  4316.  
  4317.    
  4318.    Answer: 53490
  4319.  
  4320.  
  4321. Problem 158
  4322. ===========
  4323.  
  4324.  
  4325.    Taking three different letters from the 26 letters of the alphabet,
  4326.    character strings of length three can be formed.
  4327.    Examples are 'abc', 'hat' and 'zyx'.
  4328.    When we study these three examples we see that for 'abc' two characters
  4329.    come lexicographically after its neighbour to the left.
  4330.    For 'hat' there is exactly one character that comes lexicographically
  4331.    after its neighbour to the left. For 'zyx' there are zero characters that
  4332.    come lexicographically after its neighbour to the left.
  4333.    In all there are 10400 strings of length 3 for which exactly one character
  4334.    comes lexicographically after its neighbour to the left.
  4335.  
  4336.    We now consider strings of n ≤ 26 different characters from the alphabet.
  4337.    For every n, p(n) is the number of strings of length n for which exactly
  4338.    one character comes lexicographically after its neighbour to the left.
  4339.  
  4340.    What is the maximum value of p(n)?
  4341.  
  4342.    
  4343.    Answer: 6070fa194890e52b2989af5b542aee90
  4344.  
  4345.  
  4346. Problem 159
  4347. ===========
  4348.  
  4349.  
  4350.    A composite number can be factored many different ways. For instance, not
  4351.    including multiplication by one, 24 can be factored in 7 distinct ways:
  4352.  
  4353.    24 = 2x2x2x3
  4354.    24 = 2x3x4
  4355.    24 = 2x2x6
  4356.    24 = 4x6
  4357.    24 = 3x8
  4358.    24 = 2x12
  4359.    24 = 24
  4360.  
  4361.    Recall that the digital root of a number, in base 10, is found by adding
  4362.    together the digits of that number, and repeating that process until a
  4363.    number is arrived at that is less than 10. Thus the digital root of 467 is
  4364.    8.
  4365.  
  4366.    We shall call a Digital Root Sum (DRS) the sum of the digital roots of the
  4367.    individual factors of our number.
  4368.    The chart below demonstrates all of the DRS values for 24.
  4369.  
  4370.                         ┌─────────────┬────────────────┐
  4371.                         │Factorisation│Digital Root Sum│
  4372.                         ├─────────────┼────────────────┤
  4373.                         │2x2x2x3      │       9        │
  4374.                         ├─────────────┼────────────────┤
  4375.                         │2x3x4        │       9        │
  4376.                         ├─────────────┼────────────────┤
  4377.                         │2x2x6        │       10       │
  4378.                         ├─────────────┼────────────────┤
  4379.                         │4x6          │       10       │
  4380.                         ├─────────────┼────────────────┤
  4381.                         │3x8          │       11       │
  4382.                         ├─────────────┼────────────────┤
  4383.                         │2x12         │       5        │
  4384.                         ├─────────────┼────────────────┤
  4385.                         │24           │       6        │
  4386.                         └─────────────┴────────────────┘
  4387.  
  4388.    The maximum Digital Root Sum of 24 is 11.
  4389.    The function mdrs(n) gives the maximum Digital Root Sum of n. So
  4390.    mdrs(24)=11.
  4391.    Find ∑mdrs(n) for 1 < n < 1,000,000.
  4392.  
  4393.    
  4394.    Answer: 14489159
  4395.  
  4396.  
  4397. Problem 160
  4398. ===========
  4399.  
  4400.  
  4401.    For any N, let f(N) be the last five digits before the trailing zeroes in
  4402.    N!.
  4403.    For example,
  4404.  
  4405.    9! = 362880 so f(9)=36288
  4406.    10! = 3628800 so f(10)=36288
  4407.    20! = 2432902008176640000 so f(20)=17664
  4408.  
  4409.    Find f(1,000,000,000,000)
  4410.  
  4411.    
  4412.    Answer: 16576
  4413.  
  4414.  
  4415. Problem 161
  4416. ===========
  4417.  
  4418.  
  4419.    A triomino is a shape consisting of three squares joined via the
  4420.    edges.There are two basic forms:
  4421.  
  4422.    If all possible orientations are taken into account there are six:
  4423.  
  4424.    Any n by m grid for which nxm is divisible by 3 can be tiled with
  4425.    triominoes.
  4426.    If we consider tilings that can be obtained by reflection or rotation from
  4427.    another tiling as different there are 41 ways a 2 by 9 grid can be tiled
  4428.    with triominoes:
  4429.  
  4430.    In how many ways can a 9 by 12 grid be tiled in this way by triominoes?
  4431.  
  4432.    
  4433.    p_161_trio1.gif
  4434.    p_161_trio3.gif
  4435.    p_161_k9.gif
  4436.    Answer: 975ccc38bb5402c5b485f3de5928d919
  4437.  
  4438.  
  4439. Problem 162
  4440. ===========
  4441.  
  4442.  
  4443.    In the hexadecimal number system numbers are represented using 16
  4444.    different digits:
  4445.  
  4446.                         0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
  4447.  
  4448.    The hexadecimal number AF when written in the decimal number system equals
  4449.    10x16+15=175.
  4450.  
  4451.    In the 3-digit hexadecimal numbers 10A, 1A0, A10, and A01 the digits 0,1
  4452.    and A are all present.
  4453.    Like numbers written in base ten we write hexadecimal numbers without
  4454.    leading zeroes.
  4455.  
  4456.    How many hexadecimal numbers containing at most sixteen hexadecimal digits
  4457.    exist with all of the digits 0,1, and A present at least once?
  4458.    Give your answer as a hexadecimal number.
  4459.  
  4460.    (A,B,C,D,E and F in upper case, without any leading or trailing code that
  4461.    marks the number as hexadecimal and without leading zeroes , e.g. 1A3F and
  4462.    not: 1a3f and not 0x1a3f and not $1A3F and not #1A3F and not 0000001A3F)
  4463.  
  4464.    
  4465.    Answer: 049419b9fdad9af74d5888626fff56a3
  4466.  
  4467.  
  4468. Problem 163
  4469. ===========
  4470.  
  4471.  
  4472.    Consider an equilateral triangle in which straight lines are drawn from
  4473.    each vertex to the middle of the opposite side, such as in the size 1
  4474.    triangle in the sketch below.
  4475.  
  4476.    Sixteen triangles of either different shape or size or orientation or
  4477.    location can now be observed in that triangle. Using size 1 triangles as
  4478.    building blocks, larger triangles can be formed, such as the size 2
  4479.    triangle in the above sketch. One-hundred and four triangles of either
  4480.    different shape or size or orientation or location can now be observed in
  4481.    that size 2 triangle.
  4482.  
  4483.    It can be observed that the size 2 triangle contains 4 size 1 triangle
  4484.    building blocks. A size 3 triangle would contain 9 size 1 triangle
  4485.    building blocks and a size n triangle would thus contain n^2 size 1
  4486.    triangle building blocks.
  4487.  
  4488.    If we denote T(n) as the number of triangles present in a triangle of size
  4489.    n, then
  4490.  
  4491.    T(1) = 16
  4492.    T(2) = 104
  4493.  
  4494.    Find T(36).
  4495.  
  4496.    
  4497.    p_163.gif
  4498.    Answer: 343047
  4499.  
  4500.  
  4501. Problem 164
  4502. ===========
  4503.  
  4504.  
  4505.    How many 20 digit numbers n (without any leading zero) exist such that no
  4506.    three consecutive digits of n have a sum greater than 9?
  4507.  
  4508.    
  4509.    Answer: 6e96debf3bfe7cc132401bafe5a5d6d6
  4510.  
  4511.  
  4512. Problem 165
  4513. ===========
  4514.  
  4515.  
  4516.    A segment is uniquely defined by its two endpoints.
  4517.    By considering two line segments in plane geometry there are three
  4518.    possibilities:
  4519.    the segments have zero points, one point, or infinitely many points in
  4520.    common.
  4521.  
  4522.    Moreover when two segments have exactly one point in common it might be
  4523.    the case that that common point is an endpoint of either one of the
  4524.    segments or of both. If a common point of two segments is not an endpoint
  4525.    of either of the segments it is an interior point of both segments.
  4526.    We will call a common point T of two segments L[1] and L[2] a true
  4527.    intersection point of L[1] and L[2] if T is the only common point of L[1]
  4528.    and L[2] and T is an interior point of both segments.
  4529.  
  4530.    Consider the three segments L[1], L[2], and L[3]:
  4531.  
  4532.    L[1]: (27, 44) to (12, 32)
  4533.    L[2]: (46, 53) to (17, 62)
  4534.    L[3]: (46, 70) to (22, 40)
  4535.  
  4536.    It can be verified that line segments L[2] and L[3] have a true
  4537.    intersection point. We note that as the one of the end points of L[3]:
  4538.    (22,40) lies on L[1] this is not considered to be a true point of
  4539.    intersection. L[1] and L[2] have no common point. So among the three line
  4540.    segments, we find one true intersection point.
  4541.  
  4542.    Now let us do the same for 5000 line segments. To this end, we generate
  4543.    20000 numbers using the so-called "Blum Blum Shub" pseudo-random number
  4544.    generator.
  4545.  
  4546.    s[0] = 290797
  4547.  
  4548.    s[n+1] = s[n]×s[n] (modulo 50515093)
  4549.  
  4550.    t[n] = s[n] (modulo 500)
  4551.  
  4552.    To create each line segment, we use four consecutive numbers t[n]. That
  4553.    is, the first line segment is given by:
  4554.  
  4555.    (t[1], t[2]) to (t[3], t[4])
  4556.  
  4557.    The first four numbers computed according to the above generator should
  4558.    be: 27, 144, 12 and 232. The first segment would thus be (27,144) to
  4559.    (12,232).
  4560.  
  4561.    How many distinct true intersection points are found among the 5000 line
  4562.    segments?
  4563.  
  4564.    
  4565.    Answer: 2868868
  4566.  
  4567.  
  4568. Problem 166
  4569. ===========
  4570.  
  4571.  
  4572.    A 4x4 grid is filled with digits d, 0 ≤ d ≤ 9.
  4573.  
  4574.    It can be seen that in the grid
  4575.  
  4576.                                     6 3 3 0
  4577.                                     5 0 4 3
  4578.                                     0 7 1 4
  4579.                                     1 2 4 5
  4580.  
  4581.    the sum of each row and each column has the value 12. Moreover the sum of
  4582.    each diagonal is also 12.
  4583.  
  4584.    In how many ways can you fill a 4x4 grid with the digits d, 0 ≤ d ≤ 9 so
  4585.    that each row, each column, and both diagonals have the same sum?
  4586.  
  4587.    
  4588.    Answer: 7130034
  4589.  
  4590.  
  4591. Problem 167
  4592. ===========
  4593.  
  4594.  
  4595.    For two positive integers a and b, the Ulam sequence U(a,b) is defined by
  4596.    U(a,b)[1] = a, U(a,b)[2] = b and for k > 2,U(a,b)[k] is the smallest
  4597.    integer greater than U(a,b)[(k-1)] which can be written in exactly one way
  4598.    as the sum of two distinct previous members of U(a,b).
  4599.  
  4600.    For example, the sequence U(1,2) begins with
  4601.    1, 2, 3 = 1 + 2, 4 = 1 + 3, 6 = 2 + 4, 8 = 2 + 6, 11 = 3 + 8;
  4602.    5 does not belong to it because 5 = 1 + 4 = 2 + 3 has two representations
  4603.    as the sum of two previous members, likewise 7 = 1 + 6 = 3 + 4.
  4604.  
  4605.    Find ∑U(2,2n+1)[k] for 2 ≤ n ≤10, where k = 10^11.
  4606.  
  4607.    
  4608.    Answer: aa5b61f6f4d96cbaeb5944b8fcdf64a3
  4609.  
  4610.  
  4611. Problem 168
  4612. ===========
  4613.  
  4614.  
  4615.    Consider the number 142857. We can right-rotate this number by moving the
  4616.    last digit (7) to the front of it, giving us 714285.
  4617.    It can be verified that 714285=5×142857.
  4618.    This demonstrates an unusual property of 142857: it is a divisor of its
  4619.    right-rotation.
  4620.  
  4621.    Find the last 5 digits of the sum of all integers n, 10 < n < 10^100, that
  4622.    have this property.
  4623.  
  4624.    
  4625.    Answer: 59206
  4626.  
  4627.  
  4628. Problem 169
  4629. ===========
  4630.  
  4631.  
  4632.    Define f(0)=1 and f(n) to be the number of different ways n can be
  4633.    expressed as a sum of integer powers of 2 using each power no more than
  4634.    twice.
  4635.  
  4636.    For example, f(10)=5 since there are five different ways to express 10:
  4637.  
  4638.    1 + 1 + 8
  4639.    1 + 1 + 4 + 4
  4640.    1 + 1 + 2 + 2 + 4
  4641.    2 + 4 + 4
  4642.    2 + 8
  4643.  
  4644.    What is f(10^25)?
  4645.  
  4646.    
  4647.    Answer: d149d4836703a8908becea56ddd3ed42
  4648.  
  4649.  
  4650. Problem 170
  4651. ===========
  4652.  
  4653.  
  4654.    Take the number 6 and multiply it by each of 1273 and 9854:
  4655.  
  4656.    6 × 1273 = 7638
  4657.    6 × 9854 = 59124
  4658.  
  4659.    By concatenating these products we get the 1 to 9 pandigital 763859124. We
  4660.    will call 763859124 the "concatenated product of 6 and (1273,9854)".
  4661.    Notice too, that the concatenation of the input numbers, 612739854, is
  4662.    also 1 to 9 pandigital.
  4663.  
  4664.    The same can be done for 0 to 9 pandigital numbers.
  4665.  
  4666.    What is the largest 0 to 9 pandigital 10-digit concatenated product of an
  4667.    integer with two or more other integers, such that the concatenation of
  4668.    the input numbers is also a 0 to 9 pandigital 10-digit number?
  4669.  
  4670.    
  4671.    Answer: 6ffe65352f717c1731666a107ace96c1
  4672.  
  4673.  
  4674. Problem 171
  4675. ===========
  4676.  
  4677.  
  4678.    For a positive integer n, let f(n) be the sum of the squares of the digits
  4679.    (in base 10) of n, e.g.
  4680.  
  4681.    f(3) = 3^2 = 9,
  4682.    f(25) = 2^2 + 5^2 = 4 + 25 = 29,
  4683.    f(442) = 4^2 + 4^2 + 2^2 = 16 + 16 + 4 = 36
  4684.  
  4685.    Find the last nine digits of the sum of all n, 0 < n < 10^20, such that
  4686.    f(n) is a perfect square.
  4687.  
  4688.    
  4689.    Answer: 142989277
  4690.  
  4691.  
  4692. Problem 172
  4693. ===========
  4694.  
  4695.  
  4696.    How many 18-digit numbers n (without leading zeros) are there such that no
  4697.    digit occurs more than three times in n?
  4698.  
  4699.    
  4700.    Answer: f5f260ee21ead7478403c2ccd18a1829
  4701.  
  4702.  
  4703. Problem 173
  4704. ===========
  4705.  
  4706.  
  4707.    We shall define a square lamina to be a square outline with a square
  4708.    "hole" so that the shape possesses vertical and horizontal symmetry. For
  4709.    example, using exactly thirty-two square tiles we can form two different
  4710.    square laminae:
  4711.  
  4712.    With one-hundred tiles, and not necessarily using all of the tiles at one
  4713.    time, it is possible to form forty-one different square laminae.
  4714.  
  4715.    Using up to one million tiles how many different square laminae can be
  4716.    formed?
  4717.  
  4718.    
  4719.    p_173_square_laminas.gif
  4720.    Answer: 1572729
  4721.  
  4722.  
  4723. Problem 174
  4724. ===========
  4725.  
  4726.  
  4727.    We shall define a square lamina to be a square outline with a square
  4728.    "hole" so that the shape possesses vertical and horizontal symmetry.
  4729.  
  4730.    Given eight tiles it is possible to form a lamina in only one way: 3x3
  4731.    square with a 1x1 hole in the middle. However, using thirty-two tiles it
  4732.    is possible to form two distinct laminae.
  4733.  
  4734.    If t represents the number of tiles used, we shall say that t = 8 is type
  4735.    L(1) and t = 32 is type L(2).
  4736.  
  4737.    Let N(n) be the number of t ≤ 1000000 such that t is type L(n); for
  4738.    example, N(15) = 832.
  4739.  
  4740.    What is ∑ N(n) for 1 ≤ n ≤ 10?
  4741.  
  4742.    
  4743.    p_173_square_laminas.gif
  4744.    Answer: 209566
  4745.  
  4746.  
  4747. Problem 175
  4748. ===========
  4749.  
  4750.    Define f(0)=1 and f(n) to be the number of ways to write n as a sum of
  4751.    powers of 2 where no power occurs more than twice.
  4752.  
  4753.    For example, f(10)=5 since there are five different ways to express 10:
  4754.    10 = 8+2 = 8+1+1 = 4+4+2 = 4+2+2+1+1 = 4+4+1+1
  4755.  
  4756.    It can be shown that for every fraction p/q (p>0, q>0) there exists at
  4757.    least one integer n such that
  4758.    f(n)/f(n-1)=p/q.
  4759.  
  4760.    For instance, the smallest n for which f(n)/f(n-1)=13/17 is 241.
  4761.    The binary expansion of 241 is 11110001.
  4762.    Reading this binary number from the most significant bit to the least
  4763.    significant bit there are 4 one's, 3 zeroes and 1 one. We shall call the
  4764.    string 4,3,1 the Shortened Binary Expansion of 241.
  4765.  
  4766.    Find the Shortened Binary Expansion of the smallest n for which
  4767.    f(n)/f(n-1)=123456789/987654321.
  4768.  
  4769.    Give your answer as comma separated integers, without any whitespaces.
  4770.    
  4771.    Answer: 796dddd004c3465229058072f5b4583e
  4772.  
  4773.  
  4774. Problem 176
  4775. ===========
  4776.  
  4777.  
  4778.    The four right-angled triangles with sides (9,12,15), (12,16,20),
  4779.    (5,12,13) and (12,35,37) all have one of the shorter sides (catheti) equal
  4780.    to 12. It can be shown that no other integer sided right-angled triangle
  4781.    exists with one of the catheti equal to 12.
  4782.  
  4783.    Find the smallest integer that can be the length of a cathetus of exactly
  4784.    47547 different integer sided right-angled triangles.
  4785.  
  4786.    
  4787.    Answer: c47c782ebaf8cdbb60eebfa86cd0003c
  4788.  
  4789.  
  4790. Problem 177
  4791. ===========
  4792.  
  4793.  
  4794.    Let ABCD be a convex quadrilateral, with diagonals AC and BD. At each
  4795.    vertex the diagonal makes an angle with each of the two sides, creating
  4796.    eight corner angles.
  4797.  
  4798.    For example, at vertex A, the two angles are CAD, CAB.
  4799.  
  4800.    We call such a quadrilateral for which all eight corner angles have
  4801.    integer values when measured in degrees an "integer angled quadrilateral".
  4802.    An example of an integer angled quadrilateral is a square, where all eight
  4803.    corner angles are 45°. Another example is given by DAC = 20°, BAC = 60°,
  4804.    ABD = 50°, CBD = 30°, BCA = 40°, DCA = 30°, CDB = 80°, ADB = 50°.
  4805.  
  4806.    What is the total number of non-similar integer angled quadrilaterals?
  4807.  
  4808.    Note: In your calculations you may assume that a calculated angle is
  4809.    integral if it is within a tolerance of 10^-9 of an integer value.
  4810.  
  4811.    
  4812.    p_177_quad.gif
  4813.    Answer: 129325
  4814.  
  4815.  
  4816. Problem 178
  4817. ===========
  4818.  
  4819.    Consider the number 45656.
  4820.    It can be seen that each pair of consecutive digits of 45656 has a
  4821.    difference of one.
  4822.    A number for which every pair of consecutive digits has a difference of
  4823.    one is called a step number.
  4824.    A pandigital number contains every decimal digit from 0 to 9 at least
  4825.    once.
  4826.    How many pandigital step numbers less than 10^40 are there?
  4827.    
  4828.    Answer: 2ffddfa898fa5df6321aebea84d4f33f
  4829.  
  4830.  
  4831. Problem 179
  4832. ===========
  4833.  
  4834.  
  4835.    Find the number of integers 1 < n < 10^7, for which n and n + 1 have the
  4836.    same number of positive divisors. For example, 14 has the positive
  4837.    divisors 1, 2, 7, 14 while 15 has 1, 3, 5, 15.
  4838.  
  4839.    
  4840.    Answer: 986262
  4841.  
  4842.  
  4843. Problem 180
  4844. ===========
  4845.  
  4846.  
  4847.    For any integer n, consider the three functions
  4848.  
  4849.    f[1,n](x,y,z) = x^n+1 + y^n+1 − z^n+1
  4850.    f[2,n](x,y,z) = (xy + yz + zx)*(x^n-1 + y^n-1 − z^n-1)
  4851.    f[3,n](x,y,z) = xyz*(x^n-2 + y^n-2 − z^n-2)
  4852.  
  4853.    and their combination
  4854.  
  4855.    f[n](x,y,z) = f[1,n](x,y,z) + f[2,n](x,y,z) − f[3,n](x,y,z)
  4856.  
  4857.    We call (x,y,z) a golden triple of order k if x, y, and z are all rational
  4858.    numbers of the form a / b with
  4859.    0 < a < b ≤ k and there is (at least) one integer n, so that f[n](x,y,z) =
  4860.    0.
  4861.  
  4862.    Let s(x,y,z) = x + y + z.
  4863.    Let t = u / v be the sum of all distinct s(x,y,z) for all golden triples
  4864.    (x,y,z) of order 35.
  4865.    All the s(x,y,z) and t must be in reduced form.
  4866.  
  4867.    Find u + v.
  4868.  
  4869.    
  4870.    Answer: 6459f69d151314c59df404868f45fa96
  4871.  
  4872.  
  4873. Problem 181
  4874. ===========
  4875.  
  4876.  
  4877.    Having three black objects B and one white object W they can be grouped in
  4878.    7 ways like this:
  4879.  
  4880.         (BBBW)  (B,BBW)  (B,B,BW)  (B,B,B,W)  (B,BB,W)  (BBB,W)  (BB,BW)
  4881.  
  4882.    In how many ways can sixty black objects B and forty white objects W be
  4883.    thus grouped?
  4884.  
  4885.    
  4886.    Answer: 0e1233ecbc058dabf54a8602eac55d95
  4887.  
  4888.  
  4889. Problem 182
  4890. ===========
  4891.  
  4892.  
  4893.    The RSA encryption is based on the following procedure:
  4894.  
  4895.    Generate two distinct primes p and q.
  4896.    Compute n=pq and φ=(p-1)(q-1).
  4897.    Find an integer e, 1<e<φ, such that gcd(e,φ)=1.
  4898.  
  4899.    A message in this system is a number in the interval [0,n-1].
  4900.    A text to be encrypted is then somehow converted to messages (numbers in
  4901.    the interval [0,n-1]).
  4902.    To encrypt the text, for each message, m, c=m^e mod n is calculated.
  4903.  
  4904.    To decrypt the text, the following procedure is needed: calculate d such
  4905.    that ed=1 mod φ, then for each encrypted message, c, calculate m=c^d mod
  4906.    n.
  4907.  
  4908.    There exist values of e and m such that m^e mod n=m.
  4909.    We call messages m for which m^e mod n=m unconcealed messages.
  4910.  
  4911.    An issue when choosing e is that there should not be too many unconcealed
  4912.    messages.
  4913.    For instance, let p=19 and q=37.
  4914.    Then n=19*37=703 and φ=18*36=648.
  4915.    If we choose e=181, then, although gcd(181,648)=1 it turns out that all
  4916.    possible messages
  4917.    m (0≤m≤n-1) are unconcealed when calculating m^e mod n.
  4918.    For any valid choice of e there exist some unconcealed messages.
  4919.    It's important that the number of unconcealed messages is at a minimum.
  4920.  
  4921.    Choose p=1009 and q=3643.
  4922.    Find the sum of all values of e, 1<e<φ(1009,3643) and gcd(e,φ)=1, so that
  4923.    the number of unconcealed messages for this value of e is at a minimum.
  4924.  
  4925.    
  4926.    Answer: 088ad9a61e60b9309e91cfc3ed27d729
  4927.  
  4928.  
  4929. Problem 183
  4930. ===========
  4931.  
  4932.  
  4933.    Let N be a positive integer and let N be split into k equal parts, r =
  4934.    N/k, so that N = r + r + ... + r.
  4935.    Let P be the product of these parts, P = r × r × ... × r = r^k.
  4936.  
  4937.    For example, if 11 is split into five equal parts, 11 = 2.2 + 2.2 + 2.2 +
  4938.    2.2 + 2.2, then P = 2.2^5 = 51.53632.
  4939.  
  4940.    Let M(N) = P[max] for a given value of N.
  4941.  
  4942.    It turns out that the maximum for N = 11 is found by splitting eleven into
  4943.    four equal parts which leads to P[max] = (11/4)^4; that is, M(11) =
  4944.    14641/256 = 57.19140625, which is a terminating decimal.
  4945.  
  4946.    However, for N = 8 the maximum is achieved by splitting it into three
  4947.    equal parts, so M(8) = 512/27, which is a non-terminating decimal.
  4948.  
  4949.    Let D(N) = N if M(N) is a non-terminating decimal and D(N) = -N if M(N) is
  4950.    a terminating decimal.
  4951.  
  4952.    For example, ΣD(N) for 5 ≤ N ≤ 100 is 2438.
  4953.  
  4954.    Find ΣD(N) for 5 ≤ N ≤ 10000.
  4955.  
  4956.    
  4957.    Answer: 48861552
  4958.  
  4959.  
  4960. Problem 184
  4961. ===========
  4962.  
  4963.  
  4964.    Consider the set I[r] of points (x,y) with integer co-ordinates in the
  4965.    interior of the circle with radius r, centered at the origin, i.e. x^2 +
  4966.    y^2 < r^2.
  4967.  
  4968.    For a radius of 2, I[2] contains the nine points (0,0), (1,0), (1,1),
  4969.    (0,1), (-1,1), (-1,0), (-1,-1), (0,-1) and (1,-1). There are eight
  4970.    triangles having all three vertices in I[2] which contain the origin in
  4971.    the interior. Two of them are shown below, the others are obtained from
  4972.    these by rotation.
  4973.  
  4974.    For a radius of 3, there are 360 triangles containing the origin in the
  4975.    interior and having all vertices in I[3] and for I[5] the number is 10600.
  4976.  
  4977.    How many triangles are there containing the origin in the interior and
  4978.    having all three vertices in I[105]?
  4979.  
  4980.    
  4981.    p_184.gif
  4982.    Answer: aa80f8619ed594e5d7852564457dbca6
  4983.  
  4984.  
  4985. Problem 185
  4986. ===========
  4987.  
  4988.  
  4989.    The game Number Mind is a variant of the well known game Master Mind.
  4990.  
  4991.    Instead of coloured pegs, you have to guess a secret sequence of digits.
  4992.    After each guess you're only told in how many places you've guessed the
  4993.    correct digit. So, if the sequence was 1234 and you guessed 2036, you'd be
  4994.    told that you have one correct digit; however, you would NOT be told that
  4995.    you also have another digit in the wrong place.
  4996.  
  4997.    For instance, given the following guesses for a 5-digit secret sequence,
  4998.  
  4999.    90342 ;2 correct
  5000.    70794 ;0 correct
  5001.    39458 ;2 correct
  5002.    34109 ;1 correct
  5003.    51545 ;2 correct
  5004.    12531 ;1 correct
  5005.  
  5006.    The correct sequence 39542 is unique.
  5007.  
  5008.    Based on the following guesses,
  5009.  
  5010.    5616185650518293 ;2 correct
  5011.    3847439647293047 ;1 correct
  5012.    5855462940810587 ;3 correct
  5013.    9742855507068353 ;3 correct
  5014.    4296849643607543 ;3 correct
  5015.    3174248439465858 ;1 correct
  5016.    4513559094146117 ;2 correct
  5017.    7890971548908067 ;3 correct
  5018.    8157356344118483 ;1 correct
  5019.    2615250744386899 ;2 correct
  5020.    8690095851526254 ;3 correct
  5021.    6375711915077050 ;1 correct
  5022.    6913859173121360 ;1 correct
  5023.    6442889055042768 ;2 correct
  5024.    2321386104303845 ;0 correct
  5025.    2326509471271448 ;2 correct
  5026.    5251583379644322 ;2 correct
  5027.    1748270476758276 ;3 correct
  5028.    4895722652190306 ;1 correct
  5029.    3041631117224635 ;3 correct
  5030.    1841236454324589 ;3 correct
  5031.    2659862637316867 ;2 correct
  5032.  
  5033.    Find the unique 16-digit secret sequence.
  5034.  
  5035.    
  5036.    Answer: 70f84864f21c4bf07ee53436580cd4bb
  5037.  
  5038.  
  5039. Problem 186
  5040. ===========
  5041.  
  5042.  
  5043.    Here are the records from a busy telephone system with one million users:
  5044.  
  5045.                     ┌─────────────────┬─────────┬─────────┐
  5046.                     │RecNr            │ Caller  │ Called  │
  5047.                     ├─────────────────┼─────────┼─────────┤
  5048.                     │        1        │ 200007  │ 100053  │
  5049.                     ├─────────────────┼─────────┼─────────┤
  5050.                     │        2        │ 600183  │ 500439  │
  5051.                     ├─────────────────┼─────────┼─────────┤
  5052.                     │        3        │ 600863  │ 701497  │
  5053.                     ├─────────────────┼─────────┼─────────┤
  5054.                     │       ...       │   ...   │   ...   │
  5055.                     └─────────────────┴─────────┴─────────┘
  5056.  
  5057.    The telephone number of the caller and the called number in record n are
  5058.    Caller(n) = S[2n-1] and Called(n) = S[2n] where S[1,2,3,...] come from the
  5059.    "Lagged Fibonacci Generator":
  5060.  
  5061.    For 1 ≤ k ≤ 55, S[k] = [100003 - 200003k + 300007k^3] (modulo 1000000)
  5062.    For 56 ≤ k, S[k] = [S[k-24] + S[k-55]] (modulo 1000000)
  5063.  
  5064.    If Caller(n) = Called(n) then the user is assumed to have misdialled and
  5065.    the call fails; otherwise the call is successful.
  5066.  
  5067.    From the start of the records, we say that any pair of users X and Y are
  5068.    friends if X calls Y or vice-versa. Similarly, X is a friend of a friend
  5069.    of Z if X is a friend of Y and Y is a friend of Z; and so on for longer
  5070.    chains.
  5071.  
  5072.    The Prime Minister's phone number is 524287. After how many successful
  5073.    calls, not counting misdials, will 99% of the users (including the PM) be
  5074.    a friend, or a friend of a friend etc., of the Prime Minister?
  5075.  
  5076.    
  5077.    Answer: 2325629
  5078.  
  5079.  
  5080. Problem 187
  5081. ===========
  5082.  
  5083.  
  5084.    A composite is a number containing at least two prime factors. For
  5085.    example, 15 = 3 × 5; 9 = 3 × 3; 12 = 2 × 2 × 3.
  5086.  
  5087.    There are ten composites below thirty containing precisely two, not
  5088.    necessarily distinct, prime factors:4, 6, 9, 10, 14, 15, 21, 22, 25, 26.
  5089.  
  5090.    How many composite integers, n < 10^8, have precisely two, not necessarily
  5091.    distinct, prime factors?
  5092.  
  5093.    
  5094.    Answer: 17427258
  5095.  
  5096.  
  5097. Problem 188
  5098. ===========
  5099.  
  5100.  
  5101.    The hyperexponentiation or tetration of a number a by a positive integer
  5102.    b, denoted by a↑↑b or ^ba, is recursively defined by:
  5103.  
  5104.    a↑↑1 = a,
  5105.    a↑↑(k+1) = a^(a↑↑k).
  5106.  
  5107.    Thus we have e.g. 3↑↑2 = 3^3 = 27, hence 3↑↑3 = 3^27 = 7625597484987 and
  5108.    3↑↑4 is roughly 10^3.6383346400240996*10^12.
  5109.  
  5110.    Find the last 8 digits of 1777↑↑1855.
  5111.  
  5112.    
  5113.    Answer: 95962097
  5114.  
  5115.  
  5116. Problem 189
  5117. ===========
  5118.  
  5119.  
  5120.    Consider the following configuration of 64 triangles:
  5121.  
  5122.    We wish to colour the interior of each triangle with one of three colours:
  5123.    red, green or blue, so that no two neighbouring triangles have the same
  5124.    colour. Such a colouring shall be called valid. Here, two triangles are
  5125.    said to be neighbouring if they share an edge.
  5126.    Note: if they only share a vertex, then they are not neighbours.
  5127.  
  5128.    For example, here is a valid colouring of the above grid:
  5129.  
  5130.    A colouring C' which is obtained from a colouring C by rotation or
  5131.    reflection is considered distinct from C unless the two are identical.
  5132.  
  5133.    How many distinct valid colourings are there for the above configuration?
  5134.  
  5135.    
  5136.    p_189_grid.gif
  5137.    p_189_colours.gif
  5138.    Answer: d3dfdd37601678212b746c34699f1484
  5139.  
  5140.  
  5141. Problem 190
  5142. ===========
  5143.  
  5144.  
  5145.    Let S[m] = (x[1], x[2], ... , x[m]) be the m-tuple of positive real
  5146.    numbers with x[1] + x[2] + ... + x[m] = m for which P[m] = x[1] * x[2]^2 *
  5147.    ... * x[m]^m is maximised.
  5148.  
  5149.    For example, it can be verified that [P[10]] = 4112 ([ ] is the integer
  5150.    part function).
  5151.  
  5152.    Find Σ[P[m]] for 2 ≤ m ≤ 15.
  5153.  
  5154.    
  5155.    Answer: 40cfcabd9b30d79ec81151fc756e9946
  5156.  
  5157.  
  5158. Problem 191
  5159. ===========
  5160.  
  5161.  
  5162.    A particular school offers cash rewards to children with good attendance
  5163.    and punctuality. If they are absent for three consecutive days or late on
  5164.    more than one occasion then they forfeit their prize.
  5165.  
  5166.    During an n-day period a trinary string is formed for each child
  5167.    consisting of L's (late), O's (on time), and A's (absent).
  5168.  
  5169.    Although there are eighty-one trinary strings for a 4-day period that can
  5170.    be formed, exactly forty-three strings would lead to a prize:
  5171.  
  5172.    OOOO OOOA OOOL OOAO OOAA OOAL OOLO OOLA OAOO OAOA
  5173.    OAOL OAAO OAAL OALO OALA OLOO OLOA OLAO OLAA AOOO
  5174.    AOOA AOOL AOAO AOAA AOAL AOLO AOLA AAOO AAOA AAOL
  5175.    AALO AALA ALOO ALOA ALAO ALAA LOOO LOOA LOAO LOAA
  5176.    LAOO LAOA LAAO
  5177.  
  5178.    How many "prize" strings exist over a 30-day period?
  5179.  
  5180.    
  5181.    Answer: e04dfa598b22a87570f63063f3ff595d
  5182.  
  5183.  
  5184. Problem 192
  5185. ===========
  5186.  
  5187.  
  5188.    Let x be a real number.
  5189.    A best approximation to x for the denominator bound d is a rational number
  5190.    r/s in reduced form, with s ≤ d, such that any rational number which is
  5191.    closer to x than r/s has a denominator larger than d:
  5192.  
  5193.                            |p/q-x| < |r/s-x| ⇒ q > d
  5194.  
  5195.    For example, the best approximation to √13 for the denominator bound 20 is
  5196.    18/5 and the best approximation to √13 for the denominator bound 30 is
  5197.    101/28.
  5198.  
  5199.    Find the sum of all denominators of the best approximations to √n for the
  5200.    denominator bound 10^12, where n is not a perfect square and 1 < n ≤
  5201.    100000.
  5202.  
  5203.    
  5204.    Answer: e5ec7d4b094709b1fcebbd73b10e6264
  5205.  
  5206.  
  5207. Problem 193
  5208. ===========
  5209.  
  5210.  
  5211.    A positive integer n is called squarefree, if no square of a prime divides
  5212.    n, thus 1, 2, 3, 5, 6, 7, 10, 11 are squarefree, but not 4, 8, 9, 12.
  5213.  
  5214.    How many squarefree numbers are there below 2^50?
  5215.  
  5216.    
  5217.    Answer: ea29fcf755b560777b0b6d8714234d18
  5218.  
  5219.  
  5220. Problem 194
  5221. ===========
  5222.  
  5223.  
  5224.    Consider graphs built with the units A: and B: , where the units are glued
  5225.    alongthe vertical edges as in the graph .
  5226.  
  5227.    A configuration of type (a,b,c) is a graph thus built of a units A and b
  5228.    units B, where the graph's vertices are coloured using up to c colours, so
  5229.    that no two adjacent vertices have the same colour.
  5230.    The compound graph above is an example of a configuration of type (2,2,6),
  5231.    in fact of type (2,2,c) for all c ≥ 4.
  5232.  
  5233.    Let N(a,b,c) be the number of configurations of type (a,b,c).
  5234.    For example, N(1,0,3) = 24, N(0,2,4) = 92928 and N(2,2,3) = 20736.
  5235.  
  5236.    Find the last 8 digits of N(25,75,1984).
  5237.  
  5238.    
  5239.    p_194_GraphA.png
  5240.    p_194_GraphB.png
  5241.    p_194_Fig.png
  5242.    Answer: 61190912
  5243.  
  5244.  
  5245. Problem 195
  5246. ===========
  5247.  
  5248.  
  5249.    Let's call an integer sided triangle with exactly one angle of 60 degrees
  5250.    a 60-degree triangle.
  5251.    Let r be the radius of the inscribed circle of such a 60-degree triangle.
  5252.  
  5253.    There are 1234 60-degree triangles for which r ≤ 100.
  5254.    Let T(n) be the number of 60-degree triangles for which r ≤ n, so
  5255.    T(100) = 1234,  T(1000) = 22767, and  T(10000) = 359912.
  5256.  
  5257.    Find T(1053779).
  5258.  
  5259.    
  5260.    Answer: 75085391
  5261.  
  5262.  
  5263. Problem 196
  5264. ===========
  5265.  
  5266.  
  5267.    Build a triangle from all positive integers in the following way:
  5268.  
  5269.     1
  5270.     2  3
  5271.     4  5  6
  5272.     7  8  9 10
  5273.    11 12 13 14 15
  5274.    16 17 18 19 20 21
  5275.    22 23 24 25 26 27 28
  5276.    29 30 31 32 33 34 35 36
  5277.    37 38 39 40 41 42 43 44 45
  5278.    46 47 48 49 50 51 52 53 54 55
  5279.    56 57 58 59 60 61 62 63 64 65 66
  5280.    . . .
  5281.  
  5282.    Each positive integer has up to eight neighbours in the triangle.
  5283.  
  5284.    A set of three primes is called a prime triplet if one of the three primes
  5285.    has the other two as neighbours in the triangle.
  5286.  
  5287.    For example, in the second row, the prime numbers 2 and 3 are elements of
  5288.    some prime triplet.
  5289.  
  5290.    If row 8 is considered, it contains two primes which are elements of some
  5291.    prime triplet, i.e. 29 and 31.
  5292.    If row 9 is considered, it contains only one prime which is an element of
  5293.    some prime triplet: 37.
  5294.  
  5295.    Define S(n) as the sum of the primes in row n which are elements of any
  5296.    prime triplet.
  5297.    Then S(8)=60 and S(9)=37.
  5298.  
  5299.    You are given that S(10000)=950007619.
  5300.  
  5301.    Find  S(5678027) + S(7208785).
  5302.  
  5303.    
  5304.    Answer: fb6b6b0a4b7b31ba429152bc0b6bd037
  5305.  
  5306.  
  5307. Problem 197
  5308. ===========
  5309.  
  5310.  
  5311.    Given is the function f(x) = ⌊2^30.403243784-x^2⌋ × 10^-9 ( ⌊ ⌋ is the
  5312.    floor-function),
  5313.    the sequence u[n] is defined by u[0] = -1 and u[n+1] = f(u[n]).
  5314.  
  5315.    Find u[n] + u[n+1] for n = 10^12.
  5316.    Give your answer with 9 digits after the decimal point.
  5317.  
  5318.    
  5319.    Answer: c98cbf87636906f2465d481be815e454
  5320.  
  5321.  
  5322. Problem 198
  5323. ===========
  5324.  
  5325.  
  5326.    A best approximation to a real number x for the denominator bound d is a
  5327.    rational number r/s (in reduced form) with s ≤ d, so that any rational
  5328.    number p/q which is closer to x than r/s has q > d.
  5329.  
  5330.    Usually the best approximation to a real number is uniquely determined for
  5331.    all denominator bounds. However, there are some exceptions, e.g. 9/40 has
  5332.    the two best approximations 1/4 and 1/5 for the denominator bound 6.We
  5333.    shall call a real number x ambiguous, if there is at least one denominator
  5334.    bound for which x possesses two best approximations. Clearly, an ambiguous
  5335.    number is necessarily rational.
  5336.  
  5337.    How many ambiguous numbers x = p/q,0 < x < 1/100, are there whose
  5338.    denominator q does not exceed 10^8?
  5339.  
  5340.    
  5341.    Answer: 52374425
  5342.  
  5343.  
  5344. Problem 199
  5345. ===========
  5346.  
  5347.  
  5348.    Three circles of equal radius are placed inside a larger circle such that
  5349.    each pair of circles is tangent to one another and the inner circles do
  5350.    not overlap. There are four uncovered "gaps" which are to be filled
  5351.    iteratively with more tangent circles.
  5352.  
  5353.    At each iteration, a maximally sized circle is placed in each gap, which
  5354.    creates more gaps for the next iteration. After 3 iterations (pictured),
  5355.    there are 108 gaps and the fraction of the area which is not covered by
  5356.    circles is 0.06790342, rounded to eight decimal places.
  5357.  
  5358.    What fraction of the area is not covered by circles after 10 iterations?
  5359.    Give your answer rounded to eight decimal places using the format
  5360.    x.xxxxxxxx .
  5361.  
  5362.    
  5363.    p_199_circles_in_circles.gif
  5364.    Answer: 0f8fd87159c28ae5fea6ac91a95d48dd
  5365.  
  5366.  
  5367. Problem 200
  5368. ===========
  5369.  
  5370.  
  5371.    We shall define a sqube to be a number of the form, p^2q^3, where p and q
  5372.    are distinct primes.
  5373.    For example, 200 = 5^22^3 or 120072949 = 23^261^3.
  5374.  
  5375.    The first five squbes are 72, 108, 200, 392, and 500.
  5376.  
  5377.    Interestingly, 200 is also the first number for which you cannot change
  5378.    any single digit to make a prime; we shall call such numbers, prime-proof.
  5379.    The next prime-proof sqube which contains the contiguous sub-string "200"
  5380.    is 1992008.
  5381.  
  5382.    Find the 200th prime-proof sqube containing the contiguous sub-string
  5383.    "200".
  5384.  
  5385.    
  5386.    Answer: c911c8e346aa813da5f5ed4f8e9128d8
  5387.  
  5388.  
  5389. Problem 201
  5390. ===========
  5391.  
  5392.  
  5393.    For any set A of numbers, let sum(A) be the sum of the elements of A.
  5394.    Consider the set B = {1,3,6,8,10,11}.
  5395.    There are 20 subsets of B containing three elements, and their sums are:
  5396.  
  5397.    sum({1,3,6}) = 10,
  5398.    sum({1,3,8}) = 12,
  5399.    sum({1,3,10}) = 14,
  5400.    sum({1,3,11}) = 15,
  5401.    sum({1,6,8}) = 15,
  5402.    sum({1,6,10}) = 17,
  5403.    sum({1,6,11}) = 18,
  5404.    sum({1,8,10}) = 19,
  5405.    sum({1,8,11}) = 20,
  5406.    sum({1,10,11}) = 22,
  5407.    sum({3,6,8}) = 17,
  5408.    sum({3,6,10}) = 19,
  5409.    sum({3,6,11}) = 20,
  5410.    sum({3,8,10}) = 21,
  5411.    sum({3,8,11}) = 22,
  5412.    sum({3,10,11}) = 24,
  5413.    sum({6,8,10}) = 24,
  5414.    sum({6,8,11}) = 25,
  5415.    sum({6,10,11}) = 27,
  5416.    sum({8,10,11}) = 29.
  5417.  
  5418.    Some of these sums occur more than once, others are unique.
  5419.    For a set A, let U(A,k) be the set of unique sums of k-element subsets of
  5420.    A, in our example we find U(B,3) = {10,12,14,18,21,25,27,29} and
  5421.    sum(U(B,3)) = 156.
  5422.  
  5423.    Now consider the 100-element set S = {1^2, 2^2, ... , 100^2}.
  5424.    S has 100891344545564193334812497256 50-element subsets.
  5425.  
  5426.    Determine the sum of all integers which are the sum of exactly one of the
  5427.    50-element subsets of S, i.e. find sum(U(S,50)).
  5428.  
  5429.    
  5430.    Answer: 115039000
  5431.  
  5432.  
  5433. Problem 202
  5434. ===========
  5435.  
  5436.  
  5437.    Three mirrors are arranged in the shape of an equilateral triangle, with
  5438.    their reflective surfaces pointing inwards. There is an infinitesimal gap
  5439.    at each vertex of the triangle through which a laser beam may pass.
  5440.  
  5441.    Label the vertices A, B and C. There are 2 ways in which a laser beam may
  5442.    enter vertex C, bounce off 11 surfaces, then exit through the same vertex:
  5443.    one way is shown below; the other is the reverse of that.
  5444.  
  5445.    There are 80840 ways in which a laser beam may enter vertex C, bounce off
  5446.    1000001 surfaces, then exit through the same vertex.
  5447.  
  5448.    In how many ways can a laser beam enter at vertex C, bounce off
  5449.    12017639147 surfaces, then exit through the same vertex?
  5450.  
  5451.    
  5452.    p_201_laserbeam.gif
  5453.    Answer: e9774949b5efad0d40d60ede379c5321
  5454.  
  5455.  
  5456. Problem 203
  5457. ===========
  5458.  
  5459.  
  5460.    The binomial coefficients ^nC[k] can be arranged in triangular form,
  5461.    Pascal's triangle, like this:
  5462.  
  5463.                                        1
  5464.                                     1     1
  5465.                                  1     2     1
  5466.                               1     3     3     1
  5467.                             1    4     6     4     1
  5468.                           1   5     10    10    5    1
  5469.                         1   6    15    20    15    6   1
  5470.                       1   7   21    35    35    21   7   1
  5471.  
  5472.                                    .........
  5473.  
  5474.    It can be seen that the first eight rows of Pascal's triangle contain
  5475.    twelve distinct numbers: 1, 2, 3, 4, 5, 6, 7, 10, 15, 20, 21 and 35.
  5476.  
  5477.    A positive integer n is called squarefree if no square of a prime divides
  5478.    n.Of the twelve distinct numbers in the first eight rows of Pascal's
  5479.    triangle, all except 4 and 20 are squarefree.The sum of the distinct
  5480.    squarefree numbers in the first eight rows is 105.
  5481.  
  5482.    Find the sum of the distinct squarefree numbers in the first 51 rows of
  5483.    Pascal's triangle.
  5484.  
  5485.    
  5486.    Answer: d7ec16d216c923d3c927f46cfc914e92
  5487.  
  5488.  
  5489. Problem 204
  5490. ===========
  5491.  
  5492.  
  5493.    A Hamming number is a positive number which has no prime factor larger
  5494.    than 5.
  5495.    So the first few Hamming numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15.
  5496.    There are 1105 Hamming numbers not exceeding 10^8.
  5497.  
  5498.    We will call a positive number a generalised Hamming number of type n, if
  5499.    it has no prime factor larger than n.
  5500.    Hence the Hamming numbers are the generalised Hamming numbers of type 5.
  5501.  
  5502.    How many generalised Hamming numbers of type 100 are there which don't
  5503.    exceed 10^9?
  5504.  
  5505.    
  5506.    Answer: 2944730
  5507.  
  5508.  
  5509. Problem 205
  5510. ===========
  5511.  
  5512.  
  5513.    Peter has nine four-sided (pyramidal) dice, each with faces numbered 1, 2,
  5514.    3, 4.
  5515.    Colin has six six-sided (cubic) dice, each with faces numbered 1, 2, 3, 4,
  5516.    5, 6.
  5517.  
  5518.    Peter and Colin roll their dice and compare totals: the highest total
  5519.    wins. The result is a draw if the totals are equal.
  5520.  
  5521.    What is the probability that Pyramidal Pete beats Cubic Colin? Give your
  5522.    answer rounded to seven decimal places in the form 0.abcdefg
  5523.  
  5524.    
  5525.    Answer: ba6c6c3888227a0799eca38191b587be
  5526.  
  5527.  
  5528. Problem 206
  5529. ===========
  5530.  
  5531.  
  5532.    Find the unique positive integer whose square has the form
  5533.    1_2_3_4_5_6_7_8_9_0,
  5534.    where each “_” is a single digit.
  5535.  
  5536.    
  5537.    Answer: 09f9d87cb4b1ebb34e1f607e55a351d8
  5538.  
  5539.  
  5540. Problem 207
  5541. ===========
  5542.  
  5543.  
  5544.    For some positive integers k, there exists an integer partition of the
  5545.    form   4^t = 2^t + k,
  5546.    where 4^t, 2^t, and k are all positive integers and t is a real number.
  5547.  
  5548.    The first two such partitions are 4^1 = 2^1 + 2 and 4^1.5849625... =
  5549.    2^1.5849625... + 6.
  5550.  
  5551.    Partitions where t is also an integer are called perfect.
  5552.    For any m ≥ 1 let P(m) be the proportion of such partitions that are
  5553.    perfect with k ≤ m.
  5554.    Thus P(6) = 1/2.
  5555.  
  5556.    In the following table are listed some values of P(m)
  5557.  
  5558.       P(5) = 1/1
  5559.       P(10) = 1/2
  5560.       P(15) = 2/3
  5561.       P(20) = 1/2
  5562.       P(25) = 1/2
  5563.       P(30) = 2/5
  5564.       ...
  5565.       P(180) = 1/4
  5566.       P(185) = 3/13
  5567.  
  5568.    Find the smallest m for which P(m) < 1/12345
  5569.  
  5570.    
  5571.    Answer: 3f17b264ed1717fe5fbde1e399bd501f
  5572.  
  5573.  
  5574. Problem 208
  5575. ===========
  5576.  
  5577.  
  5578.    A robot moves in a series of one-fifth circular arcs (72°), with a free
  5579.    choice of a clockwise or an anticlockwise arc for each step, but no
  5580.    turning on the spot.
  5581.  
  5582.    One of 70932 possible closed paths of 25 arcs starting northward is
  5583.  
  5584.    Given that the robot starts facing North, how many journeys of 70 arcs in
  5585.    length can it take that return it, after the final arc, to its starting
  5586.    position?
  5587.    (Any arc may be traversed multiple times.)
  5588.  
  5589.    
  5590.    p_208_robotwalk.gif
  5591.    Answer: 3010e33173f30e0aac79e84835b48823
  5592.  
  5593.  
  5594. Problem 209
  5595. ===========
  5596.  
  5597.  
  5598.    A k-input binary truth table is a map from k input bits(binary digits, 0
  5599.    [false] or 1 [true]) to 1 output bit. For example, the 2-input binary
  5600.    truth tables for the logical AND and XOR functions are:
  5601.  
  5602.    ┌────┬────┬─────────┐
  5603.    │ x  │ y  │x AND y  │
  5604.    ├────┼────┼─────────┤
  5605.    │ 0  │ 0  │    0    │
  5606.    ├────┼────┼─────────┤
  5607.    │ 0  │ 1  │    0    │
  5608.    ├────┼────┼─────────┤
  5609.    │ 1  │ 0  │    0    │
  5610.    ├────┼────┼─────────┤
  5611.    │ 1  │ 1  │    1    │
  5612.    └────┴────┴─────────┘
  5613.  
  5614.                                                         ┌────┬────┬─────────┐
  5615.                                                         │ x  │ y  │x XOR y  │
  5616.                                                         ├────┼────┼─────────┤
  5617.                                                         │ 0  │ 0  │    0    │
  5618.                                                         ├────┼────┼─────────┤
  5619.                                                         │ 0  │ 1  │    1    │
  5620.                                                         ├────┼────┼─────────┤
  5621.                                                         │ 1  │ 0  │    1    │
  5622.                                                         ├────┼────┼─────────┤
  5623.                                                         │ 1  │ 1  │    0    │
  5624.                                                         └────┴────┴─────────┘
  5625.  
  5626.    How many 6-input binary truth tables, τ, satisfy the formula
  5627.  
  5628.          τ(a, b, c, d, e, f) AND τ(b, c, d, e, f, a XOR (b AND c)) = 0
  5629.    
  5630.    Answer: 954157aa4762df2ee29580ee5a351b13
  5631.  
  5632.  
  5633. Problem 210
  5634. ===========
  5635.  
  5636.    Consider the set S(r) of points (x,y) with integer coordinates satisfying
  5637.    |x| + |y| ≤ r.
  5638.    Let O be the point (0,0) and C the point (r/4,r/4).
  5639.    Let N(r) be the number of points B in S(r), so that the triangle OBC has
  5640.    an obtuse angle, i.e. the largest angle α satisfies 90°<α<180°.
  5641.    So, for example, N(4)=24 and N(8)=100.
  5642.  
  5643.    What is N(1,000,000,000)?
  5644.  
  5645.    
  5646.    Answer: 0c808b02789c4db462322ab2ac070bbb
  5647.  
  5648.  
  5649. Problem 211
  5650. ===========
  5651.  
  5652.  
  5653.    For a positive integer n, let σ[2](n) be the sum of the squares of its
  5654.    divisors. For example,
  5655.  
  5656.                        σ[2](10) = 1 + 4 + 25 + 100 = 130.
  5657.  
  5658.    Find the sum of all n, 0 < n < 64,000,000 such that σ[2](n) is a perfect
  5659.    square.
  5660.  
  5661.    
  5662.    Answer: 5fe0ed146690e7bca448687a94353a73
  5663.  
  5664.  
  5665. Problem 212
  5666. ===========
  5667.  
  5668.  
  5669.    An axis-aligned cuboid, specified by parameters { (x[0],y[0],z[0]),
  5670.    (dx,dy,dz) }, consists of all points (X,Y,Z) such that x[0] ≤ X ≤ x[0]+dx,
  5671.    y[0] ≤ Y ≤ y[0]+dy and z[0] ≤ Z ≤ z[0]+dz. The volume of the cuboid is the
  5672.    product, dx × dy × dz. The combined volume of a collection of cuboids is
  5673.    the volume of their union and will be less than the sum of the individual
  5674.    volumes if any cuboids overlap.
  5675.  
  5676.    Let C[1],...,C[50000] be a collection of 50000 axis-aligned cuboids such
  5677.    that C[n] has parameters
  5678.  
  5679.    x[0] = S[6n-5] modulo 10000
  5680.    y[0] = S[6n-4] modulo 10000
  5681.    z[0] = S[6n-3] modulo 10000
  5682.    dx = 1 + (S[6n-2] modulo 399)
  5683.    dy = 1 + (S[6n-1] modulo 399)
  5684.    dz = 1 + (S[6n] modulo 399)
  5685.  
  5686.    where S[1],...,S[300000] come from the "Lagged Fibonacci Generator":
  5687.  
  5688.    For 1 ≤ k ≤ 55, S[k] = [100003 - 200003k + 300007k^3]   (modulo 1000000)
  5689.    For 56 ≤ k, S[k] = [S[k-24] + S[k-55]]   (modulo 1000000)
  5690.  
  5691.    Thus, C[1] has parameters {(7,53,183),(94,369,56)}, C[2] has parameters
  5692.    {(2383,3563,5079),(42,212,344)}, and so on.
  5693.  
  5694.    The combined volume of the first 100 cuboids, C[1],...,C[100], is
  5695.    723581599.
  5696.  
  5697.    What is the combined volume of all 50000 cuboids, C[1],...,C[50000] ?
  5698.  
  5699.    
  5700.    Answer: 76650c9c077929e1ce5a80a1ac81fa96
  5701.  
  5702.  
  5703. Problem 213
  5704. ===========
  5705.  
  5706.  
  5707.    A 30×30 grid of squares contains 900 fleas, initially one flea per square.
  5708.    When a bell is rung, each flea jumps to an adjacent square at random
  5709.    (usually 4 possibilities, except for fleas on the edge of the grid or at
  5710.    the corners).
  5711.  
  5712.    What is the expected number of unoccupied squares after 50 rings of the
  5713.    bell? Give your answer rounded to six decimal places.
  5714.  
  5715.    
  5716.    Answer: f81ee7dd444a3d895a4a446f9d115bf8
  5717.  
  5718.  
  5719. Problem 214
  5720. ===========
  5721.  
  5722.  
  5723.    Let φ be Euler's totient function, i.e. for a natural number n,φ(n) is the
  5724.    number of k, 1 ≤ k ≤ n, for which gcd(k,n) = 1.
  5725.  
  5726.    By iterating φ, each positive integer generates a decreasing chain of
  5727.    numbers ending in 1.
  5728.    E.g. if we start with 5 the sequence 5,4,2,1 is generated.
  5729.    Here is a listing of all chains with length 4:
  5730.  
  5731.                                                                       5,4,2,1
  5732.                                                                       7,6,2,1
  5733.                                                                       8,4,2,1
  5734.                                                                       9,6,2,1
  5735.                                                                      10,4,2,1
  5736.                                                                      12,4,2,1
  5737.                                                                      14,6,2,1
  5738.                                                                      18,6,2,1
  5739.  
  5740.    Only two of these chains start with a prime, their sum is 12.
  5741.  
  5742.    What is the sum of all primes less than 40000000 which generate a chain of
  5743.    length 25?
  5744.  
  5745.    
  5746.    Answer: 1cefd865483c03552d5247ffb05685c7
  5747.  
  5748.  
  5749. Problem 215
  5750. ===========
  5751.  
  5752.  
  5753.    Consider the problem of building a wall out of 2×1 and 3×1 bricks
  5754.    (horizontal×vertical dimensions) such that, for extra strength, the gaps
  5755.    between horizontally-adjacent bricks never line up in consecutive layers,
  5756.    i.e. never form a "running crack".
  5757.  
  5758.    For example, the following 9×3 wall is not acceptable due to the running
  5759.    crack shown in red:
  5760.  
  5761.    There are eight ways of forming a crack-free 9×3 wall, written W(9,3) = 8.
  5762.  
  5763.    Calculate W(32,10).
  5764.  
  5765.    
  5766.    p_215_crackfree.gif
  5767.    Answer: 60212c9ec4a6cd1d14277c32b6adf2d8
  5768.  
  5769.  
  5770. Problem 216
  5771. ===========
  5772.  
  5773.  
  5774.    Consider numbers t(n) of the form t(n) = 2n^2-1 with n > 1.
  5775.    The first such numbers are 7, 17, 31, 49, 71, 97, 127 and 161.
  5776.    It turns out that only 49 = 7*7 and 161 = 7*23 are not prime.
  5777.    For n ≤ 10000 there are 2202 numbers t(n) that are prime.
  5778.  
  5779.    How many numbers t(n) are prime for n ≤ 50,000,000 ?
  5780.  
  5781.    
  5782.    Answer: 5437849
  5783.  
  5784.  
  5785. Problem 217
  5786. ===========
  5787.  
  5788.  
  5789.    A positive integer with k (decimal) digits is called balanced if its first
  5790.    ⌈^k/[2]⌉ digits sum to the same value as its last ⌈^k/[2]⌉ digits, where
  5791.    ⌈x⌉, pronounced ceiling of x, is the smallest integer ≥ x, thus ⌈π⌉ = 4
  5792.    and ⌈5⌉ = 5.
  5793.  
  5794.    So, for example, all palindromes are balanced, as is 13722.
  5795.  
  5796.    Let T(n) be the sum of all balanced numbers less than 10^n.
  5797.    Thus: T(1) = 45, T(2) = 540 and T(5) = 334795890.
  5798.  
  5799.    Find T(47) mod 3^15
  5800.  
  5801.    
  5802.    Answer: 6273134
  5803.  
  5804.  
  5805. Problem 218
  5806. ===========
  5807.  
  5808.  
  5809.    Consider the right angled triangle with sides a=7, b=24 and c=25.The area
  5810.    of this triangle is 84, which is divisible by the perfect numbers 6 and
  5811.    28.
  5812.    Moreover it is a primitive right angled triangle as gcd(a,b)=1 and
  5813.    gcd(b,c)=1.
  5814.    Also c is a perfect square.
  5815.  
  5816.    We will call a right angled triangle perfect if
  5817.    -it is a primitive right angled triangle
  5818.    -its hypotenuse is a perfect square
  5819.  
  5820.    We will call a right angled triangle super-perfect if
  5821.    -it is a perfect right angled triangle and
  5822.    -its area is a multiple of the perfect numbers 6 and 28.
  5823.  
  5824.    How many perfect right-angled triangles with c≤10^16 exist that are not
  5825.    super-perfect?
  5826.  
  5827.    
  5828.    Answer: 0
  5829.  
  5830.  
  5831. Problem 219
  5832. ===========
  5833.  
  5834.  
  5835.    Let A and B be bit strings (sequences of 0's and 1's).
  5836.    If A is equal to the leftmost length(A) bits of B, then A is said to be a
  5837.    prefix of B.
  5838.    For example, 00110 is a prefix of 001101001, but not of 00111 or 100110.
  5839.  
  5840.    A prefix-free code of size n is a collection of n distinct bit strings
  5841.    such that no string is a prefix of any other. For example, this is a
  5842.    prefix-free code of size 6:
  5843.  
  5844.                           0000, 0001, 001, 01, 10, 11
  5845.  
  5846.    Now suppose that it costs one penny to transmit a '0' bit, but four pence
  5847.    to transmit a '1'.
  5848.    Then the total cost of the prefix-free code shown above is 35 pence, which
  5849.    happens to be the cheapest possible for the skewed pricing scheme in
  5850.    question.
  5851.    In short, we write Cost(6) = 35.
  5852.  
  5853.    What is Cost(10^9) ?
  5854.  
  5855.    
  5856.    Answer: 578c22ef288b88c60fbcf4541351aff5
  5857.  
  5858.  
  5859. Problem 220
  5860. ===========
  5861.  
  5862.  
  5863.    Let D[0] be the two-letter string "Fa". For n≥1, derive D[n] from D[n-1]
  5864.    by the string-rewriting rules:
  5865.  
  5866.    "a" → "aRbFR"
  5867.    "b" → "LFaLb"
  5868.  
  5869.    Thus, D[0] = "Fa", D[1] = "FaRbFR", D[2] = "FaRbFRRLFaLbFR", and so on.
  5870.  
  5871.    These strings can be interpreted as instructions to a computer graphics
  5872.    program, with "F" meaning "draw forward one unit", "L" meaning "turn left
  5873.    90 degrees", "R" meaning "turn right 90 degrees", and "a" and "b" being
  5874.    ignored. The initial position of the computer cursor is (0,0), pointing up
  5875.    towards (0,1).
  5876.  
  5877.    Then D[n] is an exotic drawing known as the Heighway Dragon of order n.
  5878.    For example, D[10] is shown below; counting each "F" as one step, the
  5879.    highlighted spot at (18,16) is the position reached after 500 steps.
  5880.  
  5881.    What is the position of the cursor after 10^12 steps in D[50] ?
  5882.    Give your answer in the form x,y with no spaces.
  5883.  
  5884.    
  5885.    p_220.gif
  5886.    Answer: e2018d8efde8ea00319f1adc042f150b
  5887.  
  5888.  
  5889. Problem 221
  5890. ===========
  5891.  
  5892.  
  5893.    We shall call a positive integer A an "Alexandrian integer", if there
  5894.    exist integers p, q, r such that:
  5895.  
  5896.    A = p · q · r    and   1 = 1 + 1 + 1
  5897.                           A   p   q   r
  5898.  
  5899.    For example, 630 is an Alexandrian integer (p = 5, q = −7, r = −18).In
  5900.    fact, 630 is the 6^th Alexandrian integer, the first 6 Alexandrian
  5901.    integers being: 6, 42, 120, 156, 420 and 630.
  5902.  
  5903.    Find the 150000^th Alexandrian integer.
  5904.  
  5905.    
  5906.    Answer: cb000c24f653d9c8f78b74123e6515ab
  5907.  
  5908.  
  5909. Problem 222
  5910. ===========
  5911.  
  5912.  
  5913.    What is the length of the shortest pipe, of internal radius 50mm, that can
  5914.    fully contain 21 balls of radii 30mm, 31mm, ..., 50mm?
  5915.  
  5916.    Give your answer in micrometres (10^-6 m) rounded to the nearest integer.
  5917.  
  5918.    
  5919.    Answer: 1590933
  5920.  
  5921.  
  5922. Problem 223
  5923. ===========
  5924.  
  5925.  
  5926.    Let us call an integer sided triangle with sides a ≤ b ≤ c barely acute if
  5927.    the sides satisfy
  5928.    a^2 + b^2 = c^2 + 1.
  5929.  
  5930.    How many barely acute triangles are there with perimeter ≤ 25,000,000?
  5931.  
  5932.    
  5933.    Answer: 61614848
  5934.  
  5935.  
  5936. Problem 224
  5937. ===========
  5938.  
  5939.  
  5940.    Let us call an integer sided triangle with sides a ≤ b ≤ c barely obtuse
  5941.    if the sides satisfy
  5942.    a^2 + b^2 = c^2 - 1.
  5943.  
  5944.    How many barely obtuse triangles are there with perimeter ≤ 75,000,000?
  5945.  
  5946.    
  5947.    Answer: 4137330
  5948.  
  5949.  
  5950. Problem 225
  5951. ===========
  5952.  
  5953.  
  5954.    The sequence 1, 1, 1, 3, 5, 9, 17, 31, 57, 105, 193, 355, 653, 1201 ...
  5955.    is defined by T[1] = T[2] = T[3] = 1 and T[n] = T[n-1] + T[n-2] + T[n-3].
  5956.  
  5957.    It can be shown that 27 does not divide any terms of this sequence.
  5958.    In fact, 27 is the first odd number with this property.
  5959.  
  5960.    Find the 124^th odd number that does not divide any terms of the above
  5961.    sequence.
  5962.  
  5963.    
  5964.    Answer: 2009
  5965.  
  5966.  
  5967. Problem 226
  5968. ===========
  5969.  
  5970.  
  5971.    The blancmange curve is the set of points (x,y) such that 0 ≤ x ≤ 1 and ,
  5972.    where s(x) = the distance from x to the nearest integer.
  5973.  
  5974.    The area under the blancmange curve is equal to ½, shown in pink in the
  5975.    diagram below.
  5976.  
  5977.                               [1]blancmange curve
  5978.  
  5979.    Let C be the circle with centre (¼,½) and radius ¼, shown in black in the
  5980.    diagram.
  5981.  
  5982.    What area under the blancmange curve is enclosed by C?
  5983.    Give your answer rounded to eight decimal places in the form 0.abcdefgh
  5984.  
  5985.  
  5986.    Visible links
  5987.    p_226_formula.gif
  5988.    p_226_scoop2.gif
  5989.    Answer: ce6fd32d1d2fb58c4c0c1f7962c39f04
  5990.  
  5991.  
  5992. Problem 227
  5993. ===========
  5994.  
  5995.  
  5996.    "The Chase" is a game played with two dice and an even number of players.
  5997.  
  5998.    The players sit around a table; the game begins with two opposite players
  5999.    having one die each. On each turn, the two players with a die roll it.
  6000.    If a player rolls a 1, he passes the die to his neighbour on the left; if
  6001.    he rolls a 6, he passes the die to his neighbour on the right; otherwise,
  6002.    he keeps the die for the next turn.
  6003.    The game ends when one player has both dice after they have been rolled
  6004.    and passed; that player has then lost.
  6005.  
  6006.    In a game with 100 players, what is the expected number of turns the game
  6007.    lasts?
  6008.  
  6009.    Give your answer rounded to ten significant digits.
  6010.  
  6011.    
  6012.    Answer: 7b87cd0a96f0f2f12f911cdc66608d95
  6013.  
  6014.  
  6015. Problem 228
  6016. ===========
  6017.  
  6018.  
  6019.    Let S[n] be the regular n-sided polygon – or shape – whose vertices v[k]
  6020.    (k = 1,2,…,n) have coordinates:
  6021.  
  6022.           x[k]   =   cos( ^2k-1/[n] ×180° )
  6023.           y[k]   =   sin( ^2k-1/[n] ×180° )
  6024.  
  6025.    Each S[n] is to be interpreted as a filled shape consisting of all points
  6026.    on the perimeter and in the interior.
  6027.  
  6028.    The Minkowski sum, S+T, of two shapes S and T is the result of adding
  6029.    every point in S to every point in T, where point addition is performed
  6030.    coordinate-wise: (u, v) + (x, y) = (u+x, v+y).
  6031.  
  6032.    For example, the sum of S[3] and S[4] is the six-sided shape shown in pink
  6033.    below:
  6034.  
  6035.                           [1]picture showing S_3 + S_4
  6036.  
  6037.    How many sides does S[1864] + S[1865] + … + S[1909] have?
  6038.  
  6039.  
  6040.    Visible links
  6041.    p_228.png
  6042.    Answer: 86226
  6043.  
  6044.  
  6045. Problem 229
  6046. ===========
  6047.  
  6048.  
  6049.    Consider the number 3600. It is very special, because
  6050.  
  6051.    3600 = 48^2 +     36^2
  6052.  
  6053.    3600 = 20^2 + 2×40^2
  6054.  
  6055.    3600 = 30^2 + 3×30^2
  6056.  
  6057.    3600 = 45^2 + 7×15^2
  6058.  
  6059.    Similarly, we find that 88201 = 99^2 + 280^2 = 287^2 + 2×54^2 = 283^2 +
  6060.    3×52^2 = 197^2 + 7×84^2.
  6061.  
  6062.    In 1747, Euler proved which numbers are representable as a sum of two
  6063.    squares.We are interested in the numbers n which admit representations of
  6064.    all of the following four types:
  6065.  
  6066.    n = a[1]^2 +   b[1]^2
  6067.  
  6068.    n = a[2]^2 + 2 b[2]^2
  6069.  
  6070.    n = a[3]^2 + 3 b[3]^2
  6071.  
  6072.    n = a[7]^2 + 7 b[7]^2,
  6073.  
  6074.    where the a[k] and b[k] are positive integers.
  6075.  
  6076.    There are 75373 such numbers that do not exceed 10^7.
  6077.    How many such numbers are there that do not exceed 2×10^9?
  6078.  
  6079.    
  6080.    Answer: 11325263
  6081.  
  6082.  
  6083. Problem 230
  6084. ===========
  6085.  
  6086.  
  6087.    For any two strings of digits, A and B, we define F[A,B] to be the
  6088.    sequence (A,B,AB,BAB,ABBAB,...) in which each term is the concatenation of
  6089.    the previous two.
  6090.  
  6091.    Further, we define D[A,B](n) to be the n^th digit in the first term of
  6092.    F[A,B] that contains at least n digits.
  6093.  
  6094.    Example:
  6095.  
  6096.    Let A=1415926535, B=8979323846. We wish to find D[A,B](35), say.
  6097.  
  6098.    The first few terms of F[A,B] are:
  6099.    1415926535
  6100.    8979323846
  6101.    14159265358979323846
  6102.    897932384614159265358979323846
  6103.    14159265358979323846897932384614159265358979323846
  6104.  
  6105.    Then D[A,B](35) is the 35^th digit in the fifth term, which is 9.
  6106.  
  6107.    Now we use for A the first 100 digits of π behind the decimal point:
  6108.  
  6109.    14159265358979323846264338327950288419716939937510
  6110.    58209749445923078164062862089986280348253421170679
  6111.  
  6112.    and for B the next hundred digits:
  6113.  
  6114.    82148086513282306647093844609550582231725359408128
  6115.    48111745028410270193852110555964462294895493038196 .
  6116.  
  6117.    Find ∑[n = 0,1,...,17]   10^n× D[A,B]((127+19n)×7^n) .
  6118.  
  6119.    
  6120.    Answer: 040735038021ff4704bbd3a0964369ef
  6121.  
  6122.  
  6123. Problem 231
  6124. ===========
  6125.  
  6126.  
  6127.    The binomial coefficient ^10C[3] = 120.
  6128.    120 = 2^3 × 3 × 5 = 2 × 2 × 2 × 3 × 5, and 2 + 2 + 2 + 3 + 5 = 14.
  6129.    So the sum of the terms in the prime factorisation of ^10C[3] is 14.
  6130.  
  6131.    Find the sum of the terms in the prime factorisation of
  6132.    ^20000000C[15000000].
  6133.  
  6134.    
  6135.    Answer: ef8bc4d9a843e71126bd10b5065132a5
  6136.  
  6137.  
  6138. Problem 232
  6139. ===========
  6140.  
  6141.  
  6142.    Two players share an unbiased coin and take it in turns to play "The
  6143.    Race". On Player 1's turn, he tosses the coin once: if it comes up Heads,
  6144.    he scores one point; if it comes up Tails, he scores nothing. On Player
  6145.    2's turn, she chooses a positive integer T and tosses the coin T times: if
  6146.    it comes up all Heads, she scores 2^T-1 points; otherwise, she scores
  6147.    nothing. Player 1 goes first. The winner is the first to 100 or more
  6148.    points.
  6149.  
  6150.    On each turn Player 2 selects the number, T, of coin tosses that maximises
  6151.    the probability of her winning.
  6152.  
  6153.    What is the probability that Player 2 wins?
  6154.  
  6155.    Give your answer rounded to eight decimal places in the form 0.abcdefgh .
  6156.  
  6157.    
  6158.    Answer: c8d5b243aa6e6b507725766f7c197a1d
  6159.  
  6160.  
  6161. Problem 233
  6162. ===========
  6163.  
  6164.  
  6165.    Let f(N) be the number of points with integer coordinates that are on a
  6166.    circle passing through (0,0), (N,0),(0,N), and (N,N).
  6167.  
  6168.    It can be shown that f(10000) = 36.
  6169.  
  6170.    What is the sum of all positive integers N ≤ 10^11 such that f(N) = 420 ?
  6171.  
  6172.    
  6173.    Answer: 7e80b27798170abb493e3b4671bd82ca
  6174.  
  6175.  
  6176. Problem 234
  6177. ===========
  6178.  
  6179.  
  6180.    For an integer n ≥ 4, we define the lower prime square root of n, denoted
  6181.    by lps(n), as the largest prime ≤ √n and the upper prime square root of n,
  6182.    ups(n), as the smallest prime ≥ √n.
  6183.  
  6184.    So, for example, lps(4) = 2 = ups(4), lps(1000) = 31, ups(1000) = 37.
  6185.    Let us call an integer n ≥ 4 semidivisible, if one of lps(n) and ups(n)
  6186.    divides n, but not both.
  6187.  
  6188.    The sum of the semidivisible numbers not exceeding 15 is 30, the numbers
  6189.    are 8, 10 and 12.
  6190.    15 is not semidivisible because it is a multiple of both lps(15) = 3 and
  6191.    ups(15) = 5.
  6192.    As a further example, the sum of the 92 semidivisible numbers up to 1000
  6193.    is 34825.
  6194.  
  6195.    What is the sum of all semidivisible numbers not exceeding 999966663333 ?
  6196.  
  6197.    
  6198.    Answer: c24a5d60f8ce5d04dec7466987c84d68
  6199.  
  6200.  
  6201. Problem 235
  6202. ===========
  6203.  
  6204.  
  6205.    Given is the arithmetic-geometric sequence u(k) = (900-3k)r^k-1.
  6206.    Let s(n) = Σ[k=1...n]u(k).
  6207.  
  6208.    Find the value of r for which s(5000) = -600,000,000,000.
  6209.  
  6210.    Give your answer rounded to 12 places behind the decimal point.
  6211.  
  6212.    
  6213.    Answer: 41b13508789be1001308e065d4f83ea2
  6214.  
  6215.  
  6216. Problem 236
  6217. ===========
  6218.  
  6219.  
  6220.    Suppliers 'A' and 'B' provided the following numbers of products for the
  6221.    luxury hamper market:
  6222.  
  6223.                                                          Product       'A'  'B'
  6224.                                                     Beluga Caviar      5248 640
  6225.                                                     Christmas Cake     1312 1888
  6226.                                                     Gammon Joint       2624 3776
  6227.                                                     Vintage Port       5760 3776
  6228.                                                     Champagne Truffles 3936 5664
  6229.  
  6230.    Although the suppliers try very hard to ship their goods in perfect
  6231.    condition, there is inevitably some spoilage - i.e. products gone bad.
  6232.  
  6233.    The suppliers compare their performance using two types of statistic:
  6234.  
  6235.      • The five per-product spoilage rates for each supplier are equal to the
  6236.        number of products gone bad divided by the number of products
  6237.        supplied, for each of the five products in turn.
  6238.      • The overall spoilage rate for each supplier is equal to the total
  6239.        number of products gone bad divided by the total number of products
  6240.        provided by that supplier.
  6241.  
  6242.    To their surprise, the suppliers found that each of the five per-product
  6243.    spoilage rates was worse (higher) for 'B' than for 'A' by the same factor
  6244.    (ratio of spoilage rates), m>1; and yet, paradoxically, the overall
  6245.    spoilage rate was worse for 'A' than for 'B', also by a factor of m.
  6246.  
  6247.    There are thirty-five m>1 for which this surprising result could have
  6248.    occurred, the smallest of which is 1476/1475.
  6249.  
  6250.    What's the largest possible value of m?
  6251.    Give your answer as a fraction reduced to its lowest terms, in the form
  6252.    u/v.
  6253.  
  6254.    
  6255.    Answer: 6e707fcffc510520d981ae16a29579bb
  6256.  
  6257.  
  6258. Problem 237
  6259. ===========
  6260.  
  6261.  
  6262.    Let T(n) be the number of tours over a 4 × n playing board such that:
  6263.  
  6264.      • The tour starts in the top left corner.
  6265.      • The tour consists of moves that are up, down, left, or right one
  6266.        square.
  6267.      • The tour visits each square exactly once.
  6268.      • The tour ends in the bottom left corner.
  6269.  
  6270.    The diagram shows one tour over a 4 × 10 board:
  6271.  
  6272.    T(10) is 2329. What is T(10^12) modulo 10^8?
  6273.  
  6274.    
  6275.    p_237.gif
  6276.    Answer: 15836928
  6277.  
  6278.  
  6279. Problem 238
  6280. ===========
  6281.  
  6282.  
  6283.    Create a sequence of numbers using the "Blum Blum Shub" pseudo-random
  6284.    number generator:
  6285.  
  6286.                           s[0]   = 14025256
  6287.                           s[n+1] = s[n]^2 mod 20300713
  6288.  
  6289.    Concatenate these numbers  s[0]s[1]s[2]… to create a string w of infinite
  6290.    length.
  6291.    Then, w = 14025256741014958470038053646…
  6292.  
  6293.    For a positive integer k, if no substring of w exists with a sum of digits
  6294.    equal to k, p(k) is defined to be zero. If at least one substring of w
  6295.    exists with a sum of digits equal to k, we define p(k) = z, where z is the
  6296.    starting position of the earliest such substring.
  6297.  
  6298.    For instance:
  6299.  
  6300.    The substrings 1, 14, 1402, …
  6301.    with respective sums of digits equal to 1, 5, 7, …
  6302.    start at position 1, hence p(1) = p(5) = p(7) = … = 1.
  6303.  
  6304.    The substrings 4, 402, 4025, …
  6305.    with respective sums of digits equal to 4, 6, 11, …
  6306.    start at position 2, hence p(4) = p(6) = p(11) = … = 2.
  6307.  
  6308.    The substrings 02, 0252, …
  6309.    with respective sums of digits equal to 2, 9, …
  6310.    start at position 3, hence p(2) = p(9) = … = 3.
  6311.  
  6312.    Note that substring 025 starting at position 3, has a sum of digits equal
  6313.    to 7, but there was an earlier substring (starting at position 1) with a
  6314.    sum of digits equal to 7, so p(7) = 1, not 3.
  6315.  
  6316.    We can verify that, for 0 < k ≤ 10^3, ∑ p(k) = 4742.
  6317.  
  6318.    Find ∑ p(k), for 0 < k ≤ 2·10^15.
  6319.  
  6320.    
  6321.    Answer: 424ed6613a372ccb9a90dddb8961ca16
  6322.  
  6323.  
  6324. Problem 239
  6325. ===========
  6326.  
  6327.  
  6328.    A set of disks numbered 1 through 100 are placed in a line in random
  6329.    order.
  6330.  
  6331.    What is the probability that we have a partial derangement such that
  6332.    exactly 22 prime number discs are found away from their natural positions?
  6333.    (Any number of non-prime disks may also be found in or out of their
  6334.    natural positions.)
  6335.  
  6336.    Give your answer rounded to 12 places behind the decimal point in the form
  6337.    0.abcdefghijkl.
  6338.  
  6339.    
  6340.    Answer: 451fd2b8c19fbfec650a5c4699f6ef6e
  6341.  
  6342.  
  6343. Problem 240
  6344. ===========
  6345.  
  6346.  
  6347.    There are 1111 ways in which five 6-sided dice (sides numbered 1 to 6) can
  6348.    be rolled so that the top three sum to 15. Some examples are:
  6349.  
  6350.    D[1],D[2],D[3],D[4],D[5] = 4,3,6,3,5
  6351.    D[1],D[2],D[3],D[4],D[5] = 4,3,3,5,6
  6352.    D[1],D[2],D[3],D[4],D[5] = 3,3,3,6,6
  6353.    D[1],D[2],D[3],D[4],D[5] = 6,6,3,3,3
  6354.  
  6355.    In how many ways can twenty 12-sided dice (sides numbered 1 to 12) be
  6356.    rolled so that the top ten sum to 70?
  6357.  
  6358.    
  6359.    Answer: cb31a3106db3876e77cd160664cd683e
  6360.  
  6361.  
  6362. Problem 241
  6363. ===========
  6364.  
  6365.  
  6366.    For a positive integer n, let σ(n) be the sum of all divisors of n, so
  6367.    e.g. σ(6) = 1 + 2 + 3 + 6 = 12.
  6368.  
  6369.    A perfect number, as you probably know, is a number with σ(n) = 2n.
  6370.  
  6371.    Let us define the perfection quotient of a positive integer p(n) =  σ(n) .
  6372.    as                                                                   n
  6373.  
  6374.    Find the sum of all positive integers n ≤ 10^18 for which p(n) has the
  6375.    form k + ^1⁄[2], where k is an integer.
  6376.  
  6377.    
  6378.    Answer: 556bfef2cacd1eff8af9126c5c13dcbc
  6379.  
  6380.  
  6381. Problem 242
  6382. ===========
  6383.  
  6384.  
  6385.    Given the set {1,2,...,n}, we define f(n,k) as the number of its k-element
  6386.    subsets with an odd sum of elements. For example, f(5,3) = 4, since the
  6387.    set {1,2,3,4,5} has four 3-element subsets having an odd sum of elements,
  6388.    i.e.: {1,2,4}, {1,3,5}, {2,3,4} and {2,4,5}.
  6389.  
  6390.    When all three values n, k and f(n,k) are odd, we say that they make
  6391.    an odd-triplet [n,k,f(n,k)].
  6392.  
  6393.    There are exactly five odd-triplets with n ≤ 10, namely:
  6394.    [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
  6395.    [9,9,f(9,9) = 1].
  6396.  
  6397.    How many odd-triplets are there with n ≤ 10^12 ?
  6398.  
  6399.    
  6400.    Answer: ba73cb75365ddca8f94a23e3fedfb6de
  6401.  
  6402.  
  6403. Problem 243
  6404. ===========
  6405.  
  6406.  
  6407.    A positive fraction whose numerator is less than its denominator is called
  6408.    a proper fraction.
  6409.    For any denominator, d, there will be d−1 proper fractions; for example,
  6410.    with d = 12:
  6411.    1/12 , 2/12 , 3/12 , 4/12 , 5/12 , 6/12 , 7/12 ,
  6412.    8/12 , 9/12 , 10/12 , 11/12 .
  6413.  
  6414.    We shall call a fraction that cannot be cancelled down a resilient
  6415.    fraction.
  6416.    Furthermore we shall define the resilience of a denominator, R(d), to be
  6417.    the ratio of its proper fractions that are resilient; for example, R(12) =
  6418.    4/11 .
  6419.    In fact, d = 12 is the smallest denominator having a resilience R(d) <
  6420.    4/10 .
  6421.  
  6422.    Find the smallest denominator d, having a resilience R(d) < 15499/94744
  6423.    .
  6424.  
  6425.    
  6426.    Answer: 531721a10786c5c2a444b474fcf039f9
  6427.  
  6428.  
  6429. Problem 244
  6430. ===========
  6431.  
  6432.  
  6433.    You probably know the game Fifteen Puzzle. Here, instead of numbered
  6434.    tiles, we have seven red tiles and eight blue tiles.
  6435.  
  6436.    A move is denoted by the uppercase initial of the direction (Left, Right,
  6437.    Up, Down) in which the tile is slid, e.g. starting from configuration (S),
  6438.    by the sequence LULUR we reach the configuration (E):
  6439.  
  6440.                   (S)                   , (E)
  6441.  
  6442.    For each path, its checksum is calculated by (pseudocode):
  6443.    checksum = 0
  6444.    checksum = (checksum × 243 + m[1]) mod 100 000 007
  6445.    checksum = (checksum × 243 + m[2]) mod 100 000 007
  6446.       …
  6447.    checksum = (checksum × 243 + m[n]) mod 100 000 007
  6448.    where m[k] is the ASCII value of the k^th letter in the move sequence and
  6449.                       the ASCII values for the moves are:
  6450.  
  6451.                                  ┌──────┬─────┐
  6452.                                  │L     │76   │
  6453.                                  ├──────┼─────┤
  6454.                                  │R     │82   │
  6455.                                  ├──────┼─────┤
  6456.                                  │U     │85   │
  6457.                                  ├──────┼─────┤
  6458.                                  │D     │68   │
  6459.                                  └──────┴─────┘
  6460.  
  6461.    For the sequence LULUR given above, the checksum would be 19761398.
  6462.  
  6463.    Now, starting from configuration (S),find all shortest ways to reach
  6464.    configuration (T).
  6465.  
  6466.                   (S)                   , (T)
  6467.  
  6468.    What is the sum of all checksums for the paths having the minimal length?
  6469.  
  6470.    
  6471.    p_244_start.gif
  6472.    p_244_example.gif
  6473.    p_244_start.gif
  6474.    p_244_target.gif
  6475.    Answer: 96356848
  6476.  
  6477.  
  6478. Problem 245
  6479. ===========
  6480.  
  6481.  
  6482.    We shall call a fraction that cannot be cancelled down a resilient
  6483.    fraction.
  6484.    Furthermore we shall define the resilience of a denominator, R(d), to be
  6485.    the ratio of its proper fractions that are resilient; for example, R(12) =
  6486.    ^4⁄[11].
  6487.  
  6488.    The resilience of a number d > 1 is     φ(d)  , where φ is Euler's totient
  6489.    then                                    d - 1 function.
  6490.  
  6491.    We further define the coresilience of a number n > 1 as C(n) =  n - φ(n) .
  6492.                                                                     n - 1
  6493.  
  6494.    The coresilience of a prime p is C(p) =    1   .
  6495.                                             p - 1
  6496.  
  6497.    Find the sum of all composite integers 1 < n ≤ 2×10^11, for which C(n) is
  6498.    a unit fraction.
  6499.  
  6500.    
  6501.    Answer: 0ebeb502fb0bd7157609835d27c266bc
  6502.  
  6503.  
  6504. Problem 246
  6505. ===========
  6506.  
  6507.  
  6508.    A definition for an ellipse is:
  6509.    Given a circle c with centre M and radius r and a point G such that
  6510.    d(G,M)<r, the locus of the points that are equidistant from c and G form
  6511.    an ellipse.
  6512.  
  6513.          The construction of the points of the ellipse is shown below.
  6514.  
  6515.    Given are the points M(-2000,1500) and G(8000,1500).
  6516.    Given is also the circle c with centre M and radius 15000.
  6517.    The locus of the points that are equidistant from G and c form an ellipse
  6518.    e.
  6519.    From a point P outside e the two tangents t[1] and t[2] to the ellipse are
  6520.    drawn.
  6521.    Let the points where t[1] and t[2] touch the ellipse be R and S.
  6522.  
  6523.    For how many lattice points P is angle RPS greater than 45 degrees?
  6524.  
  6525.    
  6526.    p_246_anim.gif
  6527.    p_246_ellipse.gif
  6528.    Answer: 94c521ffeb906391d161b66fec433827
  6529.  
  6530.  
  6531. Problem 247
  6532. ===========
  6533.  
  6534.  
  6535.    Consider the region constrained by 1 ≤ x and 0 ≤ y ≤ ^1/[x].
  6536.  
  6537.    Let S[1] be the largest square that can fit under the curve.
  6538.    Let S[2] be the largest square that fits in the remaining area, and so on.
  6539.    Let the index of S[n] be the pair (left, below) indicating the number of
  6540.    squares to the left of S[n] and the number of squares below S[n].
  6541.  
  6542.    The diagram shows some such squares labelled by number.
  6543.    S[2] has one square to its left and none below, so the index of S[2] is
  6544.    (1,0).
  6545.    It can be seen that the index of S[32] is (1,1) as is the index of S[50].
  6546.    50 is the largest n for which the index of S[n] is (1,1).
  6547.  
  6548.    What is the largest n for which the index of S[n] is (3,3)?
  6549.  
  6550.    
  6551.    p_247_hypersquares.gif
  6552.    Answer: 782252
  6553.  
  6554.  
  6555. Problem 248
  6556. ===========
  6557.  
  6558.  
  6559.    The first number n for which φ(n)=13! is 6227180929.
  6560.  
  6561.    Find the 150,000^th such number.
  6562.  
  6563.    
  6564.    Answer: b69a3ba674f6c7c5f2ce244f9e9cc873
  6565.  
  6566.  
  6567. Problem 249
  6568. ===========
  6569.  
  6570.  
  6571.    Let S = {2, 3, 5, ..., 4999} be the set of prime numbers less than 5000.
  6572.  
  6573.    Find the number of subsets of S, the sum of whose elements is a prime
  6574.    number.
  6575.    Enter the rightmost 16 digits as your answer.
  6576.  
  6577.    
  6578.    Answer: a470ee3ca52f2b68d7034e48b39b8b26
  6579.  
  6580.  
  6581. Problem 250
  6582. ===========
  6583.  
  6584.  
  6585.    Find the number of non-empty subsets of {1^1, 2^2, 3^3,...,
  6586.    250250^250250}, the sum of whose elements is divisible by 250. Enter the
  6587.    rightmost 16 digits as your answer.
  6588.  
  6589.    
  6590.    Answer: 4a5614f3700956273fe0d271f921d5f4
  6591.  
  6592.  
  6593. Problem 251
  6594. ===========
  6595.  
  6596.  
  6597.    A triplet of positive integers (a,b,c) is called a Cardano Triplet if it
  6598.    satisfies the condition:
  6599.  
  6600.    For example, (2,1,5) is a Cardano Triplet.
  6601.  
  6602.    There exist 149 Cardano Triplets for which a+b+c ≤ 1000.
  6603.  
  6604.    Find how many Cardano Triplets exist such that a+b+c ≤ 110,000,000.
  6605.  
  6606.    
  6607.    p_251_cardano.gif
  6608.    Answer: 18946051
  6609.  
  6610.  
  6611. Problem 252
  6612. ===========
  6613.  
  6614.  
  6615.    Given a set of points on a plane, we define a convex hole to be a convex
  6616.    polygon having as vertices any of the given points and not containing any
  6617.    of the given points in its interior (in addition to the vertices, other
  6618.    given points may lie on the perimeter of the polygon).
  6619.  
  6620.    As an example, the image below shows a set of twenty points and a few such
  6621.    convex holes. The convex hole shown as a red heptagon has an area equal to
  6622.    1049694.5 square units, which is the highest possible area for a convex
  6623.    hole on the given set of points.
  6624.  
  6625.    For our example, we used the first 20 points (T[2k−1], T[2k]), for
  6626.    k = 1,2,…,20, produced with the pseudo-random number generator:
  6627.  
  6628.                      S[0]   =[ ] 290797[ ]
  6629.                      S[n+1] =[ ] S[n]^2 mod 50515093
  6630.                      T[n]   =[ ] ( S[n] mod 2000 ) − 1000^ 
  6631.  
  6632.    i.e. (527, 144), (−488, 732), (−454, −947), …
  6633.  
  6634.    What is the maximum area for a convex hole on the set containing the first
  6635.    500 points in the pseudo-random sequence?
  6636.    Specify your answer including one digit after the decimal point.
  6637.  
  6638.    
  6639.    p_252_convexhole.gif
  6640.    Answer: 53b1ced82e1b588d756750c4d2f77e0d
  6641.  
  6642.  
  6643. Problem 253
  6644. ===========
  6645.  
  6646.  
  6647.    A small child has a “number caterpillar” consisting of forty jigsaw
  6648.    pieces, each with one number on it, which, when connected together in a
  6649.    line, reveal the numbers 1 to 40 in order.
  6650.  
  6651.    Every night, the child's father has to pick up the pieces of the
  6652.    caterpillar that have been scattered across the play room. He picks up the
  6653.    pieces at random and places them in the correct order.
  6654.    As the caterpillar is built up in this way, it forms distinct segments
  6655.    that gradually merge together.
  6656.    The number of segments starts at zero (no pieces placed), generally
  6657.    increases up to about eleven or twelve, then tends to drop again before
  6658.    finishing at a single segment (all pieces placed).
  6659.  
  6660.    For example:
  6661.  
  6662.                          ┌────────────┬───────────────┐
  6663.                          │Piece Placed│Segments So Far│
  6664.                          ├────────────┼───────────────┤
  6665.                          │     12     │       1       │
  6666.                          ├────────────┼───────────────┤
  6667.                          │     4      │       2       │
  6668.                          ├────────────┼───────────────┤
  6669.                          │     29     │       3       │
  6670.                          ├────────────┼───────────────┤
  6671.                          │     6      │       4       │
  6672.                          ├────────────┼───────────────┤
  6673.                          │     34     │       5       │
  6674.                          ├────────────┼───────────────┤
  6675.                          │     5      │       4       │
  6676.                          ├────────────┼───────────────┤
  6677.                          │     35     │       4       │
  6678.                          ├────────────┼───────────────┤
  6679.                          │     …      │       …       │
  6680.                          └────────────┴───────────────┘
  6681.  
  6682.    Let M be the maximum number of segments encountered during a random
  6683.    tidy-up of the caterpillar.
  6684.    For a caterpillar of ten pieces, the number of possibilities for each M is
  6685.  
  6686.                             ┌────────┬─────────────┐
  6687.                             │   M    │Possibilities│
  6688.                             ├────────┼─────────────┤
  6689.                             │   1    │    512      │
  6690.                             ├────────┼─────────────┤
  6691.                             │   2    │ 250912      │
  6692.                             ├────────┼─────────────┤
  6693.                             │   3    │1815264      │
  6694.                             ├────────┼─────────────┤
  6695.                             │   4    │1418112      │
  6696.                             ├────────┼─────────────┤
  6697.                             │   5    │ 144000      │
  6698.                             └────────┴─────────────┘
  6699.  
  6700.    so the most likely value of M is 3 and the average value is
  6701.    ^385643⁄[113400] = 3.400732, rounded to six decimal places.
  6702.  
  6703.    The most likely value of M for a forty-piece caterpillar is 11; but what
  6704.    is the average value of M?
  6705.  
  6706.    Give your answer rounded to six decimal places.
  6707.  
  6708.    
  6709.    Answer: 228de0a37019fd7c7051029f3d126422
  6710.  
  6711.  
  6712. Problem 254
  6713. ===========
  6714.  
  6715.  
  6716.    Define f(n) as the sum of the factorials of the digits of n. For example,
  6717.    f(342) = 3! + 4! + 2! = 32.
  6718.  
  6719.    Define sf(n) as the sum of the digits of f(n). So sf(342) = 3 + 2 = 5.
  6720.  
  6721.    Define g(i) to be the smallest positive integer n such that sf(n) = i.
  6722.    Though sf(342) is 5, sf(25) is also 5, and it can be verified that g(5) is
  6723.    25.
  6724.  
  6725.    Define sg(i) as the sum of the digits of g(i). So sg(5) = 2 + 5 = 7.
  6726.  
  6727.    Further, it can be verified that g(20) is 267 and ∑ sg(i) for 1 ≤ i ≤ 20
  6728.    is 156.
  6729.  
  6730.    What is ∑ sg(i) for 1 ≤ i ≤ 150?
  6731.  
  6732.    
  6733.    Answer: 936014adf2de65d41979ad900325e485
  6734.  
  6735.  
  6736. Problem 255
  6737. ===========
  6738.  
  6739.  
  6740.    We define the rounded-square-root of a positive integer n as the square
  6741.    root of n rounded to the nearest integer.
  6742.  
  6743.    The following procedure (essentially Heron's method adapted to integer
  6744.    arithmetic) finds the rounded-square-root of n:
  6745.  
  6746.    Let d be the number of digits of the number n.
  6747.    If d is odd, set x[0] = 2×10^(d-1)⁄2.
  6748.    If d is even, set x[0] = 7×10^(d-2)⁄2.
  6749.    Repeat:
  6750.  
  6751.    until x[k+1] = x[k].
  6752.  
  6753.    As an example, let us find the rounded-square-root of n = 4321.
  6754.    n has 4 digits, so x[0] = 7×10^(4-2)⁄2 = 70.
  6755.    Since x[2] = x[1], we stop here.
  6756.    So, after just two iterations, we have found that the rounded-square-root
  6757.    of 4321 is 66 (the actual square root is 65.7343137…).
  6758.  
  6759.    The number of iterations required when using this method is surprisingly
  6760.    low.
  6761.    For example, we can find the rounded-square-root of a 5-digit integer
  6762.    (10,000 ≤ n ≤ 99,999) with an average of 3.2102888889 iterations (the
  6763.    average value was rounded to 10 decimal places).
  6764.  
  6765.    Using the procedure described above, what is the average number of
  6766.    iterations required to find the rounded-square-root of a 14-digit number
  6767.    (10^13 ≤ n < 10^14)?
  6768.    Give your answer rounded to 10 decimal places.
  6769.  
  6770.    Note: The symbols ⌊x⌋ and ⌈x⌉ represent the floor function and ceiling
  6771.    function respectively.
  6772.  
  6773.    
  6774.    p_255_Heron.gif
  6775.    p_255_Example.gif
  6776.    Answer: 12be028b156b49faa1137febda940ab5
  6777.  
  6778.  
  6779. Problem 256
  6780. ===========
  6781.  
  6782.  
  6783.    Tatami are rectangular mats, used to completely cover the floor of a room,
  6784.    without overlap.
  6785.  
  6786.    Assuming that the only type of available tatami has dimensions 1×2, there
  6787.    are obviously some limitations for the shape and size of the rooms that
  6788.    can be covered.
  6789.  
  6790.    For this problem, we consider only rectangular rooms with integer
  6791.    dimensions a, b and even size s = a·b.
  6792.    We use the term 'size' to denote the floor surface area of the room, and —
  6793.    without loss of generality — we add the condition a ≤ b.
  6794.  
  6795.    There is one rule to follow when laying out tatami: there must be no
  6796.    points where corners of four different mats meet.
  6797.    For example, consider the two arrangements below for a 4×4 room:
  6798.  
  6799.    The arrangement on the left is acceptable, whereas the one on the right is
  6800.    not: a red "X" in the middle, marks the point where four tatami meet.
  6801.  
  6802.    Because of this rule, certain even-sized rooms cannot be covered with
  6803.    tatami: we call them tatami-free rooms.
  6804.    Further, we define T(s) as the number of tatami-free rooms of size s.
  6805.  
  6806.    The smallest tatami-free room has size s = 70 and dimensions 7×10.
  6807.    All the other rooms of size s = 70 can be covered with tatami; they are:
  6808.    1×70, 2×35 and 5×14.
  6809.    Hence, T(70) = 1.
  6810.  
  6811.    Similarly, we can verify that T(1320) = 5 because there are exactly 5
  6812.    tatami-free rooms of size s = 1320:
  6813.    20×66, 22×60, 24×55, 30×44 and 33×40.
  6814.    In fact, s = 1320 is the smallest room-size s for which T(s) = 5.
  6815.  
  6816.    Find the smallest room-size s for which T(s) = 200.
  6817.  
  6818.    
  6819.    p_256_tatami3.gif
  6820.    Answer: 85765680
  6821.  
  6822.  
  6823. Problem 257
  6824. ===========
  6825.  
  6826.  
  6827.    Given is an integer sided triangle ABC with sides a ≤ b ≤ c. (AB = c, BC =
  6828.    a and AC = b).
  6829.    The angular bisectors of the triangle intersect the sides at points E, F
  6830.    and G (see picture below).
  6831.  
  6832.    The segments EF, EG and FG partition the triangle ABC into four smaller
  6833.    triangles: AEG, BFE, CGF and EFG.
  6834.    It can be proven that for each of these four triangles the ratio
  6835.    area(ABC)/area(subtriangle) is rational.
  6836.    However, there exist triangles for which some or all of these ratios are
  6837.    integral.
  6838.  
  6839.    How many triangles ABC with perimeter≤100,000,000 exist so that the ratio
  6840.    area(ABC)/area(AEG) is integral?
  6841.  
  6842.    
  6843.    p_257_bisector.gif
  6844.    Answer: 139012411
  6845.  
  6846.  
  6847. Problem 258
  6848. ===========
  6849.  
  6850.  
  6851.    A sequence is defined as:
  6852.  
  6853.      • g[k] = 1, for 0 ≤ k ≤ 1999
  6854.      • g[k] = g[k-2000] + g[k-1999], for k ≥ 2000.
  6855.  
  6856.    Find g[k] mod 20092010 for k = 10^18.
  6857.  
  6858.    
  6859.    Answer: 12747994
  6860.  
  6861.  
  6862. Problem 259
  6863. ===========
  6864.  
  6865.  
  6866.    A positive integer will be called reachable if it can result from an
  6867.    arithmetic expression obeying the following rules:
  6868.  
  6869.      • Uses the digits 1 through 9, in that order and exactly once each.
  6870.      • Any successive digits can be concatenated (for example, using the
  6871.        digits 2, 3 and 4 we obtain the number 234).
  6872.      • Only the four usual binary arithmetic operations (addition,
  6873.        subtraction, multiplication and division) are allowed.
  6874.      • Each operation can be used any number of times, or not at all.
  6875.      • Unary minus is not allowed.
  6876.      • Any number of (possibly nested) parentheses may be used to define the
  6877.        order of operations.
  6878.  
  6879.    For example, 42 is reachable, since (1/23) * ((4*5)-6) * (78-9) = 42.
  6880.  
  6881.    What is the sum of all positive reachable integers?
  6882.  
  6883.    
  6884.    Answer: 771828a57c269d873335c9091af78f76
  6885.  
  6886.  
  6887. Problem 260
  6888. ===========
  6889.  
  6890.  
  6891.    A game is played with three piles of stones and two players.
  6892.    At her turn, a player removes one or more stones from the piles. However,
  6893.    if she takes stones from more than one pile, she must remove the same
  6894.    number of stones from each of the selected piles.
  6895.  
  6896.    In other words, the player chooses some N>0 and removes:
  6897.  
  6898.      • N stones from any single pile; or
  6899.      • N stones from each of any two piles (2N total); or
  6900.      • N stones from each of the three piles (3N total).
  6901.  
  6902.    The player taking the last stone(s) wins the game.
  6903.  
  6904.    A winning configuration is one where the first player can force a win.
  6905.    For example, (0,0,13), (0,11,11) and (5,5,5) are winning configurations
  6906.    because the first player can immediately remove all stones.
  6907.  
  6908.    A losing configuration is one where the second player can force a win, no
  6909.    matter what the first player does.
  6910.    For example, (0,1,2) and (1,3,3) are losing configurations: any legal move
  6911.    leaves a winning configuration for the second player.
  6912.  
  6913.    Consider all losing configurations (x[i],y[i],z[i]) where x[i] ≤ y[i] ≤
  6914.    z[i] ≤ 100.
  6915.    We can verify that Σ(x[i]+y[i]+z[i]) = 173895 for these.
  6916.  
  6917.    Find Σ(x[i]+y[i]+z[i]) where (x[i],y[i],z[i]) ranges over the losing
  6918.    configurations
  6919.    with x[i] ≤ y[i] ≤ z[i] ≤ 1000.
  6920.  
  6921.    
  6922.    Answer: 167542057
  6923.  
  6924.  
  6925. Problem 261
  6926. ===========
  6927.  
  6928.  
  6929.    Let us call a positive integer k a square-pivot, if there is a pair of
  6930.    integers m > 0 and n ≥ k, such that the sum of the (m+1) consecutive
  6931.    squares up to k equals the sum of the m consecutive squares from (n+1) on:
  6932.  
  6933.                  (k-m)^2 + ... + k^2 = (n+1)^2 + ... + (n+m)^2.
  6934.  
  6935.    Some small square-pivots are
  6936.  
  6937.      • 4: 3^2 + 4^2 = 5^2
  6938.      • 21: 20^2 + 21^2 = 29^2
  6939.      • 24: 21^2 + 22^2 + 23^2 + 24^2 = 25^2 + 26^2 + 27^2
  6940.      • 110: 108^2 + 109^2 + 110^2 = 133^2 + 134^2
  6941.  
  6942.    Find the sum of all distinct square-pivots ≤ 10^10.
  6943.  
  6944.    
  6945.    Answer: d45ddf64010ed143228a6a6b84837de9
  6946.  
  6947.  
  6948. Problem 262
  6949. ===========
  6950.  
  6951.  
  6952.    The following equation represents the continuous topography of a
  6953.    mountainous region, giving the elevation h at any point (x,y):
  6954.  
  6955.    A mosquito intends to fly from A(200,200) to B(1400,1400), without leaving
  6956.    the area given by 0 ≤ x, y ≤ 1600.
  6957.  
  6958.    Because of the intervening mountains, it first rises straight up to a
  6959.    point A', having elevation f. Then, while remaining at the same elevation
  6960.    f, it flies around any obstacles until it arrives at a point B' directly
  6961.    above B.
  6962.  
  6963.    First, determine f[min] which is the minimum constant elevation allowing
  6964.    such a trip from A to B, while remaining in the specified area.
  6965.    Then, find the length of the shortest path between A' and B', while flying
  6966.    at that constant elevation f[min].
  6967.  
  6968.    Give that length as your answer, rounded to three decimal places.
  6969.  
  6970.    Note: For convenience, the elevation function shown above is repeated
  6971.    below, in a form suitable for most programming languages:
  6972.    h=( 5000-0.005*(x*x+y*y+x*y)+12.5*(x+y) ) * exp(
  6973.    -abs(0.000001*(x*x+y*y)-0.0015*(x+y)+0.7) )
  6974.  
  6975.    
  6976.    p_262_formula1.gif
  6977.    Answer: a5921e175a44d31e7f82f7f9a61a36af
  6978.  
  6979.  
  6980. Problem 263
  6981. ===========
  6982.  
  6983.  
  6984.    Consider the number 6. The divisors of 6 are: 1,2,3 and 6.
  6985.    Every number from 1 up to and including 6 can be written as a sum of
  6986.    distinct divisors of 6:
  6987.    1=1, 2=2, 3=1+2, 4=1+3, 5=2+3, 6=6.
  6988.    A number n is called a practical number if every number from 1 up to and
  6989.    including n can be expressed as a sum of distinct divisors of n.
  6990.  
  6991.    A pair of consecutive prime numbers with a difference of six is called a
  6992.    sexy pair (since "sex" is the Latin word for "six"). The first sexy pair
  6993.    is (23, 29).
  6994.  
  6995.    We may occasionally find a triple-pair, which means three consecutive sexy
  6996.    prime pairs, such that the second member of each pair is the first member
  6997.    of the next pair.
  6998.  
  6999.    We shall call a number n such that :
  7000.  
  7001.      • (n-9, n-3), (n-3,n+3), (n+3, n+9) form a triple-pair, and
  7002.      • the numbers n-8, n-4, n, n+4 and n+8 are all practical,
  7003.  
  7004.    an engineers’ paradise.
  7005.  
  7006.    Find the sum of the first four engineers’ paradises.
  7007.  
  7008.    
  7009.    Answer: 8fe3eb7196c69a080740e076cff9b4a1
  7010.  
  7011.  
  7012. Problem 264
  7013. ===========
  7014.  
  7015.  
  7016.    Consider all the triangles having:
  7017.  
  7018.      • All their vertices on lattice points.
  7019.      • Circumcentre at the origin O.
  7020.      • Orthocentre at the point H(5, 0).
  7021.  
  7022.    There are nine such triangles having a perimeter ≤ 50.
  7023.    Listed and shown in ascending order of their perimeter, they are:
  7024.  
  7025.    A(-4, 3), B(5, 0), C(4, -3)
  7026.    A(4, 3), B(5, 0), C(-4, -3)
  7027.    A(-3, 4), B(5, 0), C(3, -4)
  7028.  
  7029.    A(3, 4), B(5, 0), C(-3, -4)
  7030.    A(0, 5), B(5, 0), C(0, -5)
  7031.    A(1, 8), B(8, -1), C(-4, -7)
  7032.  
  7033.    A(8, 1), B(1, -8), C(-4, 7)
  7034.    A(2, 9), B(9, -2), C(-6, -7)
  7035.    A(9, 2), B(2, -9), C(-6, 7)
  7036.  
  7037.    The sum of their perimeters, rounded to four decimal places, is 291.0089.
  7038.  
  7039.    Find all such triangles with a perimeter ≤ 10^5.
  7040.    Enter as your answer the sum of their perimeters rounded to four decimal
  7041.    places.
  7042.  
  7043.    
  7044.    p_264_TriangleCentres.gif
  7045.    Answer: 287514a045a38be0a75a1786694c77ee
  7046.  
  7047.  
  7048. Problem 265
  7049. ===========
  7050.  
  7051.  
  7052.    2^N binary digits can be placed in a circle so that all the N-digit
  7053.    clockwise subsequences are distinct.
  7054.  
  7055.    For N=3, two such circular arrangements are possible, ignoring rotations:
  7056.  
  7057.    For the first arrangement, the 3-digit subsequences, in clockwise order,
  7058.    are:
  7059.    000, 001, 010, 101, 011, 111, 110 and 100.
  7060.  
  7061.    Each circular arrangement can be encoded as a number by concatenating the
  7062.    binary digits starting with the subsequence of all zeros as the most
  7063.    significant bits and proceeding clockwise. The two arrangements for N=3
  7064.    are thus represented as 23 and 29:
  7065.                                00010111 [2] = 23
  7066.                                00011101 [2] = 29
  7067.  
  7068.    Calling S(N) the sum of the unique numeric representations, we can see
  7069.    that S(3) = 23 + 29 = 52.
  7070.  
  7071.    Find S(5).
  7072.  
  7073.    
  7074.    p_265_BinaryCircles.gif
  7075.    Answer: c25cebbc8dce4bdcf96cb395a11afcc3
  7076.  
  7077.  
  7078. Problem 266
  7079. ===========
  7080.  
  7081.  
  7082.    The divisors of 12 are: 1,2,3,4,6 and 12.
  7083.    The largest divisor of 12 that does not exceed the square root of 12 is 3.
  7084.    We shall call the largest divisor of an integer n that does not exceed the
  7085.    square root of n the pseudo square root (PSR) of n.
  7086.    It can be seen that PSR(3102)=47.
  7087.  
  7088.    Let p be the product of the primes below 190.
  7089.    Find PSR(p) mod 10^16.
  7090.  
  7091.    
  7092.    Answer: 32da1d501e539ab509f104e2db68d57a
  7093.  
  7094.  
  7095. Problem 267
  7096. ===========
  7097.  
  7098.  
  7099.    You are given a unique investment opportunity.
  7100.  
  7101.    Starting with £1 of capital, you can choose a fixed proportion, f, of your
  7102.    capital to bet on a fair coin toss repeatedly for 1000 tosses.
  7103.  
  7104.    Your return is double your bet for heads and you lose your bet for tails.
  7105.  
  7106.    For example, if f = 1/4, for the first toss you bet £0.25, and if heads
  7107.    comes up you win £0.5 and so then have £1.5. You then bet £0.375 and if
  7108.    the second toss is tails, you have £1.125.
  7109.  
  7110.    Choosing f to maximize your chances of having at least £1,000,000,000
  7111.    after 1,000 flips, what is the chance that you become a billionaire?
  7112.  
  7113.    All computations are assumed to be exact (no rounding), but give your
  7114.    answer rounded to 12 digits behind the decimal point in the form
  7115.    0.abcdefghijkl.
  7116.  
  7117.    
  7118.    Answer: b8dd3306c2c64eacb0ac36b414892edb
  7119.  
  7120.  
  7121. Problem 268
  7122. ===========
  7123.  
  7124.  
  7125.    It can be verified that there are 23 positive integers less than 1000 that
  7126.    are divisible by at least four distinct primes less than 100.
  7127.  
  7128.    Find how many positive integers less than 10^16 are divisible by at least
  7129.    four distinct primes less than 100.
  7130.  
  7131.    
  7132.    Answer: 6f84b20c10311cb24a824416a3c3e0a4
  7133.  
  7134.  
  7135. Problem 269
  7136. ===========
  7137.  
  7138.  
  7139.    A root or zero of a polynomial P(x) is a solution to the equation P(x) =
  7140.    0.
  7141.    Define P[n] as the polynomial whose coefficients are the digits of n.
  7142.    For example, P[5703](x) = 5x^3 + 7x^2 + 3.
  7143.  
  7144.    We can see that:
  7145.  
  7146.      • P[n](0) is the last digit of n,
  7147.      • P[n](1) is the sum of the digits of n,
  7148.      • P[n](10) is n itself.
  7149.  
  7150.    Define Z(k) as the number of positive integers, n, not exceeding k for
  7151.    which the polynomial P[n] has at least one integer root.
  7152.  
  7153.    It can be verified that Z(100 000) is 14696.
  7154.  
  7155.    What is Z(10^16)?
  7156.  
  7157.    
  7158.    Answer: f7ba868cb52a9b9c7e58b1b92e230be8
  7159.  
  7160.  
  7161. Problem 270
  7162. ===========
  7163.  
  7164.  
  7165.    A square piece of paper with integer dimensions N×N is placed with a
  7166.    corner at the origin and two of its sides along the x- and y-axes. Then,
  7167.    we cut it up respecting the following rules:
  7168.  
  7169.      • We only make straight cuts between two points lying on different sides
  7170.        of the square, and having integer coordinates.
  7171.      • Two cuts cannot cross, but several cuts can meet at the same border
  7172.        point.
  7173.      • Proceed until no more legal cuts can be made.
  7174.  
  7175.    Counting any reflections or rotations as distinct, we call C(N) the number
  7176.    of ways to cut an N×N square. For example, C(1) = 2 and C(2) = 30 (shown
  7177.    below).
  7178.  
  7179.    What is C(30) mod 10^8 ?
  7180.  
  7181.    
  7182.    p_270_CutSquare.gif
  7183.    Answer: 82282080
  7184.  
  7185.  
  7186. Problem 271
  7187. ===========
  7188.  
  7189.  
  7190.    For a positive number n, define S(n) as the sum of the integers x, for
  7191.    which 1<x<n and
  7192.    x^3≡1 mod n.
  7193.  
  7194.    When n=91, there are 8 possible values for x, namely : 9, 16, 22, 29, 53,
  7195.    74, 79, 81.
  7196.    Thus, S(91)=9+16+22+29+53+74+79+81=363.
  7197.  
  7198.    Find S(13082761331670030).
  7199.  
  7200.    
  7201.    Answer: c4157aab542bd0dfa465c890e1286cc5
  7202.  
  7203.  
  7204. Problem 272
  7205. ===========
  7206.  
  7207.  
  7208.    For a positive number n, define C(n) as the number of the integers x, for
  7209.    which 1<x<n and
  7210.    x^3≡1 mod n.
  7211.  
  7212.    When n=91, there are 8 possible values for x, namely : 9, 16, 22, 29, 53,
  7213.    74, 79, 81.
  7214.    Thus, C(91)=8.
  7215.  
  7216.    Find the sum of the positive numbers n≤10^11 for which C(n)=242.
  7217.  
  7218.    
  7219.    Answer: d84d2020055b3e8867dc359e739e0312
  7220.  
  7221.  
  7222. Problem 273
  7223. ===========
  7224.  
  7225.  
  7226.    Consider equations of the form: a^2 + b^2 = N, 0 ≤ a ≤ b, a, b and N
  7227.    integer.
  7228.  
  7229.    For N=65 there are two solutions:
  7230.  
  7231.    a=1, b=8 and a=4, b=7.
  7232.  
  7233.    We call S(N) the sum of the values of a of all solutions of a^2 + b^2 = N,
  7234.    0 ≤ a ≤ b, a, b and N integer.
  7235.  
  7236.    Thus S(65) = 1 + 4 = 5.
  7237.  
  7238.    Find ∑S(N), for all squarefree N only divisible by primes of the form 4k+1
  7239.    with 4k+1 < 150.
  7240.  
  7241.    
  7242.    Answer: 2b03731e58e9d60e559ee5fdce4f0d14
  7243.  
  7244.  
  7245. Problem 274
  7246. ===========
  7247.  
  7248.  
  7249.    For each integer p > 1 coprime to 10 there is a positive divisibility
  7250.    multiplier m < p which preserves divisibility by p for the following
  7251.    function on any positive integer, n:
  7252.  
  7253.    f(n) = (all but the last digit of n) + (the last digit of n) * m
  7254.  
  7255.    That is, if m is the divisibility multiplier for p, then f(n) is divisible
  7256.    by p if and only if n is divisible by p.
  7257.  
  7258.    (When n is much larger than p, f(n) will be less than n and repeated
  7259.    application of f provides a multiplicative divisibility test for p.)
  7260.  
  7261.    For example, the divisibility multiplier for 113 is 34.
  7262.  
  7263.    f(76275) = 7627 + 5 * 34 = 7797 : 76275 and 7797 are both divisible by 113
  7264.    f(12345) = 1234 + 5 * 34 = 1404 : 12345 and 1404 are both not divisible by
  7265.    113
  7266.  
  7267.    The sum of the divisibility multipliers for the primes that are coprime to
  7268.    10 and less than 1000 is 39517. What is the sum of the divisibility
  7269.    multipliers for the primes that are coprime to 10 and less than 10^7?
  7270.  
  7271.    
  7272.    Answer: ffd68ca67b9c3ea2653d375051e70288
  7273.  
  7274.  
  7275. Problem 275
  7276. ===========
  7277.  
  7278.  
  7279.    Let us define a balanced sculpture of order n as follows:
  7280.  
  7281.      • A polyomino made up of n+1 tiles known as the blocks (n tiles)
  7282.        and the plinth (remaining tile);
  7283.      • the plinth has its centre at position (x = 0, y = 0);
  7284.      • the blocks have y-coordinates greater than zero (so the plinth is the
  7285.        unique lowest tile);
  7286.      • the centre of mass of all the blocks, combined, has x-coordinate equal
  7287.        to zero.
  7288.  
  7289.    When counting the sculptures, any arrangements which are simply
  7290.    reflections about the y-axis, are not counted as distinct. For example,
  7291.    the 18 balanced sculptures of order 6 are shown below; note that each pair
  7292.    of mirror images (about the y-axis) is counted as one sculpture:
  7293.  
  7294.    There are 964 balanced sculptures of order 10 and 360505 of order 15.
  7295.    How many balanced sculptures are there of order 18?
  7296.  
  7297.    
  7298.    p_275_sculptures2.gif
  7299.    Answer: 15030564
  7300.  
  7301.  
  7302. Problem 276
  7303. ===========
  7304.  
  7305.  
  7306.    Consider the triangles with integer sides a, b and c with a ≤ b ≤ c.
  7307.    An integer sided triangle (a,b,c) is called primitive if gcd(a,b,c)=1.
  7308.    How many primitive integer sided triangles exist with a perimeter not
  7309.    exceeding 10 000 000?
  7310.  
  7311.    
  7312.    Answer: 29ae64e74ebfdf459dac56786e95c5d5
  7313.  
  7314.  
  7315. Problem 277
  7316. ===========
  7317.  
  7318.  
  7319.    A modified Collatz sequence of integers is obtained from a starting value
  7320.    a[1] in the following way:
  7321.  
  7322.    a[n+1] = a[n]/3 if a[n] is divisible by 3. We shall denote this as a large
  7323.    downward step, "D".
  7324.  
  7325.    a[n+1] = (4a[n] + 2)/3 if a[n] divided by 3 gives a remainder of 1. We
  7326.    shall denote this as an upward step, "U".
  7327.  
  7328.    a[n+1] = (2a[n] - 1)/3 if a[n] divided by 3 gives a remainder of 2. We
  7329.    shall denote this as a small downward step, "d".
  7330.  
  7331.    The sequence terminates when some a[n] = 1.
  7332.  
  7333.    Given any integer, we can list out the sequence of steps.
  7334.    For instance if a[1]=231, then the sequence
  7335.    {a[n]}={231,77,51,17,11,7,10,14,9,3,1} corresponds to the steps
  7336.    "DdDddUUdDD".
  7337.  
  7338.    Of course, there are other sequences that begin with that same sequence
  7339.    "DdDddUUdDD....".
  7340.    For instance, if a[1]=1004064, then the sequence is
  7341.    DdDddUUdDDDdUDUUUdDdUUDDDUdDD.
  7342.    In fact, 1004064 is the smallest possible a[1] > 10^6 that begins with the
  7343.    sequence DdDddUUdDD.
  7344.  
  7345.    What is the smallest a[1] > 10^15 that begins with the sequence
  7346.    "UDDDUdddDDUDDddDdDddDDUDDdUUDd"?
  7347.  
  7348.    
  7349.    Answer: 9508afff135320c18d82c93a8b70cd11
  7350.  
  7351.  
  7352. Problem 278
  7353. ===========
  7354.  
  7355.  
  7356.    Given the values of integers 1 < a[1] < a[2] <... < a[n], consider the
  7357.    linear combination
  7358.    q[1]a[1] + q[2]a[2] + ... + q[n]a[n] = b, using only integer values q[k] ≥
  7359.    0.
  7360.  
  7361.    Note that for a given set of a[k], it may be that not all values of b are
  7362.    possible.
  7363.    For instance, if a[1] = 5 and a[2] = 7, there are no q[1] ≥ 0 and q[2] ≥ 0
  7364.    such that b could be
  7365.    1, 2, 3, 4, 6, 8, 9, 11, 13, 16, 18 or 23.
  7366.    In fact, 23 is the largest impossible value of b for a[1] = 5 and a[2] =
  7367.    7.
  7368.    We therefore call f(5, 7) = 23.
  7369.    Similarly, it can be shown that f(6, 10, 15)=29 and f(14, 22, 77) = 195.
  7370.  
  7371.    Find ∑ f(p*q,p*r,q*r), where p, q and r are prime numbers and p < q < r <
  7372.    5000.
  7373.  
  7374.    
  7375.    Answer: 7e680606b5e9890a19894dbdbbbd102a
  7376.  
  7377.  
  7378. Problem 279
  7379. ===========
  7380.  
  7381.  
  7382.    How many triangles are there with integral sides, at least one integral
  7383.    angle (measured in degrees), and a perimeter that does not exceed 10^8?
  7384.  
  7385.    
  7386.    Answer: 1f51455a8180fdeeb21285dfb6cba45f
  7387.  
  7388.  
  7389. Problem 280
  7390. ===========
  7391.  
  7392.  
  7393.    A laborious ant walks randomly on a 5x5 grid. The walk starts from the
  7394.    central square. At each step, the ant moves to an adjacent square at
  7395.    random, without leaving the grid; thus there are 2, 3 or 4 possible moves
  7396.    at each step depending on the ant's position.
  7397.  
  7398.    At the start of the walk, a seed is placed on each square of the lower
  7399.    row. When the ant isn't carrying a seed and reaches a square of the lower
  7400.    row containing a seed, it will start to carry the seed. The ant will drop
  7401.    the seed on the first empty square of the upper row it eventually reaches.
  7402.  
  7403.    What's the expected number of steps until all seeds have been dropped in
  7404.    the top row?
  7405.    Give your answer rounded to 6 decimal places.
  7406.  
  7407.    
  7408.    Answer: 27f07f04d1908e5ce4fa6eac09881cc2
  7409.  
  7410.  
  7411. Problem 281
  7412. ===========
  7413.  
  7414.  
  7415.    You are given a pizza (perfect circle) that has been cut into m·n equal
  7416.    pieces and you want to have exactly one topping on each slice.
  7417.  
  7418.    Let f(m,n) denote the number of ways you can have toppings on the pizza
  7419.    with m different toppings (m ≥ 2), using each topping on exactly n slices
  7420.    (n ≥ 1).
  7421.    Reflections are considered distinct, rotations are not.
  7422.  
  7423.    Thus, for instance, f(2,1) = 1, f(2,2) = f(3,1) = 2 and f(3,2) = 16.
  7424.    f(3,2) is shown below:
  7425.  
  7426.    Find the sum of all f(m,n) such that f(m,n) ≤ 10^15.
  7427.  
  7428.    
  7429.    p_281_pizza.gif
  7430.    Answer: ceee6ced9d64aad844310c8ce2aae2b7
  7431.  
  7432.  
  7433. Problem 282
  7434. ===========
  7435.  
  7436.  
  7437.    For non-negative integers m, n, the Ackermann function A(m, n) is defined
  7438.    as follows:
  7439.  
  7440.    For example A(1, 0) = 2, A(2, 2) = 7 and A(3, 4) = 125.
  7441.  
  7442.    Find A(n, n) and give your answer mod 14^8.
  7443.  
  7444.    
  7445.    p_282_formula.gif
  7446.    Answer: a1cc665e127af4e907e13087ee777bd5
  7447.  
  7448.  
  7449. Problem 283
  7450. ===========
  7451.  
  7452.  
  7453.    Consider the triangle with sides 6, 8 and 10. It can be seen that the
  7454.    perimeter and the area are both equal to 24. So the area/perimeter ratio
  7455.    is equal to 1.
  7456.    Consider also the triangle with sides 13, 14 and 15. The perimeter equals
  7457.    42 while the area is equal to 84. So for this triangle the area/perimeter
  7458.    ratio is equal to 2.
  7459.  
  7460.    Find the sum of the perimeters of all integer sided triangles for which
  7461.    the area/perimeter ratios are equal to positive integers not exceeding
  7462.    1000.
  7463.  
  7464.    
  7465.    Answer: 08afda4bc05c8f3ef71c9ffea1ddc0c8
  7466.  
  7467.  
  7468. Problem 284
  7469. ===========
  7470.  
  7471.  
  7472.    The 3-digit number 376 in the decimal numbering system is an example of
  7473.    numbers with the special property that its square ends with the same
  7474.    digits: 376^2 = 141376. Let's call a number with this property a steady
  7475.    square.
  7476.  
  7477.    Steady squares can also be observed in other numbering systems. In the
  7478.    base 14 numbering system, the 3-digit number c37 is also a steady square:
  7479.    c37^2 = aa0c37, and the sum of its digits is c+3+7=18 in the same
  7480.    numbering system. The letters a, b, c and d are used for the 10, 11, 12
  7481.    and 13 digits respectively, in a manner similar to the hexadecimal
  7482.    numbering system.
  7483.  
  7484.    For 1 ≤ n ≤ 9, the sum of the digits of all the n-digit steady squares in
  7485.    the base 14 numbering system is 2d8 (582 decimal). Steady squares with
  7486.    leading 0's are not allowed.
  7487.  
  7488.    Find the sum of the digits of all the n-digit steady squares in the base
  7489.    14 numbering system for
  7490.    1 ≤ n ≤ 10000 (decimal) and give your answer in the base 14 system using
  7491.    lower case letters where necessary.
  7492.  
  7493.    
  7494.    Answer: aff724582e583649876f518f9b340a69
  7495.  
  7496.  
  7497. Problem 285
  7498. ===========
  7499.  
  7500.  
  7501.    Albert chooses a positive integer k, then two real numbers a, b are
  7502.    randomly chosen in the interval [0,1] with uniform distribution.
  7503.    The square root of the sum (k·a+1)^2 + (k·b+1)^2 is then computed and
  7504.    rounded to the nearest integer. If the result is equal to k, he scores k
  7505.    points; otherwise he scores nothing.
  7506.  
  7507.    For example, if k = 6, a = 0.2 and b = 0.85, then
  7508.    (k·a+1)^2 + (k·b+1)^2 = 42.05.
  7509.    The square root of 42.05 is 6.484... and when rounded to the nearest
  7510.    integer, it becomes 6.
  7511.    This is equal to k, so he scores 6 points.
  7512.  
  7513.    It can be shown that if he plays 10 turns with k = 1, k = 2, ..., k = 10,
  7514.    the expected value of his total score, rounded to five decimal places, is
  7515.    10.20914.
  7516.  
  7517.    If he plays 10^5 turns with k = 1, k = 2, k = 3, ..., k = 10^5, what is
  7518.    the expected value of his total score, rounded to five decimal places?
  7519.  
  7520.    
  7521.    Answer: bbae95d0ce2999cae57782c3746aecb6
  7522.  
  7523.  
  7524. Problem 286
  7525. ===========
  7526.  
  7527.  
  7528.    Barbara is a mathematician and a basketball player. She has found that the
  7529.    probability of scoring a point when shooting from a distance x is exactly
  7530.    (1 - ^x/[q]), where q is a real constant greater than 50.
  7531.  
  7532.    During each practice run, she takes shots from distances x = 1, x = 2,
  7533.    ..., x = 50 and, according to her records, she has precisely a 2 % chance
  7534.    to score a total of exactly 20 points.
  7535.  
  7536.    Find q and give your answer rounded to 10 decimal places.
  7537.  
  7538.    
  7539.    Answer: cc5a1ef0deabf698733bcef4f1149498
  7540.  
  7541.  
  7542. Problem 287
  7543. ===========
  7544.  
  7545.  
  7546.    The quadtree encoding allows us to describe a 2^N×2^N black and white
  7547.    image as a sequence of bits (0 and 1). Those sequences are to be read from
  7548.    left to right like this:
  7549.  
  7550.      • the first bit deals with the complete 2^N×2^N region;
  7551.      • "0" denotes a split:
  7552.        the current 2^n×2^n region is divided into 4 sub-regions of dimension
  7553.        2^n-1×2^n-1,
  7554.        the next bits contains the description of the top left, top right,
  7555.        bottom left and bottom right sub-regions - in that order;
  7556.      • "10" indicates that the current region contains only black pixels;
  7557.      • "11" indicates that the current region contains only white pixels.
  7558.  
  7559.    Consider the following 4×4 image (colored marks denote places where a
  7560.    split can occur):
  7561.  
  7562.    This image can be described by several sequences, for example
  7563.    :"001010101001011111011010101010", of length 30, or
  7564.    "0100101111101110", of length 16, which is the minimal sequence for this
  7565.    image.
  7566.  
  7567.    For a positive integer N, define D[N] as the 2^N×2^N image with the
  7568.    following coloring scheme:
  7569.  
  7570.      • the pixel with coordinates x = 0, y = 0 corresponds to the bottom left
  7571.        pixel,
  7572.      • if (x - 2^N-1)^2 + (y - 2^N-1)^2 ≤ 2^2N-2 then the pixel is black,
  7573.      • otherwise the pixel is white.
  7574.  
  7575.    What is the length of the minimal sequence describing D[24] ?
  7576.  
  7577.    
  7578.    p_287_quadtree.gif
  7579.    Answer: 6c2beec8a6c0bc788d5e45c317b0d7ca
  7580.  
  7581.  
  7582. Problem 288
  7583. ===========
  7584.  
  7585.  
  7586.    For any prime p the number N(p,q) is defined byN(p,q) = ∑[n=0 to q]
  7587.    T[n]*p^n
  7588.    with T[n] generated by the following random number generator:
  7589.  
  7590.    S[0] = 290797
  7591.    S[n+1] = S[n]^2 mod 50515093
  7592.    T[n] = S[n] mod p
  7593.  
  7594.    Let Nfac(p,q) be the factorial of N(p,q).
  7595.    Let NF(p,q) be the number of factors p in Nfac(p,q).
  7596.  
  7597.    You are given that NF(3,10000) mod 3^20=624955285.
  7598.  
  7599.    Find NF(61,10^7) mod 61^10
  7600.  
  7601.    
  7602.    Answer: 192bf4aa33ea85e922d583f60fe99955
  7603.  
  7604.  
  7605. Problem 289
  7606. ===========
  7607.  
  7608.  
  7609.    Let C(x,y) be a circle passing through the points (x, y), (x, y+1),
  7610.    (x+1, y) and (x+1, y+1).
  7611.  
  7612.    For positive integers m and n, let E(m,n) be a configuration which
  7613.    consists of the m·n circles:
  7614.    { C(x,y): 0 ≤ x < m, 0 ≤ y < n, x and y are integers }
  7615.  
  7616.    An Eulerian cycle on E(m,n) is a closed path that passes through each arc
  7617.    exactly once.
  7618.    Many such paths are possible on E(m,n), but we are only interested in
  7619.    those which are not self-crossing: A non-crossing path just touches itself
  7620.    at lattice points, but it never crosses itself.
  7621.  
  7622.    The image below shows E(3,3) and an example of an Eulerian non-crossing
  7623.    path.
  7624.  
  7625.    Let L(m,n) be the number of Eulerian non-crossing paths on E(m,n).
  7626.    For example, L(1,2) = 2, L(2,2) = 37 and L(3,3) = 104290.
  7627.  
  7628.    Find L(6,10) mod 10^10.
  7629.  
  7630.    
  7631.    p_289_euler.gif
  7632.    Answer: 9fa32696df356b3d41faa7dd278c88a9
  7633.  
  7634.  
  7635. Problem 290
  7636. ===========
  7637.  
  7638.  
  7639.    How many integers 0 ≤ n < 10^18 have the property that the sum of the
  7640.    digits of n equals the sum of digits of 137n?
  7641.  
  7642.    
  7643.    Answer: 8246684fec8ece9f0ee3c9898c8c9d6a
  7644.  
  7645.  
  7646. Problem 291
  7647. ===========
  7648.  
  7649.  
  7650.    A prime number p is called a Panaitopol prime if for some positive
  7651.    integers
  7652.    x and y.
  7653.  
  7654.    Find how many Panaitopol primes are less than 5×10^15.
  7655.  
  7656.    
  7657.    p_291_formula.gif
  7658.    Answer: 4037526
  7659.  
  7660.  
  7661. Problem 292
  7662. ===========
  7663.  
  7664.  
  7665.    We shall define a pythagorean polygon to be a convex polygon with the
  7666.    following properties:
  7667.  
  7668.      • there are at least three vertices,
  7669.      • no three vertices are aligned,
  7670.      • each vertex has integer coordinates,
  7671.      • each edge has integer length.
  7672.  
  7673.    For a given integer n, define P(n) as the number of distinct pythagorean
  7674.    polygons for which the perimeter is ≤ n.
  7675.    Pythagorean polygons should be considered distinct as long as none is a
  7676.    translation of another.
  7677.  
  7678.    You are given that P(4) = 1, P(30) = 3655 and P(60) = 891045.
  7679.    Find P(120).
  7680.  
  7681.    
  7682.    Answer: 27f50f02ef10f170379b144435e0144b
  7683.  
  7684.  
  7685. Problem 293
  7686. ===========
  7687.  
  7688.  
  7689.    An even positive integer N will be called admissible, if it is a power of
  7690.    2 or its distinct prime factors are consecutive primes.
  7691.    The first twelve admissible numbers are 2,4,6,8,12,16,18,24,30,32,36,48.
  7692.  
  7693.    If N is admissible, the smallest integer M > 1 such that N+M is prime,
  7694.    will be called the pseudo-Fortunate number for N.
  7695.  
  7696.    For example, N=630 is admissible since it is even and its distinct prime
  7697.    factors are the consecutive primes 2,3,5 and 7.
  7698.    The next prime number after 631 is 641; hence, the pseudo-Fortunate number
  7699.    for 630 is M=11.
  7700.    It can also be seen that the pseudo-Fortunate number for 16 is 3.
  7701.  
  7702.    Find the sum of all distinct pseudo-Fortunate numbers for admissible
  7703.    numbers N less than 10^9.
  7704.  
  7705.    
  7706.    Answer: 2209
  7707.  
  7708.  
  7709. Problem 294
  7710. ===========
  7711.  
  7712.  
  7713.    For a positive integer k, define d(k) as the sum of the digits of k in its
  7714.    usual decimal representation.Thus d(42) = 4+2 = 6.
  7715.  
  7716.    For a positive integer n, define S(n) as the number of positive integers k
  7717.    < 10^n with the following properties :
  7718.  
  7719.      • k is divisible by 23 and
  7720.      • d(k) = 23.
  7721.  
  7722.    You are given that S(9) = 263626 and S(42) = 6377168878570056.
  7723.  
  7724.    Find S(11^12) and give your answer mod 10^9.
  7725.  
  7726.    
  7727.    Answer: aefe049404a284c7d27fab3887c6c4a2
  7728.  
  7729.  
  7730. Problem 295
  7731. ===========
  7732.  
  7733.  
  7734.    We call the convex area enclosed by two circles a lenticular hole if:
  7735.  
  7736.      • The centres of both circles are on lattice points.
  7737.      • The two circles intersect at two distinct lattice points.
  7738.      • The interior of the convex area enclosed by both circles does not
  7739.        contain any lattice points.
  7740.  
  7741.    Consider the circles:
  7742.    C[0]: x^2+y^2=25
  7743.    C[1]: (x+4)^2+(y-4)^2=1
  7744.    C[2]: (x-12)^2+(y-4)^2=65
  7745.  
  7746.    The circles C[0], C[1] and C[2] are drawn in the picture below.
  7747.  
  7748.    C[0] and C[1] form a lenticular hole, as well as C[0] and C[2].
  7749.  
  7750.    We call an ordered pair of positive real numbers (r[1], r[2]) a lenticular
  7751.    pair if there exist two circles with radii r[1] and r[2] that form a
  7752.    lenticular hole.We can verify that (1, 5) and (5, √65) are the lenticular
  7753.    pairs of the example above.
  7754.  
  7755.    Let L(N) be the number of distinct lenticular pairs (r[1], r[2]) for which
  7756.    0 < r[1] ≤ r[2] ≤ N.
  7757.    We can verify that L(10) = 30 and L(100) = 3442.
  7758.  
  7759.    Find L(100 000).
  7760.  
  7761.    
  7762.    Answer: 5beaace6425205fe879116ee07dae961
  7763.  
  7764.  
  7765. Problem 296
  7766. ===========
  7767.  
  7768.  
  7769.    Given is an integer sided triangle ABC with BC ≤ AC ≤ AB.
  7770.    k is the angular bisector of angle ACB.
  7771.    m is the tangent at C to the circumscribed circle of ABC.
  7772.    n is a line parallel to m through B.
  7773.    The intersection of n and k is called E.
  7774.  
  7775.    How many triangles ABC with a perimeter not exceeding 100 000 exist such
  7776.    that BE has integral length?
  7777.  
  7778.    
  7779.    Answer: 45986a4405b2dd6c163516319e0c4a1b
  7780.  
  7781.  
  7782. Problem 297
  7783. ===========
  7784.  
  7785.  
  7786.    Each new term in the Fibonacci sequence is generated by adding the
  7787.    previous two terms.
  7788.    Starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21,
  7789.    34, 55, 89.
  7790.  
  7791.    Every positive integer can be uniquely written as a sum of nonconsecutive
  7792.    terms of the Fibonacci sequence. For example, 100 = 3 + 8 + 89.
  7793.    Such a sum is called the Zeckendorf representation of the number.
  7794.  
  7795.    For any integer n>0, let z(n) be the number of terms in the Zeckendorf
  7796.    representation of n.
  7797.    Thus, z(5) = 1, z(14) = 2, z(100) = 3 etc.
  7798.    Also, for 0<n<10^6, ∑ z(n) = 7894453.
  7799.  
  7800.    Find ∑ z(n) for 0<n<10^17.
  7801.  
  7802.    
  7803.    Answer: d3fd75f5447698748a826562750a1986
  7804.  
  7805.  
  7806. Problem 298
  7807. ===========
  7808.  
  7809.  
  7810.    Larry and Robin play a memory game involving of a sequence of random
  7811.    numbers between 1 and 10, inclusive, that are called out one at a time.
  7812.    Each player can remember up to 5 previous numbers. When the called number
  7813.    is in a player's memory, that player is awarded a point. If it's not, the
  7814.    player adds the called number to his memory, removing another number if
  7815.    his memory is full.
  7816.  
  7817.    Both players start with empty memories. Both players always add new missed
  7818.    numbers to their memory but use a different strategy in deciding which
  7819.    number to remove:
  7820.    Larry's strategy is to remove the number that hasn't been called in the
  7821.    longest time.
  7822.    Robin's strategy is to remove the number that's been in the memory the
  7823.    longest time.
  7824.  
  7825.    Example game:
  7826.  
  7827.                Turn Called  Larry's   Larry's  Robin's   Robin's
  7828.                     number   memory    score    memory    score
  7829.                1    1      1          0       1          0
  7830.                2    2      1,2        0       1,2        0
  7831.                3    4      1,2,4      0       1,2,4      0
  7832.                4    6      1,2,4,6    0       1,2,4,6    0
  7833.                5    1      1,2,4,6    1       1,2,4,6    1
  7834.                6    8      1,2,4,6,8  1       1,2,4,6,8  1
  7835.                7    10     1,4,6,8,10 1       2,4,6,8,10 1
  7836.                8    2      1,2,6,8,10 1       2,4,6,8,10 2
  7837.                9    4      1,2,4,8,10 1       2,4,6,8,10 3
  7838.                10   1      1,2,4,8,10 2       1,4,6,8,10 3
  7839.  
  7840.    Denoting Larry's score by L and Robin's score by R, what is the expected
  7841.    value of |L-R| after 50 turns? Give your answer rounded to eight decimal
  7842.    places using the format x.xxxxxxxx .
  7843.  
  7844.    
  7845.    Answer: d078fd564995aa2a813a29f44ad79611
  7846.  
  7847.  
  7848. Problem 299
  7849. ===========
  7850.  
  7851.  
  7852.    Four points with integer coordinates are selected:
  7853.    A(a, 0), B(b, 0), C(0, c) and D(0, d), with 0 < a < b and 0 < c < d.
  7854.    Point P, also with integer coordinates, is chosen on the line AC so that
  7855.    the three triangles ABP, CDP and BDP are all similar.
  7856.  
  7857.    It is easy to prove that the three triangles can be similar, only if a=c.
  7858.  
  7859.    So, given that a=c, we are looking for triplets (a,b,d) such that at least
  7860.    one point P (with integer coordinates) exists on AC, making the three
  7861.    triangles ABP, CDP and BDP all similar.
  7862.  
  7863.    For example, if (a,b,d)=(2,3,4), it can be easily verified that point
  7864.    P(1,1) satisfies the above condition. Note that the triplets (2,3,4) and
  7865.    (2,4,3) are considered as distinct, although point P(1,1) is common for
  7866.    both.
  7867.  
  7868.    If b+d < 100, there are 92 distinct triplets (a,b,d) such that point P
  7869.    exists.
  7870.    If b+d < 100 000, there are 320471 distinct triplets (a,b,d) such that
  7871.    point P exists.
  7872.  
  7873.    If b+d < 100 000 000, how many distinct triplets (a,b,d) are there such
  7874.    that point P exists?
  7875.  
  7876.    
  7877.    p_299_ThreeSimTri.gif
  7878.    Answer: fb8f093361a6db56c8a1d1661ab229cd
  7879.  
  7880.  
  7881. Problem 300
  7882. ===========
  7883.  
  7884.  
  7885.    In a very simplified form, we can consider proteins as strings consisting
  7886.    of hydrophobic (H) and polar (P) elements, e.g. HHPPHHHPHHPH.
  7887.    For this problem, the orientation of a protein is important; e.g. HPP is
  7888.    considered distinct from PPH. Thus, there are 2^n distinct proteins
  7889.    consisting of n elements.
  7890.  
  7891.    When one encounters these strings in nature, they are always folded in
  7892.    such a way that the number of H-H contact points is as large as possible,
  7893.    since this is energetically advantageous.
  7894.    As a result, the H-elements tend to accumulate in the inner part, with the
  7895.    P-elements on the outside.
  7896.    Natural proteins are folded in three dimensions of course, but we will
  7897.    only consider protein folding in two dimensions.
  7898.  
  7899.    The figure below shows two possible ways that our example protein could be
  7900.    folded (H-H contact points are shown with red dots).
  7901.  
  7902.    The folding on the left has only six H-H contact points, thus it would
  7903.    never occur naturally.
  7904.    On the other hand, the folding on the right has nine H-H contact points,
  7905.    which is optimal for this string.
  7906.  
  7907.    Assuming that H and P elements are equally likely to occur in any position
  7908.    along the string, the average number of H-H contact points in an optimal
  7909.    folding of a random protein string of length 8 turns out to be
  7910.    850 / 2^8=3.3203125.
  7911.  
  7912.    What is the average number of H-H contact points in an optimal folding of
  7913.    a random protein string of length 15?
  7914.    Give your answer using as many decimal places as necessary for an exact
  7915.    result.
  7916.  
  7917.    
  7918.    p_300_protein.gif
  7919.    Answer: 5a0d6315bc18279c46a1fb8cbd2f16b5
  7920.  
  7921.  
  7922. Problem 301
  7923. ===========
  7924.  
  7925.  
  7926.    Nim is a game played with heaps of stones, where two players take it in
  7927.    turn to remove any number of stones from any heap until no stones remain.
  7928.  
  7929.    We'll consider the three-heap normal-play version of Nim, which works as
  7930.    follows:
  7931.    - At the start of the game there are three heaps of stones.
  7932.    - On his turn the player removes any positive number of stones from any
  7933.    single heap.
  7934.    - The first player unable to move (because no stones remain) loses.
  7935.  
  7936.    If (n[1],n[2],n[3]) indicates a Nim position consisting of heaps of size
  7937.    n[1], n[2] and n[3] then there is a simple function X(n[1],n[2],n[3]) —
  7938.    that you may look up or attempt to deduce for yourself — that returns:
  7939.  
  7940.      • zero if, with perfect strategy, the player about to move will
  7941.        eventually lose; or
  7942.      • non-zero if, with perfect strategy, the player about to move will
  7943.        eventually win.
  7944.  
  7945.    For example X(1,2,3) = 0 because, no matter what the current player does,
  7946.    his opponent can respond with a move that leaves two heaps of equal size,
  7947.    at which point every move by the current player can be mirrored by his
  7948.    opponent until no stones remain; so the current player loses. To
  7949.    illustrate:
  7950.    - current player moves to (1,2,1)
  7951.    - opponent moves to (1,0,1)
  7952.    - current player moves to (0,0,1)
  7953.    - opponent moves to (0,0,0), and so wins.
  7954.  
  7955.    For how many positive integers n ≤ 2^30 does X(n,2n,3n) = 0 ?
  7956.  
  7957.    
  7958.    Answer: 2178309
  7959.  
  7960.  
  7961. Problem 302
  7962. ===========
  7963.  
  7964.  
  7965.    A positive integer n is powerful if p^2 is a divisor of n for every prime
  7966.    factor p in n.
  7967.  
  7968.    A positive integer n is a perfect power if n can be expressed as a power
  7969.    of another positive integer.
  7970.  
  7971.    A positive integer n is an Achilles number if n is powerful but not a
  7972.    perfect power. For example, 864 and 1800 are Achilles numbers: 864 =
  7973.    2^5·3^3 and 1800 = 2^3·3^2·5^2.
  7974.  
  7975.    We shall call a positive integer S a Strong Achilles number if both S and
  7976.    φ(S) are Achilles numbers.^1
  7977.    For example, 864 is a Strong Achilles number: φ(864) = 288 = 2^5·3^2.
  7978.    However, 1800 isn't a Strong Achilles number because: φ(1800) = 480 =
  7979.    2^5·3^1·5^1.
  7980.  
  7981.    There are 7 Strong Achilles numbers below 10^4 and 656 below 10^8.
  7982.  
  7983.    How many Strong Achilles numbers are there below 10^18?
  7984.  
  7985.    ^1 φ denotes Euler's totient function.
  7986.  
  7987.    
  7988.    Answer: 1170060
  7989.  
  7990.  
  7991. Problem 303
  7992. ===========
  7993.  
  7994.  
  7995.    For a positive integer n, define f(n) as the least positive multiple of n
  7996.    that, written in base 10, uses only digits ≤ 2.
  7997.  
  7998.    Thus f(2)=2, f(3)=12, f(7)=21, f(42)=210, f(89)=1121222.
  7999.  
  8000.    Also, .
  8001.  
  8002.    Find .
  8003.  
  8004.    
  8005.    Answer: b904a0b3d922e628a828e744ee7d3a60
  8006.  
  8007.  
  8008. Problem 304
  8009. ===========
  8010.  
  8011.  
  8012.    For any positive integer n the function next_prime(n) returns the smallest
  8013.    prime p
  8014.    such that p>n.
  8015.  
  8016.    The sequence a(n) is defined by:
  8017.    a(1)=next_prime(10^14) and a(n)=next_prime(a(n-1)) for n>1.
  8018.  
  8019.    The fibonacci sequence f(n) is defined by:f(0)=0, f(1)=1 and
  8020.    f(n)=f(n-1)+f(n-2) for n>1.
  8021.  
  8022.    The sequence b(n) is defined as f(a(n)).
  8023.  
  8024.    Find ∑b(n) for 1≤n≤100 000. Give your answer mod 1234567891011.
  8025.  
  8026.    
  8027.    Answer: 499427a3e4bf9ad34a6df3056604b4c1
  8028.  
  8029.  
  8030. Problem 305
  8031. ===========
  8032.  
  8033.  
  8034.    Let's call S the (infinite) string that is made by concatenating the
  8035.    consecutive positive integers (starting from 1) written down in base 10.
  8036.    Thus, S = 1234567891011121314151617181920212223242...
  8037.  
  8038.    It's easy to see that any number will show up an infinite number of times
  8039.    in S.
  8040.  
  8041.    Let's call f(n) the starting position of the n^th occurrence of n in S.
  8042.    For example, f(1)=1, f(5)=81, f(12)=271 and f(7780)=111111365.
  8043.  
  8044.    Find ∑f(3^k) for 1≤k≤13.
  8045.  
  8046.    
  8047.    Answer: 9def85298f598867d361e4afca8cdd96
  8048.  
  8049.  
  8050. Problem 306
  8051. ===========
  8052.  
  8053.  
  8054.    The following game is a classic example of Combinatorial Game Theory:
  8055.  
  8056.    Two players start with a strip of n white squares and they take alternate
  8057.    turns.
  8058.    On each turn, a player picks two contiguous white squares and paints them
  8059.    black.
  8060.    The first player who cannot make a move loses.
  8061.  
  8062.      • If n = 1, there are no valid moves, so the first player loses
  8063.        automatically.
  8064.      • If n = 2, there is only one valid move, after which the second player
  8065.        loses.
  8066.      • If n = 3, there are two valid moves, but both leave a situation where
  8067.        the second player loses.
  8068.      • If n = 4, there are three valid moves for the first player; she can
  8069.        win the game by painting the two middle squares.
  8070.      • If n = 5, there are four valid moves for the first player (shown below
  8071.        in red); but no matter what she does, the second player (blue) wins.
  8072.  
  8073.    So, for 1 ≤ n ≤ 5, there are 3 values of n for which the first player can
  8074.    force a win.
  8075.    Similarly, for 1 ≤ n ≤ 50, there are 40 values of n for which the first
  8076.    player can force a win.
  8077.  
  8078.    For 1 ≤ n ≤ 1 000 000, how many values of n are there for which the first
  8079.    player can force a win?
  8080.  
  8081.    
  8082.    p_306_pstrip.gif
  8083.    Answer: 852938
  8084.  
  8085.  
  8086. Problem 307
  8087. ===========
  8088.  
  8089.  
  8090.    k defects are randomly distributed amongst n integrated-circuit chips
  8091.    produced by a factory (any number of defects may be found on a chip and
  8092.    each defect is independent of the other defects).
  8093.  
  8094.    Let p(k,n) represent the probability that there is a chip with at least 3
  8095.    defects.
  8096.    For instance p(3,7) ≈ 0.0204081633.
  8097.  
  8098.    Find p(20 000, 1 000 000) and give your answer rounded to 10 decimal
  8099.    places in the form 0.abcdefghij
  8100.  
  8101.    
  8102.    Answer: 0c49094fa750365e13bb20ec4a158b6d
  8103.  
  8104.  
  8105. Problem 308
  8106. ===========
  8107.  
  8108.  
  8109.    A program written in the programming language Fractran consists of a list
  8110.    of fractions.
  8111.  
  8112.    The internal state of the Fractran Virtual Machine is a positive integer,
  8113.    which is initially set to a seed value. Each iteration of a Fractran
  8114.    program multiplies the state integer by the first fraction in the list
  8115.    which will leave it an integer.
  8116.  
  8117.    For example, one of the Fractran programs that John Horton Conway wrote
  8118.    for prime-generation consists of the following 14 fractions:
  8119.  
  8120.    17 , 78 , 19 , 23 , 29 , 77 , 95 , 77 , 1  , 11 , 13 , 15 , 1 , 55 .
  8121.    91   85   51   38   33   29   23   19   17   13   11   2    7   1
  8122.  
  8123.    Starting with the seed integer 2, successive iterations of the program
  8124.    produce the sequence:
  8125.    15, 825, 725, 1925, 2275, 425, ..., 68, 4, 30, ..., 136, 8, 60, ..., 544,
  8126.    32, 240, ...
  8127.  
  8128.    The powers of 2 that appear in this sequence are 2^2, 2^3, 2^5, ...
  8129.    It can be shown that all the powers of 2 in this sequence have prime
  8130.    exponents and that all the primes appear as exponents of powers of 2, in
  8131.    proper order!
  8132.  
  8133.    If someone uses the above Fractran program to solve Project Euler Problem
  8134.    7 (find the 10001^st prime), how many iterations would be needed until the
  8135.    program produces 2^10001st prime ?
  8136.  
  8137.    
  8138.    Answer: 43e736dfc6478a52653814248a71771d
  8139.  
  8140.  
  8141. Problem 309
  8142. ===========
  8143.  
  8144.  
  8145.    In the classic "Crossing Ladders" problem, we are given the lengths x and
  8146.    y of two ladders resting on the opposite walls of a narrow, level street.
  8147.    We are also given the height h above the street where the two ladders
  8148.    cross and we are asked to find the width of the street (w).
  8149.  
  8150.    Here, we are only concerned with instances where all four variables are
  8151.    positive integers.
  8152.    For example, if x = 70, y = 119 and h = 30, we can calculate that w = 56.
  8153.  
  8154.    In fact, for integer values x, y, h and 0 < x < y < 200, there are only
  8155.    five triplets (x,y,h) producing integer solutions for w:
  8156.    (70, 119, 30), (74, 182, 21), (87, 105, 35), (100, 116, 35) and (119, 175,
  8157.    40).
  8158.  
  8159.    For integer values x, y, h and 0 < x < y < 1 000 000, how many triplets
  8160.    (x,y,h) produce integer solutions for w?
  8161.  
  8162.    
  8163.    p_309_ladders.gif
  8164.    Answer: 210139
  8165.  
  8166.  
  8167. Problem 310
  8168. ===========
  8169.  
  8170.  
  8171.    Alice and Bob play the game Nim Square.
  8172.    Nim Square is just like ordinary three-heap normal play Nim, but the
  8173.    players may only remove a square number of stones from a heap.
  8174.    The number of stones in the three heaps is represented by the ordered
  8175.    triple (a,b,c).
  8176.    If 0≤a≤b≤c≤29 then the number of losing positions for the next player is
  8177.    1160.
  8178.  
  8179.    Find the number of losing positions for the next player if 0≤a≤b≤c≤100
  8180.    000.
  8181.  
  8182.    
  8183.    Answer: 6b94f848996393eef163add4d17360c7
  8184.  
  8185.  
  8186. Problem 311
  8187. ===========
  8188.  
  8189.  
  8190.    ABCD is a convex, integer sided quadrilateral with 1 ≤ AB < BC < CD < AD.
  8191.    BD has integer length. O is the midpoint of BD. AO has integer length.
  8192.    We'll call ABCD a biclinic integral quadrilateral if AO = CO ≤ BO = DO.
  8193.  
  8194.    For example, the following quadrilateral is a biclinic integral
  8195.    quadrilateral:
  8196.    AB = 19, BC = 29, CD = 37, AD = 43, BD = 48 and AO = CO = 23.
  8197.  
  8198.    Let B(N) be the number of distinct biclinic integral quadrilaterals ABCD
  8199.    that satisfy AB^2+BC^2+CD^2+AD^2 ≤ N.
  8200.    We can verify that B(10 000) = 49 and B(1 000 000) = 38239.
  8201.  
  8202.    Find B(10 000 000 000).
  8203.  
  8204.    
  8205.    p_311_biclinic.gif
  8206.    Answer: 36115d4f7dc07eea106d78e8431868e6
  8207.  
  8208.  
  8209. Problem 312
  8210. ===========
  8211.  
  8212.  
  8213.    - A Sierpiński graph of order-1 (S[1]) is an equilateral triangle.
  8214.    - S[n+1] is obtained from S[n] by positioning three copies of S[n] so that
  8215.    every pair of copies has one common corner.
  8216.  
  8217.    Let C(n) be the number of cycles that pass exactly once through all the
  8218.    vertices of S[n].
  8219.    For example, C(3) = 8 because eight such cycles can be drawn on S[3], as
  8220.    shown below:
  8221.  
  8222.    It can also be verified that :
  8223.    C(1) = C(2) = 1
  8224.    C(5) = 71328803586048
  8225.    C(10 000) mod 10^8 = 37652224
  8226.    C(10 000) mod 13^8 = 617720485
  8227.  
  8228.    Find C(C(C(10 000))) mod 13^8.
  8229.  
  8230.    
  8231.    p_312_sierpinskyAt.gif
  8232.    p_312_sierpinsky8t.gif
  8233.    Answer: 535113d1a81f421fe814d48205dac570
  8234.  
  8235.  
  8236. Problem 313
  8237. ===========
  8238.  
  8239.  
  8240.    In a sliding game a counter may slide horizontally or vertically into an
  8241.    empty space. The objective of the game is to move the red counter from the
  8242.    top left corner of a grid to the bottom right corner; the space always
  8243.    starts in the bottom right corner. For example, the following sequence of
  8244.    pictures show how the game can be completed in five moves on a 2 by 2
  8245.    grid.
  8246.  
  8247.    Let S(m,n) represent the minimum number of moves to complete the game on
  8248.    an m by n grid. For example, it can be verified that S(5,4) = 25.
  8249.  
  8250.    There are exactly 5482 grids for which S(m,n) = p^2, where p < 100 is
  8251.    prime.
  8252.  
  8253.    How many grids does S(m,n) = p^2, where p < 10^6 is prime?
  8254.  
  8255.    
  8256.    p_313_sliding_game_1.gif
  8257.    p_313_sliding_game_2.gif
  8258.    Answer: 2468d42fa1c7f61547ce71c9826218ea
  8259.  
  8260.  
  8261. Problem 314
  8262. ===========
  8263.  
  8264.  
  8265.    The moon has been opened up, and land can be obtained for free, but there
  8266.    is a catch. You have to build a wall around the land that you stake out,
  8267.    and building a wall on the moon is expensive. Every country has been
  8268.    allotted a 500 m by 500 m square area, but they will possess only that
  8269.    area which they wall in. 251001 posts have been placed in a rectangular
  8270.    grid with 1 meter spacing. The wall must be a closed series of straight
  8271.    lines, each line running from post to post.
  8272.  
  8273.    The bigger countries of course have built a 2000 m wall enclosing the
  8274.    entire 250 000 m^2 area. The [1]Duchy of Grand Fenwick, has a tighter
  8275.    budget, and has asked you (their Royal Programmer) to compute what shape
  8276.    would get best maximum enclosed-area/wall-length ratio.
  8277.  
  8278.    You have done some preliminary calculations on a sheet of paper.For a 2000
  8279.    meter wall enclosing the 250 000 m^2 area theenclosed-area/wall-length
  8280.    ratio is 125.
  8281.    Although not allowed , but to get an idea if this is anything better: if
  8282.    you place a circle inside the square area touching the four sides the area
  8283.    will be equal to π*250^2 m^2 and the perimeter will be π*500 m, so the
  8284.    enclosed-area/wall-length ratio will also be 125.
  8285.  
  8286.    However, if you cut off from the square four triangles with sides 75 m, 75
  8287.    m and 75√2 m the total area becomes 238750 m^2 and the perimeter becomes
  8288.    1400+300√2 m. So this gives an enclosed-area/wall-length ratio of 130.87,
  8289.    which is significantly better.
  8290.  
  8291.    Find the maximum enclosed-area/wall-length ratio.
  8292.    Give your answer rounded to 8 places behind the decimal point in the form
  8293.    abc.defghijk.
  8294.  
  8295.  
  8296.    Visible links
  8297.    1. http://en.wikipedia.org/wiki/Grand_Fenwick
  8298.    p_314_landgrab.gif
  8299.    Answer: aa457cae6f67945d50683a85a9b70230
  8300.  
  8301.  
  8302. Problem 315
  8303. ===========
  8304.  
  8305.  
  8306.    Sam and Max are asked to transform two digital clocks into two "digital
  8307.    root" clocks.
  8308.    A digital root clock is a digital clock that calculates digital roots step
  8309.    by step.
  8310.  
  8311.    When a clock is fed a number, it will show it and then it will start the
  8312.    calculation, showing all the intermediate values until it gets to the
  8313.    result.
  8314.    For example, if the clock is fed the number 137, it will show: "137" →
  8315.    "11" → "2" and then it will go black, waiting for the next number.
  8316.  
  8317.    Every digital number consists of some light segments: three horizontal
  8318.    (top, middle, bottom) and four vertical (top-left, top-right, bottom-left,
  8319.    bottom-right).
  8320.    Number "1" is made of vertical top-right and bottom-right, number "4" is
  8321.    made by middle horizontal and vertical top-left, top-right and
  8322.    bottom-right. Number "8" lights them all.
  8323.  
  8324.    The clocks consume energy only when segments are turned on/off.
  8325.    To turn on a "2" will cost 5 transitions, while a "7" will cost only 4
  8326.    transitions.
  8327.  
  8328.    Sam and Max built two different clocks.
  8329.  
  8330.    Sam's clock is fed e.g. number 137: the clock shows "137", then the panel
  8331.    is turned off, then the next number ("11") is turned on, then the panel is
  8332.    turned off again and finally the last number ("2") is turned on and, after
  8333.    some time, off.
  8334.    For the example, with number 137, Sam's clock requires:
  8335.  
  8336.    "137" : (2 + 5 + 4) × 2 = 22 transitions ("137" on/off).
  8337.    "11"  : (2 + 2) × 2 = 8 transitions ("11" on/off).
  8338.    "2"   : (5) × 2 = 10 transitions ("2" on/off).
  8339.  
  8340.    For a grand total of 40 transitions.
  8341.  
  8342.    Max's clock works differently. Instead of turning off the whole panel, it
  8343.    is smart enough to turn off only those segments that won't be needed for
  8344.    the next number.
  8345.    For number 137, Max's clock requires:
  8346.  
  8347.            2 + 5 + 4 = 11 transitions ("137" on)
  8348.    "137" : 7 transitions (to turn off the segments that are not needed for
  8349.            number "11").
  8350.            0 transitions (number "11" is already turned on correctly)
  8351.    "11"  : 3 transitions (to turn off the first "1" and the bottom part of
  8352.            the second "1";
  8353.            the top part is common with number "2").
  8354.            4 tansitions (to turn on the remaining segments in order to get a
  8355.    "2"   : "2")
  8356.            5 transitions (to turn off number "2").
  8357.  
  8358.    For a grand total of 30 transitions.
  8359.  
  8360.    Of course, Max's clock consumes less power than Sam's one.
  8361.    The two clocks are fed all the prime numbers between A = 10^7 and B =
  8362.    2×10^7.
  8363.    Find the difference between the total number of transitions needed by
  8364.    Sam's clock and that needed by Max's one.
  8365.  
  8366.    
  8367.    p_315_clocks.gif
  8368.    Answer: 13625242
  8369.  
  8370.  
  8371. Problem 316
  8372. ===========
  8373.  
  8374.  
  8375.    Let p = p[1] p[2] p[3] ... be an infinite sequence of random digits,
  8376.    selected from {0,1,2,3,4,5,6,7,8,9} with equal probability.
  8377.    It can be seen that p corresponds to the real number 0.p[1] p[2] p[3] ....
  8378.    It can also be seen that choosing a random real number from the interval
  8379.    [0,1) is equivalent to choosing an infinite sequence of random digits
  8380.    selected from {0,1,2,3,4,5,6,7,8,9} with equal probability.
  8381.  
  8382.    For any positive integer n with d decimal digits, let k be the smallest
  8383.    index such that
  8384.    p[k, ]p[k+1], ...p[k+d-1] are the decimal digits of n, in the same order.
  8385.    Also, let g(n) be the expected value of k; it can be proven that g(n) is
  8386.    always finite and, interestingly, always an integer number.
  8387.  
  8388.    For example, if n = 535, then
  8389.    for p = 31415926535897...., we get k = 9
  8390.    for p = 355287143650049560000490848764084685354..., we get k = 36
  8391.    etc and we find that g(535) = 1008.
  8392.  
  8393.    Given that , find
  8394.  
  8395.    Note: represents the floor function.
  8396.    
  8397.    p_316_decexp1.gif
  8398.    p_316_decexp2.gif
  8399.    p_316_decexp3.gif
  8400.    Answer: 2495e8f6e9d4cdadbf0411144e7180b9
  8401.  
  8402.  
  8403. Problem 317
  8404. ===========
  8405.  
  8406.  
  8407.    A firecracker explodes at a height of 100 m above level ground. It breaks
  8408.    into a large number of very small fragments, which move in every
  8409.    direction; all of them have the same initial velocity of 20 m/s.
  8410.  
  8411.    We assume that the fragments move without air resistance, in a uniform
  8412.    gravitational field with g=9.81 m/s^2.
  8413.  
  8414.    Find the volume (in m^3) of the region through which the fragments move
  8415.    before reaching the ground. Give your answer rounded to four decimal
  8416.    places.
  8417.  
  8418.    
  8419.    Answer: b0e2bec93bfe598ade5d3d1141f76bdd
  8420.  
  8421.  
  8422. Problem 318
  8423. ===========
  8424.  
  8425.  
  8426.    Consider the real number √2+√3.
  8427.    When we calculate the even powers of √2+√3we get:
  8428.    (√2+√3)^2 = 9.898979485566356...
  8429.    (√2+√3)^4 = 97.98979485566356...
  8430.    (√2+√3)^6 = 969.998969071069263...
  8431.    (√2+√3)^8 = 9601.99989585502907...
  8432.    (√2+√3)^10 = 95049.999989479221...
  8433.    (√2+√3)^12 = 940897.9999989371855...
  8434.    (√2+√3)^14 = 9313929.99999989263...
  8435.    (√2+√3)^16 = 92198401.99999998915...
  8436.  
  8437.    It looks like that the number of consecutive nines at the beginning of the
  8438.    fractional part of these powers is non-decreasing.
  8439.    In fact it can be proven that the fractional part of (√2+√3)^2n approaches
  8440.    1 for large n.
  8441.  
  8442.    Consider all real numbers of the form √p+√q with p and q positive integers
  8443.    and p<q, such that the fractional part of (√p+√q)^2n approaches 1 for
  8444.    large n.
  8445.  
  8446.    Let C(p,q,n) be the number of consecutive nines at the beginning of the
  8447.    fractional part of
  8448.    (√p+√q)^2n.
  8449.  
  8450.    Let N(p,q) be the minimal value of n such that C(p,q,n) ≥ 2011.
  8451.  
  8452.    Find ∑N(p,q) for p+q ≤ 2011.
  8453.  
  8454.    
  8455.    Answer: de358f1c4d6e30c1a4f82c8bc5cedf2d
  8456.  
  8457.  
  8458. Problem 319
  8459. ===========
  8460.  
  8461.  
  8462.    Let x[1], x[2],..., x[n] be a sequence of length n such that:
  8463.  
  8464.      • x[1] = 2
  8465.      • for all 1 < i ≤ n : x[i-1] < x[i]
  8466.      • for all i and j with 1 ≤ i, j ≤ n : (x[i]) ^ j < (x[j] + 1)^i
  8467.  
  8468.    There are only five such sequences of length 2, namely:{2,4}, {2,5},
  8469.    {2,6}, {2,7} and {2,8}.
  8470.    There are 293 such sequences of length 5; three examples are given below:
  8471.    {2,5,11,25,55}, {2,6,14,36,88}, {2,8,22,64,181}.
  8472.  
  8473.    Let t(n) denote the number of such sequences of length n.
  8474.    You are given that t(10) = 86195 and t(20) = 5227991891.
  8475.  
  8476.    Find t(10^10) and give your answer modulo 10^9.
  8477.  
  8478.    
  8479.    Answer: d346ab7d128ee0402820edf5fe4aed30
  8480.  
  8481.  
  8482. Problem 320
  8483. ===========
  8484.  
  8485.  
  8486.    Let N(i) be the smallest integer n such that n! is divisible by
  8487.    (i!)^1234567890
  8488.  
  8489.    Let S(u)=∑N(i) for 10 ≤ i ≤ u.
  8490.  
  8491.    S(1000)=614538266565663.
  8492.  
  8493.    Find S(1 000 000) mod 10^18.
  8494.  
  8495.    
  8496.    Answer: 8426f939c3ee410a8c4d43886ef77ccb
  8497.  
  8498.  
  8499. Problem 321
  8500. ===========
  8501.  
  8502.  
  8503.    A horizontal row comprising of 2n + 1 squares has n red counters placed at
  8504.    one end and n blue counters at the other end, being separated by a single
  8505.    empty square in the centre. For example, when n = 3.
  8506.  
  8507.    A counter can move from one square to the next (slide) or can jump over
  8508.    another counter (hop) as long as the square next to that counter is
  8509.    unoccupied.
  8510.  
  8511.    Let M(n) represent the minimum number of moves/actions to completely
  8512.    reverse the positions of the coloured counters; that is, move all the red
  8513.    counters to the right and all the blue counters to the left.
  8514.  
  8515.    It can be verified M(3) = 15, which also happens to be a triangle number.
  8516.  
  8517.    If we create a sequence based on the values of n for which M(n) is a
  8518.    triangle number then the first five terms would be:
  8519.    1, 3, 10, 22, and 63, and their sum would be 99.
  8520.  
  8521.    Find the sum of the first forty terms of this sequence.
  8522.  
  8523.    
  8524.    p_321_swapping_counters_1.gif
  8525.    p_321_swapping_counters_2.gif
  8526.    Answer: 6d87412130312b01a999225a5fe689b1
  8527.  
  8528.  
  8529. Problem 322
  8530. ===========
  8531.  
  8532.  
  8533.    Let T(m, n) be the number of the binomial coefficients ^iC[n] that are
  8534.    divisible by 10 for n ≤ i < m(i, m and n are positive integers).
  8535.    You are given that T(10^9, 10^7-10) = 989697000.
  8536.  
  8537.    Find T(10^18, 10^12-10).
  8538.  
  8539.    
  8540.    Answer: a75af9d717fa592487fb45e7552204a8
  8541.  
  8542.  
  8543. Problem 323
  8544. ===========
  8545.  
  8546.  
  8547.    Let y[0], y[1], y[2],... be a sequence of random unsigned 32 bit integers
  8548.    (i.e. 0 ≤ y[i] < 2^32, every value equally likely).
  8549.  
  8550.    For the sequence x[i] the following recursion is given:
  8551.  
  8552.      • x[0] = 0 and
  8553.      • x[i] = x[i-1] | y[i-1], for i > 0. ( | is the bitwise-OR operator)
  8554.  
  8555.    It can be seen that eventually there will be an index N such that x[i] =
  8556.    2^32 -1 (a bit-pattern of all ones) for all i ≥ N.
  8557.  
  8558.    Find the expected value of N.
  8559.    Give your answer rounded to 10 digits after the decimal point.
  8560.  
  8561.    
  8562.    Answer: c8f8a7ab17a87f1b17a1f4a86c984ea7
  8563.  
  8564.  
  8565. Problem 324
  8566. ===========
  8567.  
  8568.  
  8569.    Let f(n) represent the number of ways one can fill a 3×3×n tower with
  8570.    blocks of 2×1×1.
  8571.    You're allowed to rotate the blocks in any way you like; however,
  8572.    rotations, reflections etc of the tower itself are counted as distinct.
  8573.  
  8574.    For example (with q = 100000007) :
  8575.    f(2) = 229,
  8576.    f(4) = 117805,
  8577.    f(10) mod q = 96149360,
  8578.    f(10^3) mod q = 24806056,
  8579.    f(10^6) mod q = 30808124.
  8580.  
  8581.    Find f(10^10000) mod 100000007.
  8582.  
  8583.    
  8584.    Answer: 96972774
  8585.  
  8586.  
  8587. Problem 325
  8588. ===========
  8589.  
  8590.  
  8591.    A game is played with two piles of stones and two players. At her turn, a
  8592.    player removes a number of stones from the larger pile. The number of
  8593.    stones she removes must be a positive multiple of the number of stones in
  8594.    the smaller pile.
  8595.  
  8596.    E.g., let the ordered pair(6,14) describe a configuration with 6 stones in
  8597.    the smaller pile and 14 stones in the larger pile, then the first player
  8598.    can remove 6 or 12 stones from the larger pile.
  8599.  
  8600.    The player taking all the stones from a pile wins the game.
  8601.  
  8602.    A winning configuration is one where the first player can force a win. For
  8603.    example, (1,5), (2,6) and (3,12) are winning configurations because the
  8604.    first player can immediately remove all stones in the second pile.
  8605.  
  8606.    A losing configuration is one where the second player can force a win, no
  8607.    matter what the first player does. For example, (2,3) and (3,4) are losing
  8608.    configurations: any legal move leaves a winning configuration for the
  8609.    second player.
  8610.  
  8611.    Define S(N) as the sum of (x[i]+y[i]) for all losing configurations
  8612.    (x[i],y[i]), 0 < x[i] < y[i] ≤ N. We can verify that S(10) = 211 and
  8613.    S(10^4) = 230312207313.
  8614.  
  8615.    Find S(10^16) mod 7^10.
  8616.  
  8617.    
  8618.    Answer: 54672965
  8619.  
  8620.  
  8621. Problem 326
  8622. ===========
  8623.  
  8624.  
  8625.    Let a[n] be a sequence recursively defined by: .
  8626.  
  8627.    So the first 10 elements of a[n] are: 1,1,0,3,0,3,5,4,1,9.
  8628.  
  8629.    Let f(N,M) represent the number of pairs (p,q) such that:
  8630.  
  8631.    It can be seen that f(10,10)=4 with the pairs (3,3), (5,5), (7,9) and
  8632.    (9,10).
  8633.  
  8634.    You are also given that f(10^4,10^3)=97158.
  8635.  
  8636.    Find f(10^12,10^6).
  8637.  
  8638.    
  8639.    p_326_formula1.gif
  8640.    p_326_formula2.gif
  8641.    Answer: d95dff1a5ceee0064993d98defdd603e
  8642.  
  8643.  
  8644. Problem 327
  8645. ===========
  8646.  
  8647.  
  8648.    A series of three rooms are connected to each other by automatic doors.
  8649.  
  8650.    Each door is operated by a security card. Once you enter a room the door
  8651.    automatically closes and that security card cannot be used again. A
  8652.    machine at the start will dispense an unlimited number of cards, but each
  8653.    room (including the starting room) contains scanners and if they detect
  8654.    that you are holding more than three security cards or if they detect an
  8655.    unattended security card on the floor, then all the doors will become
  8656.    permanently locked. However, each room contains a box where you may safely
  8657.    store any number of security cards for use at a later stage.
  8658.  
  8659.    If you simply tried to travel through the rooms one at a time then as you
  8660.    entered room 3 you would have used all three cards and would be trapped in
  8661.    that room forever!
  8662.  
  8663.    However, if you make use of the storage boxes, then escape is possible.
  8664.    For example, you could enter room 1 using your first card, place one card
  8665.    in the storage box, and use your third card to exit the room back to the
  8666.    start. Then after collecting three more cards from the dispensing machine
  8667.    you could use one to enter room 1 and collect the card you placed in the
  8668.    box a moment ago. You now have three cards again and will be able to
  8669.    travel through the remaining three doors. This method allows you to travel
  8670.    through all three rooms using six security cards in total.
  8671.  
  8672.    It is possible to travel through six rooms using a total of 123 security
  8673.    cards while carrying a maximum of 3 cards.
  8674.  
  8675.    Let C be the maximum number of cards which can be carried at any time.
  8676.  
  8677.    Let R be the number of rooms to travel through.
  8678.  
  8679.    Let M(C,R) be the minimum number of cards required from the dispensing
  8680.    machine to travel through R rooms carrying up to a maximum of C cards at
  8681.    any time.
  8682.  
  8683.    For example, M(3,6)=123 and M(4,6)=23.
  8684.    And, ΣM(C,6)=146 for 3 ≤ C ≤ 4.
  8685.  
  8686.    You are given that ΣM(C,10)=10382 for 3 ≤ C ≤ 10.
  8687.  
  8688.    Find ΣM(C,30) for 3 ≤ C ≤ 40.
  8689.  
  8690.    
  8691.    p_327_rooms_of_doom.gif
  8692.    Answer: 2cd4c0ad8a00c5be99802188ee2628fb
  8693.  
  8694.  
  8695. Problem 328
  8696. ===========
  8697.  
  8698.  
  8699.    We are trying to find a hidden number selected from the set of integers
  8700.    {1, 2, ..., n} by asking questions. Each number (question) we ask, has a
  8701.    cost equal to the number asked and we get one of three possible answers:
  8702.  
  8703.      • "Your guess is lower than the hidden number", or
  8704.      • "Yes, that's it!", or
  8705.      • "Your guess is higher than the hidden number".
  8706.  
  8707.    Given the value of n, an optimal strategy minimizes the total cost (i.e.
  8708.    the sum of all the questions asked) for the worst possible case. E.g.
  8709.  
  8710.    If n=3, the best we can do is obviously to ask the number "2". The answer
  8711.    will immediately lead us to find the hidden number (at a total cost = 2).
  8712.  
  8713.    If n=8, we might decide to use a "binary search" type of strategy: Our
  8714.    first question would be "4" and if the hidden number is higher than 4 we
  8715.    will need one or two additional questions.
  8716.    Let our second question be "6". If the hidden number is still higher than
  8717.    6, we will need a third question in order to discriminate between 7 and 8.
  8718.    Thus, our third question will be "7" and the total cost for this
  8719.    worst-case scenario will be 4+6+7=17.
  8720.  
  8721.    We can improve considerably the worst-case cost for n=8, by asking "5" as
  8722.    our first question.
  8723.    If we are told that the hidden number is higher than 5, our second
  8724.    question will be "7", then we'll know for certain what the hidden number
  8725.    is (for a total cost of 5+7=12).
  8726.    If we are told that the hidden number is lower than 5, our second question
  8727.    will be "3" and if the hidden number is lower than 3 our third question
  8728.    will be "1", giving a total cost of 5+3+1=9.
  8729.    Since 12>9, the worst-case cost for this strategy is 12. That's better
  8730.    than what we achieved previously with the "binary search" strategy; it is
  8731.    also better than or equal to any other strategy.
  8732.    So, in fact, we have just described an optimal strategy for n=8.
  8733.  
  8734.    Let C(n) be the worst-case cost achieved by an optimal strategy for n, as
  8735.    described above.
  8736.    Thus C(1) = 0, C(2) = 1, C(3) = 2 and C(8) = 12.
  8737.    Similarly, C(100) = 400 and C(n) = 17575.
  8738.  
  8739.    Find C(n).
  8740.  
  8741.    
  8742.    p_328_sum1.gif
  8743.    p_328_sum2.gif
  8744.    Answer: 92a3220ad5b17a562c039e6e93d6df90
  8745.  
  8746.  
  8747. Problem 329
  8748. ===========
  8749.  
  8750.  
  8751.    Susan has a prime frog.
  8752.    Her frog is jumping around over 500 squares numbered 1 to 500.He can only
  8753.    jump one square to the left or to the right, with equal probability, and
  8754.    he cannot jump outside the range [1;500].
  8755.    (if it lands at either end, it automatically jumps to the only available
  8756.    square on the next move.)
  8757.  
  8758.    When he is on a square with a prime number on it, he croaks 'P' (PRIME)
  8759.    with probability 2/3 or 'N' (NOT PRIME) with probability 1/3 just before
  8760.    jumping to the next square.
  8761.    When he is on a square with a number on it that is not a prime he croaks
  8762.    'P' with probability 1/3 or 'N' with probability 2/3 just before jumping
  8763.    to the next square.
  8764.  
  8765.    Given that the frog's starting position is random with the same
  8766.    probability for every square, and given that she listens to his first 15
  8767.    croaks, what is the probability that she hears the sequence
  8768.    PPPPNNPPPNPPNPN?
  8769.  
  8770.    Give your answer as a fraction p/q in reduced form.
  8771.    
  8772.    Answer: e392a8b1b053c83e68663e08456bb392
  8773.  
  8774.  
  8775. Problem 330
  8776. ===========
  8777.  
  8778.    An infinite sequence of real numbers a(n) is defined for all integers n as
  8779.    follows:
  8780.  
  8781.    For example,
  8782.  
  8783.    a(0) = 1  + 1  + 1  + ... = e − 1
  8784.           1!   2!   3!
  8785.  
  8786.    a(1) = e − 1 + 1  + 1  + ... = 2e − 3
  8787.           1!      2!   3!
  8788.  
  8789.    a(2) = 2e − 3 + e − 1 + 1  + ... = 7 e − 6
  8790.           1!       2!      3!         2
  8791.  
  8792.    with e = 2.7182818... being Euler's constant.
  8793.  
  8794.    It can be shown that a(n) is of  A(n) e + B(n) for integers A(n) and B(n).
  8795.    the form                         n!
  8796.  
  8797.    For example a(10) = 328161643 e − 652694486 .
  8798.                        10!
  8799.  
  8800.    Find A(10^9) + B(10^9) and give your answer mod 77 777 777.
  8801.  
  8802.    
  8803.    p_330_formula.gif
  8804.    Answer: 15955822
  8805.  
  8806.  
  8807. Problem 331
  8808. ===========
  8809.  
  8810.  
  8811.    N×N disks are placed on a square game board. Each disk has a black side
  8812.    and white side.
  8813.  
  8814.    At each turn, you may choose a disk and flip all the disks in the same row
  8815.    and the same column as this disk: thus 2×N-1 disks are flipped. The game
  8816.    ends when all disks show their white side. The following example shows a
  8817.    game on a 5×5 board.
  8818.  
  8819.    It can be proven that 3 is the minimal number of turns to finish this
  8820.    game.
  8821.  
  8822.    The bottom left disk on the N×N board has coordinates (0,0);
  8823.    the bottom right disk has coordinates (N-1,0) and the top left disk has
  8824.    coordinates (0,N-1).
  8825.  
  8826.    Let C[N] be the following configuration of a board with N×N disks:
  8827.    A disk at (x,y) satisfying , shows its black side; otherwise, it shows its
  8828.    white side. C[5] is shown above.
  8829.  
  8830.    Let T(N) be the minimal number of turns to finish a game starting from
  8831.    configuration C[N] or 0 if configuration C[N] is unsolvable.
  8832.    We have shown that T(5)=3. You are also given that T(10)=29 and T(1
  8833.    000)=395253.
  8834.  
  8835.    Find .
  8836.  
  8837.    
  8838.    p_331_crossflips3.gif
  8839.    p_331_crossflips1.gif
  8840.    p_331_crossflips2.gif
  8841.    Answer: b609ccc578e71db9de0524fff94e1b70
  8842.  
  8843.  
  8844. Problem 332
  8845. ===========
  8846.  
  8847.  
  8848.    A spherical triangle is a figure formed on the surface of a sphere by
  8849.    three great circular arcs intersecting pairwise in three vertices.
  8850.  
  8851.    Let C(r) be the sphere with the centre (0,0,0) and radius r.
  8852.    Let Z(r) be the set of points on the surface of C(r) with integer
  8853.    coordinates.
  8854.    Let T(r) be the set of spherical triangles with vertices in
  8855.    Z(r).Degenerate spherical triangles, formed by three points on the same
  8856.    great arc, are not included in T(r).
  8857.    Let A(r) be the area of the smallest spherical triangle in T(r).
  8858.  
  8859.    For example A(14) is 3.294040 rounded to six decimal places.
  8860.  
  8861.    Find A(r). Give your answer rounded to six decimal places.
  8862.  
  8863.    
  8864.    p_332_spherical.jpg
  8865.    p_332_sum.gif
  8866.    Answer: c2ae53ebfb15db373cfe5d71078ea1ca
  8867.  
  8868.  
  8869. Problem 333
  8870. ===========
  8871.  
  8872.  
  8873.    All positive integers can be partitioned in such a way that each and every
  8874.    term of the partition can be expressed as 2^ix3^j, where i,j ≥ 0.
  8875.  
  8876.    Let's consider only those such partitions where none of the terms can
  8877.    divide any of the other terms.
  8878.    For example, the partition of 17 = 2 + 6 + 9 = (2^1x3^0 + 2^1x3^1 +
  8879.    2^0x3^2) would not be valid since 2 can divide 6. Neither would the
  8880.    partition 17 = 16 + 1 = (2^4x3^0 + 2^0x3^0) since 1 can divide 16. The
  8881.    only valid partition of 17 would be 8 + 9 = (2^3x3^0 + 2^0x3^2).
  8882.  
  8883.    Many integers have more than one valid partition, the first being 11
  8884.    having the following two partitions.
  8885.    11 = 2 + 9 = (2^1x3^0 + 2^0x3^2)
  8886.    11 = 8 + 3 = (2^3x3^0 + 2^0x3^1)
  8887.  
  8888.    Let's define P(n) as the number of valid partitions of n. For example,
  8889.    P(11) = 2.
  8890.  
  8891.    Let's consider only the prime integers q which would have a single valid
  8892.    partition such as P(17).
  8893.  
  8894.    The sum of the primes q <100 such that P(q)=1 equals 233.
  8895.  
  8896.    Find the sum of the primes q <1000000 such that P(q)=1.
  8897.  
  8898.    
  8899.    Answer: 3053105
  8900.  
  8901.  
  8902. Problem 334
  8903. ===========
  8904.  
  8905.  
  8906.    In Plato's heaven, there exist an infinite number of bowls in a straight
  8907.    line.
  8908.    Each bowl either contains some or none of a finite number of beans.
  8909.    A child plays a game, which allows only one kind of move: removing two
  8910.    beans from any bowl, and putting one in each of the two adjacent bowls.
  8911.    The game ends when each bowl contains either one or no beans.
  8912.  
  8913.    For example, consider two adjacent bowls containing 2 and 3 beans
  8914.    respectively, all other bowls being empty. The following eight moves will
  8915.    finish the game:
  8916.  
  8917.    You are given the following sequences:
  8918.  
  8919.    t[0] = 123456.
  8920.  
  8921.             t[i-1] ,         if t[i-1] is even
  8922.    t[i] =   2
  8923.             t[i-1]   926252, if t[i-1] is odd
  8924.             2
  8925.            where ⌊x⌋ is the floor function
  8926.            and is the bitwise XOR operator.
  8927.  
  8928.    b[i] = ( t[i] mod 2^11) + 1.
  8929.  
  8930.    The first two terms of the last sequence are b[1] = 289 and b[2] = 145.
  8931.    If we start with b[1] and b[2] beans in two adjacent bowls, 3419100 moves
  8932.    would be required to finish the game.
  8933.  
  8934.    Consider now 1500 adjacent bowls containing b[1], b[2],..., b[1500] beans
  8935.    respectively, all other bowls being empty. Find how many moves it takes
  8936.    before the game ends.
  8937.  
  8938.    
  8939.    p_334_beans.gif
  8940.    p_334_cases.gif
  8941.    p_334_lfloor.gif
  8942.    p_334_rfloor.gif
  8943.    p_334_oplus.gif
  8944.    Answer: 71851da3058acf6b74e90251bdf4aa8f
  8945.  
  8946.  
  8947. Problem 335
  8948. ===========
  8949.  
  8950.  
  8951.    Whenever Peter feels bored, he places some bowls, containing one bean
  8952.    each, in a circle. After this, he takes all the beans out of a certain
  8953.    bowl and drops them one by one in the bowls going clockwise. He repeats
  8954.    this, starting from the bowl he dropped the last bean in, until the
  8955.    initial situation appears again. For example with 5 bowls he acts as
  8956.    follows:
  8957.  
  8958.    So with 5 bowls it takes Peter 15 moves to return to the initial
  8959.    situation.
  8960.  
  8961.    Let M(x) represent the number of moves required to return to the initial
  8962.    situation, starting with x bowls. Thus, M(5) = 15. It can also be verified
  8963.    that M(100) = 10920.
  8964.  
  8965.    Find M(2^k+1). Give your answer modulo 7^9.
  8966.  
  8967.    
  8968.    p_335_mancala.gif
  8969.    p_335_sum.gif
  8970.    Answer: 5032316
  8971.  
  8972.  
  8973. Problem 336
  8974. ===========
  8975.  
  8976.  
  8977.    A train is used to transport four carriages in the order: ABCD. However,
  8978.    sometimes when the train arrives to collect the carriages they are not in
  8979.    the correct order.
  8980.    To rearrange the carriages they are all shunted on to a large rotating
  8981.    turntable. After the carriages are uncoupled at a specific point the train
  8982.    moves off the turntable pulling the carriages still attached with it. The
  8983.    remaining carriages are rotated 180 degrees. All of the carriages are then
  8984.    rejoined and this process is repeated as often as necessary in order to
  8985.    obtain the least number of uses of the turntable.
  8986.    Some arrangements, such as ADCB, can be solved easily: the carriages are
  8987.    separated between A and D, and after DCB are rotated the correct order has
  8988.    been achieved.
  8989.  
  8990.    However, Simple Simon, the train driver, is not known for his efficiency,
  8991.    so he always solves the problem by initially getting carriage A in the
  8992.    correct place, then carriage B, and so on.
  8993.  
  8994.    Using four carriages, the worst possible arrangements for Simon, which we
  8995.    shall call maximix arrangements, are DACB and DBAC; each requiring him
  8996.    five rotations (although, using the most efficient approach, they could be
  8997.    solved using just three rotations). The process he uses for DACB is shown
  8998.    below.
  8999.  
  9000.    It can be verified that there are 24 maximix arrangements for six
  9001.    carriages, of which the tenth lexicographic maximix arrangement is DFAECB.
  9002.  
  9003.    Find the 2011^th lexicographic maximix arrangement for eleven carriages.
  9004.  
  9005.    
  9006.    p_336_maximix.gif
  9007.    Answer: 7968e48fc692ce25bf7f5494f4ab6814
  9008.  
  9009.  
  9010. Problem 337
  9011. ===========
  9012.  
  9013.  
  9014.    Let {a[1], a[2],..., a[n]} be an integer sequence of length n such that:
  9015.  
  9016.      • a[1] = 6
  9017.      • for all 1 ≤ i < n : φ(a[i]) < φ(a[i+1]) < a[i] < a[i+1] ^1
  9018.  
  9019.    Let S(N) be the number of such sequences with a[n] ≤ N.
  9020.    For example, S(10) = 4: {6}, {6, 8}, {6, 8, 9} and {6, 10}.
  9021.    We can verify that S(100) = 482073668 and S(10 000) mod 10^8 = 73808307.
  9022.  
  9023.    Find S(20 000 000) mod 10^8.
  9024.  
  9025.    ^1 φ denotes Euler's totient function.
  9026.  
  9027.    
  9028.    Answer: 85068035
  9029.  
  9030.  
  9031. Problem 338
  9032. ===========
  9033.  
  9034.  
  9035.    A rectangular sheet of grid paper with integer dimensions w × h is given.
  9036.    Its grid spacing is 1.
  9037.    When we cut the sheet along the grid lines into two pieces and rearrange
  9038.    those pieces without overlap, we can make new rectangles with different
  9039.    dimensions.
  9040.  
  9041.    For example, from a sheet with dimensions 9 × 4 , we can make rectangles
  9042.    with dimensions 18 × 2, 12 × 3 and 6 × 6 by cutting and rearranging as
  9043.    below:
  9044.  
  9045.    Similarly, from a sheet with dimensions 9 × 8 , we can make rectangles
  9046.    with dimensions 18 × 4 and 12 × 6 .
  9047.  
  9048.    For a pair w and h, let F(w,h) be the number of distinct rectangles that
  9049.    can be made from a sheet with dimensions w × h .
  9050.    For example, F(2,1) = 0, F(2,2) = 1, F(9,4) = 3 and F(9,8) = 2.
  9051.    Note that rectangles congruent to the initial one are not counted in
  9052.    F(w,h).
  9053.    Note also that rectangles with dimensions w × h and dimensions h × w are
  9054.    not considered distinct.
  9055.  
  9056.    For an integer N, let G(N) be the sum of F(w,h) for all pairs w and h
  9057.    which satisfy 0 < h ≤ w ≤ N.
  9058.    We can verify that G(10) = 55, G(10^3) = 971745 and G(10^5) = 9992617687.
  9059.  
  9060.    Find G(10^12). Give your answer modulo 10^8.
  9061.  
  9062.    
  9063.    p_338_gridpaper.gif
  9064.    Answer: 15614292
  9065.  
  9066.  
  9067. Problem 339
  9068. ===========
  9069.  
  9070.  
  9071.    "And he came towards a valley, through which ran a river; and the borders
  9072.    of the valley were wooded, and on each side of the river were level
  9073.    meadows. And on one side of the river he saw a flock of white sheep, and
  9074.    on the other a flock of black sheep. And whenever one of the white sheep
  9075.    bleated, one of the black sheep would cross over and become white; and
  9076.    when one of the black sheep bleated, one of the white sheep would cross
  9077.    over and become black."
  9078.    [1]en.wikisource.org
  9079.  
  9080.    Initially each flock consists of n sheep. Each sheep (regardless of
  9081.    colour) is equally likely to be the next sheep to bleat. After a sheep has
  9082.    bleated and a sheep from the other flock has crossed over, Peredur may
  9083.    remove a number of white sheep in order to maximize the expected final
  9084.    number of black sheep. Let E(n) be the expected final number of black
  9085.    sheep if Peredur uses an optimal strategy.
  9086.  
  9087.    You are given that E(5) = 6.871346 rounded to 6 places behind the decimal
  9088.    point.
  9089.    Find E(10 000) and give your answer rounded to 6 places behind the decimal
  9090.    point.
  9091.  
  9092.  
  9093.    Visible links
  9094.    1. http://en.wikisource.org/wiki/The_Mabinogion/Peredur_the_Son_of_Evrawc
  9095.    Answer: 0be02210b2d2212d37d026478093c457
  9096.  
  9097.  
  9098. Problem 340
  9099. ===========
  9100.  
  9101.  
  9102.    For fixed integers a, b, c, define the crazy function F(n) as follows:
  9103.    F(n) = n - c for all n > b
  9104.    F(n) = F(a + F(a + F(a + F(a + n)))) for all n ≤ b.
  9105.  
  9106.    Also, define S(a, b, c) = .
  9107.  
  9108.    For example, if a = 50, b = 2000 and c = 40, then F(0) = 3240 and F(2000)
  9109.    = 2040.
  9110.    Also, S(50, 2000, 40) = 5204240.
  9111.  
  9112.    Find the last 9 digits of S(21^7, 7^21, 12^7).
  9113.  
  9114.    
  9115.    p_340_formula.gif
  9116.    Answer: fc838afe9ecde39bbe230923d7b50775
  9117.  
  9118.  
  9119. Problem 341
  9120. ===========
  9121.  
  9122.  
  9123.    The Golomb's self-describing sequence {G(n)} is the only nondecreasing
  9124.    sequence of natural numbers such that n appears exactly G(n) times in the
  9125.    sequence. The values of G(n) for the first few n are
  9126.  
  9127.            n     1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  …
  9128.            G(n)  1  2  2  3  3  4  4  4  5  5   5   6   6   6   6   …
  9129.  
  9130.    You are given that G(10^3) = 86, G(10^6) = 6137.
  9131.    You are also given that ΣG(n^3) = 153506976 for 1 ≤ n < 10^3.
  9132.  
  9133.    Find ΣG(n^3) for 1 ≤ n < 10^6.
  9134.  
  9135.    
  9136.    Answer: 7c163c3b4886943667b5c89db0a6cd02
  9137.  
  9138.  
  9139. Problem 342
  9140. ===========
  9141.  
  9142.  
  9143.    Consider the number 50.
  9144.    50^2 = 2500 = 2^2 × 5^4, so φ(2500) = 2 × 4 × 5^3 = 8 × 5^3 = 2^3 × 5^3.
  9145.    ^1
  9146.    So 2500 is a square and φ(2500) is a cube.
  9147.  
  9148.    Find the sum of all numbers n, 1 < n < 10^10 such that φ(n^2) is a cube.
  9149.  
  9150.    ^1 φ denotes Euler's totient function.
  9151.  
  9152.    
  9153.    Answer: 0e9add0383d4116c7c5cb3dc73fc0536
  9154.  
  9155.  
  9156. Problem 343
  9157. ===========
  9158.  
  9159.  
  9160.    For any positive integer k, a finite sequence a[i] of fractions x[i]/y[i]
  9161.    is defined by:
  9162.    a[1] = 1/k and
  9163.    a[i] = (x[i-1]+1)/(y[i-1]-1) reduced to lowest terms for i>1.
  9164.    When a[i] reaches some integer n, the sequence stops. (That is, when
  9165.    y[i]=1.)
  9166.    Define f(k) = n.
  9167.    For example, for k = 20:
  9168.  
  9169.    1/20 → 2/19 → 3/18 = 1/6 → 2/5 → 3/4 → 4/3 → 5/2 → 6/1 = 6
  9170.  
  9171.    So f(20) = 6.
  9172.  
  9173.    Also f(1) = 1, f(2) = 2, f(3) = 1 and Σf(k^3) = 118937 for 1 ≤ k ≤ 100.
  9174.  
  9175.    Find Σf(k^3) for 1 ≤ k ≤ 2×10^6.
  9176.  
  9177.    
  9178.    Answer: 0e10bd111425ad8e1343ac79dac7bb0e
  9179.  
  9180.  
  9181. Problem 344
  9182. ===========
  9183.  
  9184.  
  9185.    One variant of N.G. de Bruijn's silver dollar game can be described as
  9186.    follows:
  9187.  
  9188.    On a strip of squares a number of coins are placed, at most one coin per
  9189.    square. Only one coin, called the silver dollar, has any value. Two
  9190.    players take turns making moves. At each turn a player must make either a
  9191.    regular or a special move.
  9192.  
  9193.    A regular move consists of selecting one coin and moving it one or more
  9194.    squares to the left. The coin cannot move out of the strip or jump on or
  9195.    over another coin.
  9196.  
  9197.    Alternatively, the player can choose to make the special move of pocketing
  9198.    the leftmost coin rather than making a regular move. If no regular moves
  9199.    are possible, the player is forced to pocket the leftmost coin.
  9200.  
  9201.    The winner is the player who pockets the silver dollar.
  9202.  
  9203.    A winning configuration is an arrangement of coins on the strip where the
  9204.    first player can force a win no matter what the second player does.
  9205.  
  9206.    Let W(n,c) be the number of winning configurations for a strip of n
  9207.    squares, c worthless coins and one silver dollar.
  9208.  
  9209.    You are given that W(10,2) = 324 and W(100,10) = 1514704946113500.
  9210.  
  9211.    Find W(1 000 000, 100) modulo the semiprime 1000 036 000 099 (= 1 000 003
  9212.    · 1 000 033).
  9213.  
  9214.    
  9215.    p_344_silverdollar.gif
  9216.    Answer: 38e7b980b38fcac89b3e267e328cd292
  9217.  
  9218.  
  9219. Problem 345
  9220. ===========
  9221.  
  9222.  
  9223.    We define the Matrix Sum of a matrix as the maximum sum of matrix elements
  9224.    with each element being the only one in his row and column. For example,
  9225.    the Matrix Sum of the matrix below equals 3315 ( = 863 + 383 + 343 + 959 +
  9226.    767):
  9227.  
  9228.                                 7  53 183 439 863
  9229.                               497 383 563  79 973
  9230.                               287  63 343 169 583
  9231.                               627 343 773 959 943
  9232.                               767 473 103 699 303
  9233.  
  9234.    Find the Matrix Sum of:
  9235.  
  9236.             7  53 183 439 863 497 383 563  79 973 287  63 343 169 583
  9237.           627 343 773 959 943 767 473 103 699 303 957 703 583 639 913
  9238.           447 283 463  29  23 487 463 993 119 883 327 493 423 159 743
  9239.           217 623   3 399 853 407 103 983  89 463 290 516 212 462 350
  9240.           960 376 682 962 300 780 486 502 912 800 250 346 172 812 350
  9241.           870 456 192 162 593 473 915  45 989 873 823 965 425 329 803
  9242.           973 965 905 919 133 673 665 235 509 613 673 815 165 992 326
  9243.           322 148 972 962 286 255 941 541 265 323 925 281 601  95 973
  9244.           445 721  11 525 473  65 511 164 138 672  18 428 154 448 848
  9245.           414 456 310 312 798 104 566 520 302 248 694 976 430 392 198
  9246.           184 829 373 181 631 101 969 613 840 740 778 458 284 760 390
  9247.           821 461 843 513  17 901 711 993 293 157 274  94 192 156 574
  9248.            34 124   4 878 450 476 712 914 838 669 875 299 823 329 699
  9249.           815 559 813 459 522 788 168 586 966 232 308 833 251 631 107
  9250.           813 883 451 509 615  77 281 613 459 205 380 274 302  35 805
  9251.  
  9252.    
  9253.    Answer: 13938
  9254.  
  9255.  
  9256. Problem 346
  9257. ===========
  9258.  
  9259.  
  9260.    The number 7 is special, because 7 is 111 written in base 2, and 11
  9261.    written in base 6
  9262.    (i.e. 7[10] = 11[6] = 111[2]). In other words, 7 is a repunit in at least
  9263.    two bases b > 1.
  9264.  
  9265.    We shall call a positive integer with this property a strong repunit. It
  9266.    can be verified that there are 8 strong repunits below 50:
  9267.    {1,7,13,15,21,31,40,43}.
  9268.    Furthermore, the sum of all strong repunits below 1000 equals 15864.
  9269.  
  9270.    Find the sum of all strong repunits below 10^12.
  9271.    
  9272.    Answer: a17874b5a9ec9d7fc8c6489ab8ff29b9
  9273.  
  9274.  
  9275. Problem 347
  9276. ===========
  9277.  
  9278.  
  9279.    The largest integer ≤ 100 that is only divisible by both the primes 2 and
  9280.    3 is 96, as 96=32*3=2^5*3.For two distinct primes p and q let M(p,q,N) be
  9281.    the largest positive integer ≤N only divisibleby both p and q and
  9282.    M(p,q,N)=0 if such a positive integer does not exist.
  9283.  
  9284.    E.g. M(2,3,100)=96.
  9285.    M(3,5,100)=75 and not 90 because 90 is divisible by 2 ,3 and 5.
  9286.    Also M(2,73,100)=0 because there does not exist a positive integer ≤ 100
  9287.    that is divisible by both 2 and 73.
  9288.  
  9289.    Let S(N) be the sum of all distinct M(p,q,N).S(100)=2262.
  9290.  
  9291.    Find S(10 000 000).
  9292.  
  9293.    
  9294.    Answer: 96ce0eabcbe7a2b2eb1197a1bcc5d37b
  9295.  
  9296.  
  9297. Problem 348
  9298. ===========
  9299.  
  9300.  
  9301.    Many numbers can be expressed as the sum of a square and a cube. Some of
  9302.    them in more than one way.
  9303.  
  9304.    Consider the palindromic numbers that can be expressed as the sum of a
  9305.    square and a cube, both greater than 1, in exactly 4 different ways.
  9306.    For example, 5229225 is a palindromic number and it can be expressed in
  9307.    exactly 4 different ways:
  9308.  
  9309.    2285^2 + 20^3
  9310.    2223^2 + 66^3
  9311.    1810^2 + 125^3
  9312.    1197^2 + 156^3
  9313.  
  9314.    Find the sum of the five smallest such palindromic numbers.
  9315.  
  9316.    
  9317.    Answer: f286f9159fc20aeb97a8bf8396ba64de
  9318.  
  9319.  
  9320. Problem 349
  9321. ===========
  9322.  
  9323.  
  9324.    An ant moves on a regular grid of squares that are coloured either black
  9325.    or white.
  9326.    The ant is always oriented in one of the cardinal directions (left, right,
  9327.    up or down) and moves from square to adjacent square according to the
  9328.    following rules:
  9329.    - if it is on a black square, it flips the color of the square to white,
  9330.    rotates 90 degrees counterclockwise and moves forward one square.
  9331.    - if it is on a white square, it flips the color of the square to black,
  9332.    rotates 90 degrees clockwise and moves forward one square.
  9333.  
  9334.    Starting with a grid that is entirely white, how many squares are black
  9335.    after 10^18 moves of the ant?
  9336.  
  9337.    
  9338.    Answer: 412b0faec10b3adb415363d2df26530d
  9339.  
  9340.  
  9341. Problem 350
  9342. ===========
  9343.  
  9344.  
  9345.    A list of size n is a sequence of n natural numbers.
  9346.    Examples are (2,4,6), (2,6,4), (10,6,15,6), and (11).
  9347.  
  9348.    The greatest common divisor, or gcd, of a list is the largest natural
  9349.    number that divides all entries of the list.
  9350.    Examples: gcd(2,6,4) = 2, gcd(10,6,15,6) = 1 and gcd(11) = 11.
  9351.  
  9352.    The least common multiple, or lcm, of a list is the smallest natural
  9353.    number divisible by each entry of the list.
  9354.    Examples: lcm(2,6,4) = 12, lcm(10,6,15,6) = 30 and lcm(11) = 11.
  9355.  
  9356.    Let f(G, L, N) be the number of lists of size N with gcd ≥ G and lcm ≤ L.
  9357.    For example:
  9358.  
  9359.    f(10, 100, 1) = 91.
  9360.    f(10, 100, 2) = 327.
  9361.    f(10, 100, 3) = 1135.
  9362.    f(10, 100, 1000) mod 101^4 = 3286053.
  9363.  
  9364.    Find f(10^6, 10^12, 10^18) mod 101^4.
  9365.  
  9366.    
  9367.    Answer: 84664213
  9368.  
  9369.  
  9370. Problem 351
  9371. ===========
  9372.  
  9373.  
  9374.    A hexagonal orchard of order n is a triangular lattice made up of points
  9375.    within a regular hexagon with side n. The following is an example of a
  9376.    hexagonal orchard of order 5:
  9377.  
  9378.    Highlighted in green are the points which are hidden from the center by a
  9379.    point closer to it. It can be seen that for a hexagonal orchard of order
  9380.    5, 30 points are hidden from the center.
  9381.  
  9382.    Let H(n) be the number of points hidden from the center in a hexagonal
  9383.    orchard of order n.
  9384.  
  9385.    H(5) = 30. H(10) = 138. H(1 000) = 1177848.
  9386.  
  9387.    Find H(100 000 000).
  9388.  
  9389.    
  9390.    p_351_hexorchard.png
  9391.    Answer: 338481092e945257756075a8d03978fd
  9392.  
  9393.  
  9394. Problem 352
  9395. ===========
  9396.  
  9397.  
  9398.    Each one of the 25 sheep in a flock must be tested for a rare virus, known
  9399.    to affect 2% of the sheep population.An accurate and extremely sensitive
  9400.    PCR test exists for blood samples, producing a clear positive / negative
  9401.    result, but it is very time-consuming and expensive.
  9402.  
  9403.    Because of the high cost, the vet-in-charge suggests that instead of
  9404.    performing 25 separate tests, the following procedure can be used instead:
  9405.  
  9406.    The sheep are split into 5 groups of 5 sheep in each group. For each
  9407.    group, the 5 samples are mixed together and a single test is performed.
  9408.    Then,
  9409.  
  9410.      • If the result is negative, all the sheep in that group are deemed to
  9411.        be virus-free.
  9412.      • If the result is positive, 5 additional tests will be performed (a
  9413.        separate test for each animal) to determine the affected
  9414.        individual(s).
  9415.  
  9416.    Since the probability of infection for any specific animal is only 0.02,
  9417.    the first test (on the pooled samples) for each group will be:
  9418.  
  9419.      • Negative (and no more tests needed) with probability 0.98^5 =
  9420.        0.9039207968.
  9421.      • Positive (5 additional tests needed) with probability 1 - 0.9039207968
  9422.        = 0.0960792032.
  9423.  
  9424.    Thus, the expected number of tests for each group is 1 + 0.0960792032 × 5
  9425.    = 1.480396016.
  9426.    Consequently, all 5 groups can be screened using an average of only
  9427.    1.480396016 × 5 = 7.40198008 tests, which represents a huge saving of more
  9428.    than 70% !
  9429.  
  9430.    Although the scheme we have just described seems to be very efficient, it
  9431.    can still be improved considerably (always assuming that the test is
  9432.    sufficiently sensitive and that there are no adverse effects caused by
  9433.    mixing different samples). E.g.:
  9434.  
  9435.      • We may start by running a test on a mixture of all the 25 samples. It
  9436.        can be verified that in about 60.35% of the cases this test will be
  9437.        negative, thus no more tests will be needed. Further testing will only
  9438.        be required for the remaining 39.65% of the cases.
  9439.      • If we know that at least one animal in a group of 5 is infected and
  9440.        the first 4 individual tests come out negative, there is no need to
  9441.        run a test on the fifth animal (we know that it must be infected).
  9442.      • We can try a different number of groups / different number of animals
  9443.        in each group, adjusting those numbers at each level so that the total
  9444.        expected number of tests will be minimised.
  9445.  
  9446.    To simplify the very wide range of possibilities, there is one restriction
  9447.    we place when devising the most cost-efficient testing scheme: whenever we
  9448.    start with a mixed sample, all the sheep contributing to that sample must
  9449.    be fully screened (i.e. a verdict of infected / virus-free must be reached
  9450.    for all of them) before we start examining any other animals.
  9451.  
  9452.    For the current example, it turns out that the most cost-efficient testing
  9453.    scheme (we'll call it the optimal strategy) requires an average of just
  9454.    4.155452 tests!
  9455.  
  9456.    Using the optimal strategy, let T(s,p) represent the average number of
  9457.    tests needed to screen a flock of s sheep for a virus having probability p
  9458.    to be present in any individual.
  9459.    Thus, rounded to six decimal places, T(25, 0.02) = 4.155452 and T(25,
  9460.    0.10) = 12.702124.
  9461.  
  9462.    Find ΣT(10000, p) for p=0.01, 0.02, 0.03, ... 0.50.
  9463.    Give your answer rounded to six decimal places.
  9464.  
  9465.    
  9466.    Answer: 2e74b2fb574d6318cdbf2a41ad006de7
  9467.  
  9468.  
  9469. Problem 353
  9470. ===========
  9471.  
  9472.  
  9473.    A moon could be described by the sphere C(r) with centre (0,0,0) and
  9474.    radius r.
  9475.  
  9476.    There are stations on the moon at the points on the surface of C(r) with
  9477.    integer coordinates. The station at (0,0,r) is called North Pole station,
  9478.    the station at (0,0,-r) is called South Pole station.
  9479.  
  9480.    All stations are connected with each other via the shortest road on the
  9481.    great arc through the stations. A journey between two stations is risky.
  9482.    If d is the length of the road between two stations, (d/(π r))^2 is a
  9483.    measure for the risk of the journey (let us call it the risk of the road).
  9484.    If the journey includes more than two stations, the risk of the journey is
  9485.    the sum of risks of the used roads.
  9486.  
  9487.    A direct journey from the North Pole station to the South Pole station has
  9488.    the length πr and risk 1. The journey from the North Pole station to the
  9489.    South Pole station via (0,r,0) has the same length, but a smaller risk:
  9490.    (½πr/(πr))^2+(½πr/(πr))^2=0.5.
  9491.  
  9492.    The minimal risk of a journey from the North Pole station to the South
  9493.    Pole station on C(r) is M(r).
  9494.  
  9495.    You are given that M(7)=0.1784943998 rounded to 10 digits behind the
  9496.    decimal point.
  9497.  
  9498.    Find ∑M(2^n-1) for 1≤n≤15.
  9499.  
  9500.    Give your answer rounded to 10 digits behind the decimal point in the form
  9501.    a.bcdefghijk.
  9502.  
  9503.    
  9504.    Answer: 211b5626459be71baefc78478d18bdc3
  9505.  
  9506.  
  9507. Problem 354
  9508. ===========
  9509.  
  9510.  
  9511.    Consider a honey bee's honeycomb where each cell is a perfect regular
  9512.    hexagon with side length 1.
  9513.  
  9514.    One particular cell is occupied by the queen bee.
  9515.    For a positive real number L, let B(L) count the cells with distance L
  9516.    from the queen bee cell (all distances are measured from centre to
  9517.    centre); you may assume that the honeycomb is large enough to accommodate
  9518.    for any distance we wish to consider.
  9519.    For example, B(√3) = 6, B(√21) = 12 and B(111 111 111) = 54.
  9520.  
  9521.    Find the number of L ≤ 5·10^11 such that B(L) = 450.
  9522.  
  9523.    
  9524.    p_354_bee_honeycomb.png
  9525.    Answer: 58065134
  9526.  
  9527.  
  9528. Problem 355
  9529. ===========
  9530.  
  9531.  
  9532.    Define Co(n) to be the maximal possible sum of a set of mutually co-prime
  9533.    elements from {1, 2, ..., n}.
  9534.    For example Co(10) is 30 and hits that maximum on the subset
  9535.    {1, 5, 7, 8, 9}.
  9536.  
  9537.    You are given that Co(30) = 193 and Co(100) = 1356.
  9538.  
  9539.    Find Co(200000).
  9540.  
  9541.    
  9542.    Answer: 41cb97b6d02878d79f8b2e3b6c74920a
  9543.  
  9544.  
  9545. Problem 356
  9546. ===========
  9547.  
  9548.  
  9549.    Let a[n] be the largest real root of a polynomial g(x) = x^3 - 2^n·x^2 +
  9550.    n.
  9551.    For example, a[2] = 3.86619826...
  9552.  
  9553.    Find the last eight digits of.
  9554.  
  9555.    Note: represents the floor function.
  9556.  
  9557.    
  9558.    p_356_cubicpoly1.gif
  9559.    p_356_cubicpoly2.gif
  9560.    Answer: 28010159
  9561.  
  9562.  
  9563. Problem 357
  9564. ===========
  9565.  
  9566.  
  9567.    Consider the divisors of 30: 1,2,3,5,6,10,15,30.
  9568.    It can be seen that for every divisor d of 30, d+30/d is prime.
  9569.  
  9570.    Find the sum of all positive integers n not exceeding 100 000 000
  9571.    such thatfor every divisor d of n, d+n/d is prime.
  9572.  
  9573.    
  9574.    Answer: ed25b13b18a21c1077fed00ef42f503b
  9575.  
  9576.  
  9577. Problem 358
  9578. ===========
  9579.  
  9580.  
  9581.    A cyclic number with n digits has a very interesting property:
  9582.    When it is multiplied by 1, 2, 3, 4, ... n, all the products have exactly
  9583.    the same digits, in the same order, but rotated in a circular fashion!
  9584.  
  9585.    The smallest cyclic number is the 6-digit number 142857 :
  9586.    142857 × 1 = 142857
  9587.    142857 × 2 = 285714
  9588.    142857 × 3 = 428571
  9589.    142857 × 4 = 571428
  9590.    142857 × 5 = 714285
  9591.    142857 × 6 = 857142
  9592.  
  9593.    The next cyclic number is 0588235294117647 with 16 digits :
  9594.    0588235294117647 × 1 = 0588235294117647
  9595.    0588235294117647 × 2 = 1176470588235294
  9596.    0588235294117647 × 3 = 1764705882352941
  9597.    ...
  9598.    0588235294117647 × 16 = 9411764705882352
  9599.  
  9600.    Note that for cyclic numbers, leading zeros are important.
  9601.  
  9602.    There is only one cyclic number for which, the eleven leftmost digits are
  9603.    00000000137 and the five rightmost digits are 56789 (i.e., it has the form
  9604.    00000000137...56789 with an unknown number of digits in the middle). Find
  9605.    the sum of all its digits.
  9606.  
  9607.    
  9608.    Answer: 359e1ec8aeaa3932b54f2a5d20fa4f73
  9609.  
  9610.  
  9611. Problem 359
  9612. ===========
  9613.  
  9614.  
  9615.    An infinite number of people (numbered 1, 2, 3, etc.) are lined up to get
  9616.    a room at Hilbert's newest infinite hotel. The hotel contains an infinite
  9617.    number of floors (numbered 1, 2, 3, etc.), and each floor contains an
  9618.    infinite number of rooms (numbered 1, 2, 3, etc.).
  9619.  
  9620.    Initially the hotel is empty. Hilbert declares a rule on how the n^th
  9621.    person is assigned a room: person n gets the first vacant room in the
  9622.    lowest numbered floor satisfying either of the following:
  9623.  
  9624.      • the floor is empty
  9625.      • the floor is not empty, and if the latest person taking a room in that
  9626.        floor is person m, then m + n is a perfect square
  9627.  
  9628.    Person 1 gets room 1 in floor 1 since floor 1 is empty.
  9629.    Person 2 does not get room 2 in floor 1 since 1 + 2 = 3 is not a perfect
  9630.    square.
  9631.    Person 2 instead gets room 1 in floor 2 since floor 2 is empty.
  9632.    Person 3 gets room 2 in floor 1 since 1 + 3 = 4 is a perfect square.
  9633.  
  9634.    Eventually, every person in the line gets a room in the hotel.
  9635.  
  9636.    Define P(f, r) to be n if person n occupies room r in floor f, and 0 if no
  9637.    person occupies the room. Here are a few examples:
  9638.    P(1, 1) = 1
  9639.    P(1, 2) = 3
  9640.    P(2, 1) = 2
  9641.    P(10, 20) = 440
  9642.    P(25, 75) = 4863
  9643.    P(99, 100) = 19454
  9644.  
  9645.    Find the sum of all P(f, r) for all positive f and r such that f × r =
  9646.    71328803586048 and give the last 8 digits as your answer.
  9647.  
  9648.    
  9649.    Answer: 40632119
  9650.  
  9651.  
  9652. Problem 360
  9653. ===========
  9654.  
  9655.  
  9656.    Given two points (x[1],y[1],z[1]) and (x[2],y[2],z[2]) in three
  9657.    dimensional space, the Manhattan distance between those points is defined
  9658.    as
  9659.    |x[1]-x[2]|+|y[1]-y[2]|+|z[1]-z[2]|.
  9660.  
  9661.    Let C(r) be a sphere with radius r and center in the origin O(0,0,0).
  9662.    Let I(r) be the set of all points with integer coordinates on the surface
  9663.    of C(r).
  9664.    Let S(r) be the sum of the Manhattan distances of all elements of I(r) to
  9665.    the origin O.
  9666.  
  9667.    E.g. S(45)=34518.
  9668.  
  9669.    Find S(10^10).
  9670.  
  9671.    
  9672.    Answer: 82ec91527315eafb7e3acc139eeeb8eb
  9673.  
  9674.  
  9675. Problem 361
  9676. ===========
  9677.  
  9678.  
  9679.    The Thue-Morse sequence {T[n]} is a binary sequence satisfying:
  9680.  
  9681.      • T[0] = 0
  9682.      • T[2n] = T[n]
  9683.      • T[2n+1] = 1 - T[n]
  9684.  
  9685.    The first several terms of {T[n]} are given as follows:
  9686.    01101001100101101001011001101001....
  9687.  
  9688.    We define {A[n]} as the sorted sequence of integers such that the binary
  9689.    expression of each element appears as a subsequence in {T[n]}.
  9690.    For example, the decimal number 18 is expressed as 10010 in binary. 10010
  9691.    appears in {T[n]} (T[8] to T[12]), so 18 is an element of {A[n]}.
  9692.    The decimal number 14 is expressed as 1110 in binary. 1110 never appears
  9693.    in {T[n]}, so 14 is not an element of {A[n]}.
  9694.  
  9695.    The first several terms of A[n] are given as follows:
  9696.  
  9697.               n     0  1  2  3  4  5  6  7  8   9   10  11  12  …
  9698.               A[n]  0  1  2  3  4  5  6  9  10  11  12  13  18  …
  9699.  
  9700.    We can also verify that A[100] = 3251 and A[1000] = 80852364498.
  9701.  
  9702.    Find the last 9 digits of .
  9703.  
  9704.    
  9705.    p_361_Thue-Morse1.gif
  9706.    Answer: 178476944
  9707.  
  9708.  
  9709. Problem 362
  9710. ===========
  9711.  
  9712.  
  9713.    Consider the number 54.
  9714.    54 can be factored in 7 distinct ways into one or more factors larger than
  9715.    1:
  9716.    54, 2×27, 3×18, 6×9, 3×3×6, 2×3×9 and 2×3×3×3.
  9717.    If we require that the factors are all squarefree only two ways remain:
  9718.    3×3×6 and 2×3×3×3.
  9719.  
  9720.    Let's call Fsf(n) the number of ways n can be factored into one or more
  9721.    squarefree factors larger than 1, soFsf(54)=2.
  9722.  
  9723.    Let S(n) be ∑Fsf(k) for k=2 to n.
  9724.  
  9725.    S(100)=193.
  9726.  
  9727.    Find S(10 000 000 000).
  9728.  
  9729.    
  9730.    Answer: b62f0d524bec8653ba7b8a2cab70260b
  9731.  
  9732.  
  9733. Problem 363
  9734. ===========
  9735.  
  9736.    A cubic Bézier curve is defined by four points: P[0], P[1], P[2] and P[3].
  9737.  
  9738.    The curve is constructed as follows:
  9739.    On the segments P[0]P[1], P[1]P[2] and P[2]P[3] the points Q[0],Q[1] and
  9740.    Q[2] are drawn such that
  9741.    P[0]Q[0]/P[0]P[1]=P[1]Q[1]/P[1]P[2]=P[2]Q[2]/P[2]P[3]=t (t in [0,1]).
  9742.    On the segments Q[0]Q[1] and Q[1]Q[2] the points R[0] and R[1] are drawn
  9743.    such thatQ[0]R[0]/Q[0]Q[1]=Q[1]R[1]/Q[1]Q[2]=t for the same value of t.
  9744.    On the segment R[0]R[1] the point B is drawn such that R[0]B/R[0]R[1]=t
  9745.    for the same value of t.The Bézier curve defined by the points P[0], P[1],
  9746.    P[2], P[3] is the locus of B as Q[0] takes all possible positions on the
  9747.    segment P[0]P[1]. (Please note that for all points the value of t is the
  9748.    same.)
  9749.  
  9750.    [1]Applet
  9751.  
  9752.    In the applet to the right you can drag the points P[0], P[1], P[2] and
  9753.    P[3] to see what the Bézier curve (green curve) defined by those points
  9754.    looks like. You can also drag the point Q[0] along the segment P[0]P[1].
  9755.  
  9756.    From the construction it is clear that the Bézier curve will be tangent to
  9757.    the segments P[0]P[1] in P[0] and P[2]P[3] in P[3].
  9758.  
  9759.    A cubic Bézier curve with P[0]=(1,0), P[1]=(1,v), P[2]=(v,1) and
  9760.    P[3]=(0,1) is used to approximate a quarter circle.
  9761.    The value v>0 is chosen such that the area enclosed by the lines OP[0],
  9762.    OP[3] and the curve is equal to ^π/[4] (the area of the quarter circle).
  9763.  
  9764.    By how many percent does the length of the curve differ from the length of
  9765.    the quarter circle?
  9766.    That is, if L is the length of the curve, calculate 100*^(L-π/2)/[(π/2)].
  9767.    Give your answer rounded to 10 digits behind the decimal point.
  9768.  
  9769.  
  9770.    Visible links
  9771.    1. CabriJava.class
  9772.    Answer: 2bc63386b7cccc64c67f90e719936143
  9773.  
  9774.  
  9775. Problem 364
  9776. ===========
  9777.  
  9778.  
  9779.    There are N seats in a row. N people come after each other to fill the
  9780.    seats according to the following rules:
  9781.  
  9782.     1. If there is any seat whose adjacent seat(s) are not occupied take such
  9783.        a seat.
  9784.     2. If there is no such seat and there is any seat for which only one
  9785.        adjacent seat is occupied take such a seat.
  9786.     3. Otherwise take one of the remaining available seats.
  9787.  
  9788.    Let T(N) be the number of possibilities that N seats are occupied by N
  9789.    people with the given rules.
  9790.    The following figure shows T(4)=8.
  9791.  
  9792.    We can verify that T(10) = 61632 and T(1 000) mod 100 000 007 = 47255094.
  9793.  
  9794.    Find T(1 000 000) mod 100 000 007.
  9795.  
  9796.    
  9797.    p_364_comf_dist.gif
  9798.    Answer: 44855254
  9799.  
  9800.  
  9801. Problem 365
  9802. ===========
  9803.  
  9804.  
  9805.    The binomial coeffient C(10^18,10^9) is a number with more than 9 billion
  9806.    (9×10^9) digits.
  9807.  
  9808.    Let M(n,k,m) denote the binomial coefficient C(n,k) modulo m.
  9809.  
  9810.    Calculate ∑M(10^18,10^9,p*q*r) for 1000<p<q<r<5000 and p,q,r prime.
  9811.  
  9812.    
  9813.    Answer: 53addf69042b0cefbeb94f3bd3224918
  9814.  
  9815.  
  9816. Problem 366
  9817. ===========
  9818.  
  9819.  
  9820.    Two players, Anton and Bernhard, are playing the following game.
  9821.    There is one pile of n stones.
  9822.    The first player may remove any positive number of stones, but not the
  9823.    whole pile.
  9824.    Thereafter, each player may remove at most twice the number of stones his
  9825.    opponent took on the previous move.
  9826.    The player who removes the last stone wins.
  9827.  
  9828.    E.g. n=5
  9829.    If the first player takes anything more than one stone the next player
  9830.    will be able to take all remaining stones.
  9831.    If the first player takes one stone, leaving four, his opponent will take
  9832.    also one stone, leaving three stones.
  9833.    The first player cannot take all three because he may take at most 2x1=2
  9834.    stones. So let's say he takes also one stone, leaving 2. The second player
  9835.    can take the two remaining stones and wins.
  9836.    So 5 is a losing position for the first player.
  9837.    For some winning positions there is more than one possible move for the
  9838.    first player.
  9839.    E.g. when n=17 the first player can remove one or four stones.
  9840.  
  9841.    Let M(n) be the maximum number of stones the first player can take from a
  9842.    winning position at his first turn and M(n)=0 for any other position.
  9843.  
  9844.    ∑M(n) for n≤100 is 728.
  9845.  
  9846.    Find ∑M(n) for n≤10^18.Give your answer modulo 10^8.
  9847.  
  9848.    
  9849.    Answer: 88351299
  9850.  
  9851.  
  9852. Problem 367
  9853. ===========
  9854.  
  9855.  
  9856.    Bozo sort, not to be confused with the slightly less efficient bogo sort,
  9857.    consists out of checking if the input sequence is sorted and if not
  9858.    swapping randomly two elements. This is repeated until eventually the
  9859.    sequence is sorted.
  9860.  
  9861.    If we consider all permutations of the first 4 natural numbers as input
  9862.    the expectation value of the number of swaps, averaged over all 4! input
  9863.    sequences is 24.75.
  9864.    The already sorted sequence takes 0 steps.
  9865.  
  9866.    In this problem we consider the following variant on bozo sort.
  9867.    If the sequence is not in order we pick three elements at random and
  9868.    shuffle these three elements randomly.
  9869.    All 3!=6 permutations of those three elements are equally likely.
  9870.    The already sorted sequence will take 0 steps.
  9871.    If we consider all permutations of the first 4 natural numbers as input
  9872.    the expectation value of the number of shuffles, averaged over all 4!
  9873.    input sequences is 27.5.
  9874.    Consider as input sequences the permutations of the first 11 natural
  9875.    numbers.
  9876.    Averaged over all 11! input sequences, what is the expected number of
  9877.    shuffles this sorting algorithm will perform?
  9878.  
  9879.    Give your answer rounded to the nearest integer.
  9880.  
  9881.    
  9882.    Answer: 48271207
  9883.  
  9884.  
  9885. Problem 368
  9886. ===========
  9887.  
  9888.  
  9889.    The harmonic series 1 + 1 + 1 + 1 + ... is well known to be divergent.
  9890.                            2   3   4
  9891.  
  9892.    If we however omit from this series every term where the denominator has a
  9893.    9 in it, the series remarkably enough converges to approximately
  9894.    22.9206766193.
  9895.    This modified harmonic series is called the Kempner series.
  9896.  
  9897.    Let us now consider another modified harmonic series by omitting from the
  9898.    harmonic series every term where the denominator has 3 or more equal
  9899.    consecutive digits.One can verify that out of the first 1200 terms of the
  9900.    harmonic series, only 20 terms will be omitted.
  9901.    These 20 omitted terms are:
  9902.  
  9903.    1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1   , 1    , 1    ,
  9904.    111   222   333   444   555   666   777   888   999   1000   1110
  9905.  
  9906.    1    , 1    , 1    , 1    , 1    , 1    , 1    , 1    and 1    .
  9907.    1111   1112   1113   1114   1115   1116   1117   1118     1119
  9908.  
  9909.    This series converges as well.
  9910.  
  9911.    Find the value the series converges to.
  9912.    Give your answer rounded to 10 digits behind the decimal point.
  9913.  
  9914.    
  9915.    Answer: bfb15c388f4721cbd5eb89f17be2eef2
  9916.  
  9917.  
  9918. Problem 369
  9919. ===========
  9920.  
  9921.  
  9922.    In a standard 52 card deck of playing cards, a set of 4 cards is a Badugi
  9923.    if it contains 4 cards with no pairs and no two cards of the same suit.
  9924.  
  9925.    Let f(n) be the number of ways to choose n cards with a 4 card subset that
  9926.    is a Badugi. For example, there are 2598960 ways to choose five cards from
  9927.    a standard 52 card deck, of which 514800 contain a 4 card subset that is a
  9928.    Badugi, so f(5) = 514800.
  9929.  
  9930.    Find ∑f(n) for 4 ≤ n ≤ 13.
  9931.  
  9932.    
  9933.    Answer: 0f8828f58dbac4f15f296c79b686ed0e
  9934.  
  9935.  
  9936. Problem 370
  9937. ===========
  9938.  
  9939.  
  9940.    Let us define a geometric triangle as an integer sided triangle with sides
  9941.    a ≤ b ≤ c so that its sides form a geometric progression, i.e.
  9942.    b^2 = a · c . 
  9943.  
  9944.    An example of such a geometric triangle is the triangle with sides a =
  9945.    144, b = 156 and c = 169.
  9946.  
  9947.    There are 861805 geometric triangles with perimeter ≤ 10^6 .
  9948.  
  9949.    How many geometric triangles exist with perimeter ≤ 2.5·10^13 ?
  9950.  
  9951.    
  9952.    Answer: 85b5048e25677205555a5308991c2e04
  9953.  
  9954.  
  9955. Problem 371
  9956. ===========
  9957.  
  9958.  
  9959.    Oregon licence plates consist of three letters followed by a three digit
  9960.    number (each digit can be from [0..9]).
  9961.    While driving to work Seth plays the following game:
  9962.    Whenever the numbers of two licence plates seen on his trip add to 1000
  9963.    that's a win.
  9964.  
  9965.    E.g. MIC-012 and HAN-988 is a win and RYU-500 and SET-500 too. (as long as
  9966.    he sees them in the same trip).
  9967.  
  9968.    Find the expected number of plates he needs to see for a win.
  9969.    Give your answer rounded to 8 decimal places behind the decimal point.
  9970.  
  9971.    Note: We assume that each licence plate seen is equally likely to have any
  9972.    three digit number on it.
  9973.  
  9974.    
  9975.    Answer: 537403a97924621c604ce5ab6288b97d
  9976.  
  9977.  
  9978. Problem 372
  9979. ===========
  9980.  
  9981.  
  9982.    Let R(M, N) be the number of lattice points (x, y) which satisfy M<x≤N,
  9983.    M<y≤N and is odd.
  9984.    We can verify that R(0, 100) = 3019 and R(100, 10000) = 29750422.
  9985.    Find R(2·10^6, 10^9).
  9986.  
  9987.    Note: represents the floor function.
  9988.  
  9989.    
  9990.    p_372_pencilray1.jpg
  9991.    p_372_pencilray2.gif
  9992.    Answer: 5fdeda0dca23d12ae3eb1763b2c6f5ea
  9993.  
  9994.  
  9995. Problem 373
  9996. ===========
  9997.  
  9998.  
  9999.    Every triangle has a circumscribed circle that goes through the three
  10000.    vertices.Consider all integer sided triangles for which the radius of the
  10001.    circumscribed circle is integral as well.
  10002.  
  10003.    Let S(n) be the sum of the radii of the circumscribed circles of all such
  10004.    triangles for which the radius does not exceed n.
  10005.  
  10006.    S(100)=4950 and S(1200)=1653605.
  10007.  
  10008.    Find S(10^7).
  10009.  
  10010.    
  10011.    Answer: 888d60a6b2b4b9146d7c9c14ffd82673
  10012.  
  10013.  
  10014. Problem 374
  10015. ===========
  10016.  
  10017.  
  10018.    An integer partition of a number n is a way of writing n as a sum of
  10019.    positive integers.
  10020.  
  10021.    Partitions that differ only in the order of their summands are considered
  10022.    the same.A partition of n into distinct parts is a partition of n in which
  10023.    every part occurs at most once.
  10024.  
  10025.    The partitions of 5 into distinct parts are:
  10026.    5, 4+1 and 3+2.
  10027.  
  10028.    Let f(n) be the maximum product of the parts of any such partition of n
  10029.    into distinct parts and let m(n) be the number of elements of any such
  10030.    partition of n with that product.
  10031.  
  10032.    So f(5)=6 and m(5)=2.
  10033.  
  10034.    For n=10 the partition with the largest product is 10=2+3+5, which gives
  10035.    f(10)=30 and m(10)=3.
  10036.    And their product, f(10)·m(10) = 30·3 = 90
  10037.  
  10038.    It can be verified that
  10039.    ∑f(n)·m(n) for 1 ≤ n ≤ 100 = 1683550844462.
  10040.  
  10041.    Find ∑f(n)·m(n) for 1 ≤ n ≤ 10^14.
  10042.    Give your answer modulo 982451653, the 50 millionth prime.
  10043.  
  10044.    
  10045.    Answer: 6fcb063062076b5aaaff3e3cd03e4b2f
  10046.  
  10047.  
  10048. Problem 375
  10049. ===========
  10050.  
  10051.  
  10052.    Let S[n] be an integer sequence produced with the following pseudo-random
  10053.    number generator:
  10054.  
  10055.                         S[0]   =[ ] 290797[ ]
  10056.                         S[n+1] =[ ] S[n]^2 mod 50515093
  10057.  
  10058.    Let A(i, j) be the minimum of the numbers S[i], S[i+1], ... , S[j] for i ≤
  10059.    j.
  10060.    Let M(N) = ΣA(i, j) for 1 ≤ i ≤ j ≤ N.
  10061.    We can verify that M(10) = 432256955 and M(10 000) = 3264567774119.
  10062.  
  10063.    Find M(2 000 000 000).
  10064.  
  10065.    
  10066.    Answer: 68a12e3f2e4ccbae9c8555e547fbe096
  10067.  
  10068.  
  10069. Problem 376
  10070. ===========
  10071.  
  10072.  
  10073.    Consider the following set of dice with nonstandard pips:
  10074.  
  10075.    Die A: 1 4 4 4 4 4
  10076.    Die B: 2 2 2 5 5 5
  10077.    Die C: 3 3 3 3 3 6
  10078.  
  10079.    A game is played by two players picking a die in turn and rolling it. The
  10080.    player who rolls the highest value wins.
  10081.  
  10082.    If the first player picks die A and the second player picks die B we get
  10083.    P(second player wins) = 7/12 > 1/2
  10084.  
  10085.    If the first player picks die B and the second player picks die C we get
  10086.    P(second player wins) = 7/12 > 1/2
  10087.  
  10088.    If the first player picks die C and the second player picks die A we get
  10089.    P(second player wins) = 25/36 > 1/2
  10090.  
  10091.    So whatever die the first player picks, the second player can pick another
  10092.    die and have a larger than 50% chance of winning.
  10093.    A set of dice having this property is called a nontransitive set of dice.
  10094.  
  10095.    We wish to investigate how many sets of nontransitive dice exist. We will
  10096.    assume the following conditions:
  10097.  
  10098.      • There are three six-sided dice with each side having between 1 and N
  10099.        pips, inclusive.
  10100.      • Dice with the same set of pips are equal, regardless of which side on
  10101.        the die the pips are located.
  10102.      • The same pip value may appear on multiple dice; if both players roll
  10103.        the same value neither player wins.
  10104.      • The sets of dice {A,B,C}, {B,C,A} and {C,A,B} are the same set.
  10105.  
  10106.    For N = 7 we find there are 9780 such sets.
  10107.    How many are there for N = 30 ?
  10108.  
  10109.    
  10110.    Answer: c64df302990eb3738f8ec62ea6b66c0b
  10111.  
  10112.  
  10113. Problem 377
  10114. ===========
  10115.  
  10116.  
  10117.    There are 16 positive integers that do not have a zero in their digits and
  10118.    that have a digital sum equal to 5, namely:
  10119.    5, 14, 23, 32, 41, 113, 122, 131, 212, 221, 311, 1112, 1121, 1211, 2111
  10120.    and 11111.
  10121.    Their sum is 17891.
  10122.  
  10123.    Let f(n) be the sum of all positive integers that do not have a zero in
  10124.    their digits and have a digital sum equal to n.
  10125.  
  10126.    Find .
  10127.    Give the last 9 digits as your answer.
  10128.  
  10129.    
  10130.    Answer: a915ccbae49de15208c88affba84d206
  10131.  
  10132.  
  10133. Problem 378
  10134. ===========
  10135.  
  10136.  
  10137.    Let T(n) be the n^th triangle number, so T(n) = n (n+1) .
  10138.                                                    2
  10139.  
  10140.    Let dT(n) be the number of divisors of T(n).
  10141.    E.g.:T(7) = 28 and dT(7) = 6.
  10142.  
  10143.    Let Tr(n) be the number of triples (i, j, k) such that 1 ≤ i < j < k ≤ n
  10144.    and dT(i) > dT(j) > dT(k).
  10145.    Tr(20) = 14, Tr(100) = 5772 and Tr(1000) = 11174776.
  10146.  
  10147.    Find Tr(60 000 000).
  10148.    Give the last 18 digits of your answer.
  10149.  
  10150.    
  10151.    Answer: 336745dc9d90928596237c4b471a8927
  10152.  
  10153.  
  10154. Problem 379
  10155. ===========
  10156.  
  10157.  
  10158.    Let f(n) be the number of couples (x,y) with x and y positive integers, x
  10159.    ≤ y and the least common multiple of x and y equal to n.
  10160.  
  10161.    Let g be the summatory function of f, i.e.: g(n) = ∑ f(i) for 1 ≤ i ≤ n.
  10162.  
  10163.    You are given that g(10^6) = 37429395.
  10164.  
  10165.    Find g(10^12).
  10166.  
  10167.    
  10168.    Answer: de20f710cb6665c48795072197ad53e0
  10169.  
  10170.  
  10171. Problem 380
  10172. ===========
  10173.  
  10174.  
  10175.    An m×n maze is an m×n rectangular grid with walls placed between grid
  10176.    cells such that there is exactly one path from the top-left square to any
  10177.    other square.
  10178.    The following are examples of a 9×12 maze and a 15×20 maze:
  10179.  
  10180.    Let C(m,n) be the number of distinct m×n mazes. Mazes which can be formed
  10181.    by rotation and reflection from another maze are considered distinct.
  10182.  
  10183.    It can be verified that C(1,1) = 1, C(2,2) = 4, C(3,4) = 2415, and C(9,12)
  10184.    = 2.5720e46 (in scientific notation rounded to 5 significant digits).
  10185.    Find C(100,500) and write your answer in scientific notation rounded to 5
  10186.    significant digits.
  10187.  
  10188.    When giving your answer, use a lowercase e to separate mantissa and
  10189.    exponent.E.g. if the answer is 1234567891011 then the answer format would
  10190.    be 1.2346e12.
  10191.  
  10192.    
  10193.    Answer: c86d2f4c17c8134fbebed5d37a0f90d7
  10194.  
  10195.  
  10196. Problem 381
  10197. ===========
  10198.  
  10199.  
  10200.    For a prime p let S(p) = (∑(p-k)!) mod(p) for 1 ≤ k ≤ 5.
  10201.  
  10202.    For example, if p=7,
  10203.    (7-1)! + (7-2)! + (7-3)! + (7-4)! + (7-5)! = 6! + 5! + 4! + 3! + 2! =
  10204.    720+120+24+6+2 = 872.
  10205.    As 872 mod(7) = 4, S(7) = 4.
  10206.  
  10207.    It can be verified that ∑S(p) = 480 for 5 ≤ p < 100.
  10208.  
  10209.    Find ∑S(p) for 5 ≤ p < 10^8.
  10210.  
  10211.    
  10212.    Answer: 80c84973a9643e46d49d79d7284e7ff3
  10213.  
  10214.  
  10215. Problem 382
  10216. ===========
  10217.  
  10218.  
  10219.    A polygon is a flat shape consisting of straight line segments that are
  10220.    joined to form a closed chain or circuit. A polygon consists of at least
  10221.    three sides and does not self-intersect.
  10222.  
  10223.    A set S of positive numbers is said to generate a polygon P if:
  10224.  
  10225.      • no two sides of P are the same length,
  10226.      • the length of every side of P is in S, and
  10227.      • S contains no other value.
  10228.  
  10229.    For example:
  10230.    The set {3, 4, 5} generates a polygon with sides 3, 4, and 5 (a triangle).
  10231.    The set {6, 9, 11, 24} generates a polygon with sides 6, 9, 11, and 24 (a
  10232.    quadrilateral).
  10233.    The sets {1, 2, 3} and {2, 3, 4, 9} do not generate any polygon at all.
  10234.  
  10235.    Consider the sequence s, defined as follows:
  10236.  
  10237.      • s[1] = 1, s[2] = 2, s[3] = 3
  10238.      • s[n] = s[n-1] + s[n-3] for n > 3.
  10239.  
  10240.    Let U[n] be the set {s[1], s[2], ..., s[n]}. For example, U[10] = {1, 2,
  10241.    3, 4, 6, 9, 13, 19, 28, 41}.
  10242.    Let f(n) be the number of subsets of U[n] which generate at least one
  10243.    polygon.
  10244.    For example, f(5) = 7, f(10) = 501 and f(25) = 18635853.
  10245.  
  10246.    Find the last 9 digits of f(10^18).
  10247.  
  10248.    
  10249.    Answer: 56a121bcf3bb674d0d3ce561b6b24ea5
  10250.  
  10251.  
  10252. Problem 383
  10253. ===========
  10254.  
  10255.  
  10256.    Let f[5](n) be the largest integer x for which 5^x divides n.
  10257.    For example, f[5](625000) = 7.
  10258.  
  10259.    Let T[5](n) be the number of integers i which satisfy f[5]((2·i-1)!) <
  10260.    2·f[5](i!) and 1 ≤ i ≤ n.
  10261.    It can be verified that T[5](10^3) = 68 and T[5](10^9) = 2408210.
  10262.  
  10263.    Find T[5](10^18).
  10264.  
  10265.    
  10266.    Answer: c1bc7c945344e1967bfaced9ade895a0
  10267.  
  10268.  
  10269. Problem 384
  10270. ===========
  10271.  
  10272.  
  10273.    Define the sequence a(n) as the number of adjacent pairs of ones in the
  10274.    binary expansion of n (possibly overlapping).
  10275.    E.g.: a(5) = a(101[2]) = 0, a(6) = a(110[2]) = 1, a(7) = a(111[2]) = 2
  10276.  
  10277.    Define the sequence b(n) = (-1)^a(n).
  10278.    This sequence is called the Rudin-Shapiro sequence.
  10279.  
  10280.    Also consider the summatory sequence of b(n): .
  10281.  
  10282.    The first couple of values of these sequences are:
  10283.    n        0     1     2     3     4     5     6     7
  10284.    a(n)     0     0     0     1     0     0     1     2
  10285.    b(n)     1     1     1    -1     1     1    -1     1
  10286.    s(n)     1     2     3     2     3     4     3     4
  10287.  
  10288.    The sequence s(n) has the remarkable property that all elements are
  10289.    positive and every positive integer k occurs exactly k times.
  10290.  
  10291.    Define g(t,c), with 1 ≤ c ≤ t, as the index in s(n) for which t occurs for
  10292.    the c'th time in s(n).
  10293.    E.g.: g(3,3) = 6, g(4,2) = 7 and g(54321,12345) = 1220847710.
  10294.  
  10295.    Let F(n) be the fibonacci sequence defined by:
  10296.    F(0)=F(1)=1 and
  10297.    F(n)=F(n-1)+F(n-2) for n>1.
  10298.  
  10299.    Define GF(t)=g(F(t),F(t-1)).
  10300.  
  10301.    Find ΣGF(t) for 2≤t≤45.
  10302.  
  10303.    
  10304.    Answer: ea0bb1fff1a51b48971762b93aeed103
  10305.  
  10306.  
  10307. Problem 385
  10308. ===========
  10309.  
  10310.  
  10311.    For any triangle T in the plane, it can be shown that there is a unique
  10312.    ellipse with largest area that is completely inside T.
  10313.  
  10314.    For a given n, consider triangles T such that:
  10315.    - the vertices of T have integer coordinates with absolute value ≤ n, and
  10316.    - the foci^1 of the largest-area ellipse inside T are (√13,0) and
  10317.    (-√13,0).
  10318.    Let A(n) be the sum of the areas of all such triangles.
  10319.  
  10320.    For example, if n = 8, there are two such triangles. Their vertices are
  10321.    (-4,-3),(-4,3),(8,0) and (4,3),(4,-3),(-8,0), and the area of each
  10322.    triangle is 36. Thus A(8) = 36 + 36 = 72.
  10323.  
  10324.    It can be verified that A(10) = 252, A(100) = 34632 and A(1000) = 3529008.
  10325.  
  10326.    Find A(1 000 000 000).
  10327.  
  10328.    ^1The foci (plural of focus) of an ellipse are two points A and B such
  10329.    that for every point P on the boundary of the ellipse, AP + PB is
  10330.    constant.
  10331.  
  10332.    
  10333.    Answer: a21c033d9e119c293e51966ea78c9950
  10334.  
  10335.  
  10336. Problem 386
  10337. ===========
  10338.  
  10339.  
  10340.    Let n be an integer and S(n) be the set of factors of n.
  10341.  
  10342.    A subset A of S(n) is called an antichain of S(n) if A contains only one
  10343.    element or if none of the elements of A divides any of the other elements
  10344.    of A.
  10345.  
  10346.    For example: S(30) = {1, 2, 3, 5, 6, 10, 15, 30}
  10347.    {2, 5, 6} is not an antichain of S(30).
  10348.    {2, 3, 5} is an antichain of S(30).
  10349.  
  10350.    Let N(n) be the maximum length of an antichain of S(n).
  10351.  
  10352.    Find ΣN(n) for 1 ≤ n ≤ 10^8
  10353.  
  10354.    
  10355.    Answer: 528755790
  10356.  
  10357.  
  10358. Problem 387
  10359. ===========
  10360.  
  10361.  
  10362.    A Harshad or Niven number is a number that is divisible by the sum of its
  10363.    digits.
  10364.    201 is a Harshad number because it is divisible by 3 (the sum of its
  10365.    digits.)
  10366.    When we truncate the last digit from 201, we get 20, which is a Harshad
  10367.    number.
  10368.    When we truncate the last digit from 20, we get 2, which is also a Harshad
  10369.    number.
  10370.    Let's call a Harshad number that, while recursively truncating the last
  10371.    digit, always results in a Harshad number a right truncatable Harshad
  10372.    number.
  10373.  
  10374.    Also:
  10375.    201/3=67 which is prime.
  10376.    Let's call a Harshad number that, when divided by the sum of its digits,
  10377.    results in a prime a strong Harshad number.
  10378.  
  10379.    Now take the number 2011 which is prime.
  10380.    When we truncate the last digit from it we get 201, a strong Harshad
  10381.    number that is also right truncatable.
  10382.    Let's call such primes strong, right truncatable Harshad primes.
  10383.  
  10384.    You are given that the sum of the strong, right truncatable Harshad primes
  10385.    less than 10000 is 90619.
  10386.  
  10387.    Find the sum of the strong, right truncatable Harshad primes less than
  10388.    10^14.
  10389.  
  10390.    
  10391.    Answer: a20cbd8639767decfa2c2c9955eb6be3
  10392.  
  10393.  
  10394. Problem 388
  10395. ===========
  10396.  
  10397.  
  10398.    Consider all lattice points (a,b,c) with 0 ≤ a,b,c ≤ N.
  10399.  
  10400.    From the origin O(0,0,0) all lines are drawn to the other lattice points.
  10401.    Let D(N) be the number of distinct such lines.
  10402.  
  10403.    You are given that D(1 000 000) = 831909254469114121.
  10404.  
  10405.    Find D(10^10). Give as your answer the first nine digits followed by the
  10406.    last nine digits.
  10407.  
  10408.    
  10409.    Answer: 2bab886c7d98d802d9249c9e12d72c25
  10410.  
  10411.  
  10412. Problem 389
  10413. ===========
  10414.  
  10415.  
  10416.    An unbiased single 4-sided die is thrown and its value, T, is noted.
  10417.    T unbiased 6-sided dice are thrown and their scores are added together.
  10418.    The sum, C, is noted.
  10419.    C unbiased 8-sided dice are thrown and their scores are added together.
  10420.    The sum, O, is noted.
  10421.    O unbiased 12-sided dice are thrown and their scores are added together.
  10422.    The sum, D, is noted.
  10423.    D unbiased 20-sided dice are thrown and their scores are added together.
  10424.    The sum, I, is noted.
  10425.    Find the variance of I, and give your answer rounded to 4 decimal places.
  10426.  
  10427.    
  10428.    Answer: 79a080d38b837547b975c97b44764dfb
  10429.  
  10430.  
  10431. Problem 390
  10432. ===========
  10433.  
  10434.  
  10435.    Consider the triangle with sides √5, √65 and √68.It can be shown that this
  10436.    triangle has area 9.
  10437.  
  10438.    S(n) is the sum of the areas of all triangles with sides √(1+b^2),
  10439.    √(1+c^2) and √(b^2+c^2) (for positive integers b and c ) that have an
  10440.    integral area not exceeding n.
  10441.  
  10442.    The example triangle has b=2 and c=8.
  10443.  
  10444.    S(10^6)=18018206.
  10445.  
  10446.    Find S(10^10).
  10447.  
  10448.    
  10449.    Answer: ed7f2fbc05a2fd2033d80de671f35ea3
  10450.  
  10451.  
  10452. Problem 391
  10453. ===========
  10454.  
  10455.  
  10456.    Let s[k] be the number of 1’s when writing the numbers from 0 to k in
  10457.    binary.
  10458.    For example, writing 0 to 5 in binary, we have 0, 1, 10, 11, 100, 101.
  10459.    There are seven 1’s, so s[5] = 7.
  10460.    The sequence S = {s[k] : k ≥ 0} starts {0, 1, 2, 4, 5, 7, 9, 12, ...}.
  10461.  
  10462.    A game is played by two players. Before the game starts, a number n is
  10463.    chosen. A counter c starts at 0. At each turn, the player chooses a number
  10464.    from 1 to n (inclusive) and increases c by that number. The resulting
  10465.    value of c must be a member of S. If there are no more valid moves, the
  10466.    player loses.
  10467.  
  10468.    For example:
  10469.    Let n = 5. c starts at 0.
  10470.    Player 1 chooses 4, so c becomes 0 + 4 = 4.
  10471.    Player 2 chooses 5, so c becomes 4 + 5 = 9.
  10472.    Player 1 chooses 3, so c becomes 9 + 3 = 12.
  10473.    etc.
  10474.    Note that c must always belong to S, and each player can increase c by at
  10475.    most n.
  10476.  
  10477.    Let M(n) be the highest number the first player can choose at her first
  10478.    turn to force a win, and M(n) = 0 if there is no such move. For example,
  10479.    M(2) = 2, M(7) = 1 and M(20) = 4.
  10480.  
  10481.    Given Σ(M(n))^3 = 8150 for 1 ≤ n ≤ 20.
  10482.  
  10483.    Find Σ(M(n))^3 for 1 ≤ n ≤ 1000.
  10484.  
  10485.    
  10486.    Answer: b2947548d4f5c4878c5f788f9849e750
  10487.  
  10488.  
  10489. Problem 392
  10490. ===========
  10491.  
  10492.  
  10493.    A rectilinear grid is an orthogonal grid where the spacing between the
  10494.    gridlines does not have to be equidistant.
  10495.    An example of such grid is logarithmic graph paper.
  10496.  
  10497.    Consider rectilinear grids in the Cartesian coordinate system with the
  10498.    following properties:
  10499.  
  10500.      • The gridlines are parallel to the axes of the Cartesian coordinate
  10501.        system.
  10502.      • There are N+2 vertical and N+2 horizontal gridlines. Hence there are
  10503.        (N+1) x (N+1) rectangular cells.
  10504.      • The equations of the two outer vertical gridlines are x = -1 and x =
  10505.        1.
  10506.      • The equations of the two outer horizontal gridlines are y = -1 and y =
  10507.        1.
  10508.      • The grid cells are colored red if they overlap with the unit circle,
  10509.        black otherwise.
  10510.  
  10511.    For this problem we would like you to find the postions of the remaining N
  10512.    inner horizontal and N inner vertical gridlines so that the area occupied
  10513.    by the red cells is minimized.
  10514.  
  10515.    E.g. here is a picture of the solution for N = 10:
  10516.  
  10517.    The area occupied by the red cells for N = 10 rounded to 10 digits behind
  10518.    the decimal point is 3.3469640797.
  10519.  
  10520.    Find the positions for N = 400.
  10521.    Give as your answer the area occupied by the red cells rounded to 10
  10522.    digits behind the decimal point.
  10523.  
  10524.    
  10525.    Answer: 3268b0bc489187db3d234c097040d909
  10526.  
  10527.  
  10528. Problem 393
  10529. ===========
  10530.  
  10531.  
  10532.    An n×n grid of squares contains n^2 ants, one ant per square.
  10533.    All ants decide to move simultaneously to an adjacent square (usually 4
  10534.    possibilities, except for ants on the edge of the grid or at the corners).
  10535.    We define f(n) to be the number of ways this can happen without any ants
  10536.    ending on the same square and without any two ants crossing the same edge
  10537.    between two squares.
  10538.  
  10539.    You are given that f(4) = 88.
  10540.    Find f(10).
  10541.  
  10542.    
  10543.    Answer: 58e4990838fb3d1725872da30f9db748
  10544.  
  10545.  
  10546. Problem 394
  10547. ===========
  10548.  
  10549.  
  10550.    Jeff eats a pie in an unusual way.
  10551.    The pie is circular. He starts with slicing an initial cut in the pie
  10552.    along a radius.
  10553.    While there is at least a given fraction F of pie left, he performs the
  10554.    following procedure:
  10555.    - He makes two slices from the pie centre to any point of what is
  10556.    remaining of the pie border, any point on the remaining pie border equally
  10557.    likely. This will divide the remaining pie into three pieces.
  10558.    - Going counterclockwise from the initial cut, he takes the first two pie
  10559.    pieces and eats them.
  10560.    When less than a fraction F of pie remains, he does not repeat this
  10561.    procedure. Instead, he eats all of the remaining pie.
  10562.  
  10563.    For x ≥ 1, let E(x) be the expected number of times Jeff repeats the
  10564.    procedure above with F = ^1/[x].
  10565.    It can be verified that E(1) = 1, E(2) ≈ 1.2676536759, and E(7.5) ≈
  10566.    2.1215732071.
  10567.  
  10568.    Find E(40) rounded to 10 decimal places behind the decimal point.
  10569.  
  10570.    
  10571.    Answer: f8ad575e1a03365a60b6429c3b7a64df
  10572.  
  10573.  
  10574. Problem 395
  10575. ===========
  10576.  
  10577.  
  10578.    The Pythagorean tree is a fractal generated by the following procedure:
  10579.  
  10580.    Start with a unit square. Then, calling one of the sides its base (in the
  10581.    animation, the bottom side is the base):
  10582.  
  10583.     1. Attach a right triangle to the side opposite the base, with the
  10584.        hypotenuse coinciding with that side and with the sides in a 3-4-5
  10585.        ratio. Note that the smaller side of the triangle must be on the
  10586.        'right' side with respect to the base (see animation).
  10587.     2. Attach a square to each leg of the right triangle, with one of its
  10588.        sides coinciding with that leg.
  10589.     3. Repeat this procedure for both squares, considering as their bases the
  10590.        sides touching the triangle.
  10591.  
  10592.    The resulting figure, after an infinite number of iterations, is the
  10593.    Pythagorean tree.
  10594.  
  10595.    It can be shown that there exists at least one rectangle, whose sides are
  10596.    parallel to the largest square of the Pythagorean tree, which encloses the
  10597.    Pythagorean tree completely.
  10598.  
  10599.    Find the smallest area possible for such a bounding rectangle, and give
  10600.    your answer rounded to 10 decimal places.
  10601.  
  10602.    
  10603.    p_395_pythagorean.gif
  10604.    Answer: 505048b0c619161d05b9b3e492f3edc3
  10605.  
  10606.  
  10607. Problem 396
  10608. ===========
  10609.  
  10610.  
  10611.    For any positive integer n, the nth weak Goodstein sequence {g[1], g[2],
  10612.    g[3], ...} is defined as:
  10613.  
  10614.      • g[1] = n
  10615.      • for k > 1, g[k] is obtained by writing g[k-1] in base k, interpreting
  10616.        it as a base k + 1 number, and subtracting 1.
  10617.  
  10618.    The sequence terminates when g[k] becomes 0.
  10619.  
  10620.    For example, the 6th weak Goodstein sequence is {6, 11, 17, 25, ...}:
  10621.  
  10622.      • g[1] = 6.
  10623.      • g[2] = 11 since 6 = 110[2], 110[3] = 12, and 12 - 1 = 11.
  10624.      • g[3] = 17 since 11 = 102[3], 102[4] = 18, and 18 - 1 = 17.
  10625.      • g[4] = 25 since 17 = 101[4], 101[5] = 26, and 26 - 1 = 25.
  10626.  
  10627.    and so on.
  10628.  
  10629.    It can be shown that every weak Goodstein sequence terminates.
  10630.  
  10631.    Let G(n) be the number of nonzero elements in the nth weak Goodstein
  10632.    sequence.
  10633.    It can be verified that G(2) = 3, G(4) = 21 and G(6) = 381.
  10634.    It can also be verified that ΣG(n) = 2517 for 1 ≤ n < 8.
  10635.  
  10636.    Find the last 9 digits of ΣG(n) for 1 ≤ n < 16.
  10637.  
  10638.    
  10639.    Answer: 173214653
  10640.  
  10641.  
  10642. Problem 397
  10643. ===========
  10644.  
  10645.  
  10646.    On the parabola y = x^2/k, three points A(a, a^2/k), B(b, b^2/k) and C(c,
  10647.    c^2/k) are chosen.
  10648.  
  10649.    Let F(K, X) be the number of the integer quadruplets (k, a, b, c) such
  10650.    that at least one angle of the triangle ABC is 45-degree, with 1 ≤ k ≤ K
  10651.    and -X ≤ a < b < c ≤ X.
  10652.  
  10653.    For example, F(1, 10) = 41 and F(10, 100) = 12492.
  10654.    Find F(10^6, 10^9).
  10655.  
  10656.    
  10657.    Answer: 07f769df9543bc05e6318878c34d074d
  10658.  
  10659.  
  10660. Problem 398
  10661. ===========
  10662.  
  10663.  
  10664.    Inside a rope of length n, n-1 points are placed with distance 1 from each
  10665.    other and from the endpoints. Among these points, we choose m-1 points at
  10666.    random and cut the rope at these points to create m segments.
  10667.  
  10668.    Let E(n, m) be the expected length of the second-shortest segment.For
  10669.    example, E(3, 2) = 2 and E(8, 3) = 16/7.Note that if multiple segments
  10670.    have the same shortest length the length of the second-shortest segment is
  10671.    defined as the same as the shortest length.
  10672.  
  10673.    Find E(10^7, 100).Give your answer rounded to 5 decimal places behind the
  10674.    decimal point.
  10675.  
  10676.    
  10677.    Answer: fa0a25d62fa225e05fd8736713a9bfc0
  10678.  
  10679.  
  10680. Problem 399
  10681. ===========
  10682.  
  10683.  
  10684.    The first 15 fibonacci numbers are:
  10685.    1,1,2,3,5,8,13,21,34,55,89,144,233,377,610.
  10686.    It can be seen that 8 and 144 are not squarefree: 8 is divisible by 4 and
  10687.    144 is divisible by 4 and by 9.
  10688.    So the first 13 squarefree fibonacci numbers are:
  10689.    1,1,2,3,5,13,21,34,55,89,233,377 and 610.
  10690.  
  10691.    The 200th squarefree fibonacci number
  10692.    is:971183874599339129547649988289594072811608739584170445.
  10693.    The last sixteen digits of this number are: 1608739584170445 and in
  10694.    scientific notation this number can be written as 9.7e53.
  10695.  
  10696.    Find the 100 000 000th squarefree fibonacci number.
  10697.    Give as your answer its last sixteen digits followed by a comma followed
  10698.    by the number in scientific notation (rounded to one digit after the
  10699.    decimal point).
  10700.    For the 200th squarefree number the answer would have been:
  10701.    1608739584170445,9.7e53
  10702.  
  10703.    Note:
  10704.    For this problem, assume that for every prime p, the first fibonacci
  10705.    number divisible by p is not divisible by p^2 (this is part of Wall's
  10706.    conjecture). This has been verified for primes ≤ 3·10^15, but has not been
  10707.    proven in general.
  10708.    If it happens that the conjecture is false, then the accepted answer to
  10709.    this problem isn't guaranteed to be the 100 000 000th squarefree fibonacci
  10710.    number, rather it represents only a lower bound for that number.
  10711.  
  10712.    
  10713.    Answer: a0819cfe3be6a04645b8d4fe2345e184
  10714.  
  10715.  
  10716. Problem 400
  10717. ===========
  10718.  
  10719.  
  10720.    A Fibonacci tree is a binary tree recursively defined as:
  10721.  
  10722.      • T(0) is the empty tree.
  10723.      • T(1) is the binary tree with only one node.
  10724.      • T(k) consists of a root node that has T(k-1) and T(k-2) as children.
  10725.  
  10726.    On such a tree two players play a take-away game. On each turn a player
  10727.    selects a node and removes that node along with the subtree rooted at that
  10728.    node.
  10729.    The player who is forced to take the root node of the entire tree loses.
  10730.  
  10731.    Here are the winning moves of the first player on the first turn for T(k)
  10732.    from k=1 to k=6.
  10733.  
  10734.    Let f(k) be the number of winning moves of the first player (i.e. the
  10735.    moves for which the second player has no winning strategy) on the first
  10736.    turn of the game when this game is played on T(k).
  10737.  
  10738.    For example, f(5) = 1 and f(10) = 17.
  10739.  
  10740.    Find f(10000). Give the last 18 digits of your answer.
  10741.  
  10742.    
  10743.    Answer: 60aa790c07af1446c1e2deba72543a1f
  10744.  
  10745.  
  10746. Problem 401
  10747. ===========
  10748.  
  10749.  
  10750.    The divisors of 6 are 1,2,3 and 6.
  10751.    The sum of the squares of these numbers is 1+4+9+36=50.
  10752.  
  10753.    Let sigma2(n) represent the sum of the squares of the divisors of n.Thus
  10754.    sigma2(6)=50.
  10755.  
  10756.    Let SIGMA2 represent the summatory function of sigma2, that is
  10757.    SIGMA2(n)=∑sigma2(i) for i=1 to n.
  10758.    The first 6 values of SIGMA2 are: 1,6,16,37,63 and 113.
  10759.  
  10760.    Find SIGMA2(10^15) modulo 10^9.
  10761.  
  10762.    
  10763.    Answer: 982a249d8b45ef10c98c32dabac00751
  10764.  
  10765.  
  10766. Problem 402
  10767. ===========
  10768.  
  10769.  
  10770.    It can be shown that the polynomial n^4 + 4n^3 + 2n^2 + 5n is a multiple
  10771.    of 6 for every integer n. It can also be shown that 6 is the largest
  10772.    integer satisfying this property.
  10773.  
  10774.    Define M(a, b, c) as the maximum m such that n^4 + an^3 + bn^2 + cn is a
  10775.    multiple of m for all integers n. For example, M(4, 2, 5) = 6.
  10776.  
  10777.    Also, define S(N) as the sum of M(a, b, c) for all 0 < a, b, c ≤ N.
  10778.  
  10779.    We can verify that S(10) = 1972 and S(10000) = 2024258331114.
  10780.  
  10781.    Let F[k] be the Fibonacci sequence:
  10782.    F[0] = 0, F[1] = 1 and
  10783.    F[k] = F[k-1] + F[k-2] for k ≥ 2.
  10784.  
  10785.    Find the last 9 digits of Σ S(F[k]) for 2 ≤ k ≤ 1234567890123.
  10786.  
  10787.    
  10788.    Answer: fa7ae8e9243f01b0eac10ec5aaff1f42
  10789.  
  10790.  
  10791. Problem 403
  10792. ===========
  10793.  
  10794.  
  10795.    For integers a and b, we define D(a, b) as the domain enclosed by the
  10796.    parabola y = x^2 and the line y = a·x + b:
  10797.    D(a, b) = { (x, y) | x^2 ≤ y ≤ a·x + b }.
  10798.  
  10799.    L(a, b) is defined as the number of lattice points contained in D(a, b).
  10800.    For example, L(1, 2) = 8 and L(2, -1) = 1.
  10801.  
  10802.    We also define S(N) as the sum of L(a, b) for all the pairs (a, b) such
  10803.    that the area of D(a, b) is a rational number and |a|,|b| ≤ N.
  10804.    We can verify that S(5) = 344 and S(100) = 26709528.
  10805.  
  10806.    Find S(10^12). Give your answer mod 10^8.
  10807.  
  10808.    
  10809.    Answer: 18224771
  10810.  
  10811.  
  10812. Problem 404
  10813. ===========
  10814.  
  10815.  
  10816.    E[a] is an ellipse with an equation of the form x^2 + 4y^2 = 4a^2.
  10817.    E[a]' is the rotated image of E[a] by θ degrees counterclockwise around
  10818.    the origin O(0, 0) for 0° < θ < 90°.
  10819.  
  10820.    b is the distance to the origin of the two intersection points closest to
  10821.    the origin and c is the distance of the two other intersection points.
  10822.    We call an ordered triplet (a, b, c) a canonical ellipsoidal triplet if a,
  10823.    b and c are positive integers.
  10824.    For example, (209, 247, 286) is a canonical ellipsoidal triplet.
  10825.  
  10826.    Let C(N) be the number of distinct canonical ellipsoidal triplets (a, b,
  10827.    c) for a ≤ N.
  10828.    It can be verified that C(10^3) = 7, C(10^4) = 106 and C(10^6) = 11845.
  10829.  
  10830.    Find C(10^17).
  10831.  
  10832.    
  10833.    p_404_c_ellipse.gif
  10834.    Answer: 2d1bc4b93bbc19d9e70c5b04338dea2e
  10835.  
  10836.  
  10837. Problem 405
  10838. ===========
  10839.  
  10840.  
  10841.    We wish to tile a rectangle whose length is twice its width.
  10842.    Let T(0) be the tiling consisting of a single rectangle.
  10843.    For n > 0, let T(n) be obtained from T(n-1) by replacing all tiles in the
  10844.    following manner:
  10845.  
  10846.    The following animation demonstrates the tilings T(n) for n from 0 to 5:
  10847.  
  10848.    Let f(n) be the number of points where four tiles meet in T(n).
  10849.    For example, f(1) = 0, f(4) = 82 and f(10^9) mod 17^7 = 126897180.
  10850.  
  10851.    Find f(10^k) for k = 10^18, give your answer modulo 17^7.
  10852.  
  10853.    
  10854.    p_405_tile1.png
  10855.    p_405_tile2.gif
  10856.    Answer: 93b712426b768586f88d0bfe597842e6
  10857.  
  10858.  
  10859. Problem 406
  10860. ===========
  10861.  
  10862.  
  10863.    We are trying to find a hidden number selected from the set of integers
  10864.    {1, 2, ..., n} by asking questions. Each number (question) we ask, we get
  10865.    one of three possible answers:
  10866.  
  10867.      • "Your guess is lower than the hidden number" (and you incur a cost of
  10868.        a), or
  10869.      • "Your guess is higher than the hidden number" (and you incur a cost of
  10870.        b), or
  10871.      • "Yes, that's it!" (and the game ends).
  10872.  
  10873.    Given the value of n, a, and b, an optimal strategy minimizes the total
  10874.    cost for the worst possible case.
  10875.  
  10876.    For example, if n = 5, a = 2, and b = 3, then we may begin by asking "2"
  10877.    as our first question.
  10878.  
  10879.    If we are told that 2 is higher than the hidden number (for a cost of
  10880.    b=3), then we are sure that "1" is the hidden number (for a total cost of
  10881.    3).
  10882.    If we are told that 2 is lower than the hidden number (for a cost of a=2),
  10883.    then our next question will be "4".
  10884.    If we are told that 4 is higher than the hidden number (for a cost of
  10885.    b=3), then we are sure that "3" is the hidden number (for a total cost of
  10886.    2+3=5).
  10887.    If we are told that 4 is lower than the hidden number (for a cost of a=2),
  10888.    then we are sure that "5" is the hidden number (for a total cost of
  10889.    2+2=4).
  10890.    Thus, the worst-case cost achieved by this strategy is 5. It can also be
  10891.    shown that this is the lowest worst-case cost that can be achieved. So, in
  10892.    fact, we have just described an optimal strategy for the given values of
  10893.    n, a, and b.
  10894.  
  10895.    Let C(n, a, b) be the worst-case cost achieved by an optimal strategy for
  10896.    the given values of n, a, and b.
  10897.  
  10898.    Here are a few examples:
  10899.    C(5, 2, 3) = 5
  10900.    C(500, √2, √3) = 13.22073197...
  10901.    C(20000, 5, 7) = 82
  10902.    C(2000000, √5, √7) = 49.63755955...
  10903.  
  10904.    Let F[k] be the Fibonacci numbers: F[k] = F[k-1] + F[k-2] with base cases
  10905.    F[1] = F[2] = 1.
  10906.    Find ∑[1≤k≤30] C(10^12, √k, √F[k]), and give your answer rounded to 8
  10907.    decimal places behind the decimal point.
  10908.  
  10909.    
  10910.    Answer: 0766b1ee975f5674d30fd6c3c934c6e0
  10911.  
  10912.  
  10913. Problem 407
  10914. ===========
  10915.  
  10916.  
  10917.    If we calculate a^2 mod 6 for 0 ≤ a ≤ 5 we get: 0,1,4,3,4,1.
  10918.  
  10919.    The largest value of a such that a^2 ≡ a mod 6 is 4.
  10920.    Let's call M(n) the largest value of a < n such that a^2 ≡ a (mod n).
  10921.    So M(6) = 4.
  10922.  
  10923.    Find ∑M(n) for 1 ≤ n ≤ 10^7.
  10924.  
  10925.    
  10926.    Answer: f4da34a4b357123cb142739a52e010f2
  10927.  
  10928.  
  10929. Problem 408
  10930. ===========
  10931.  
  10932.  
  10933.    Let's call a lattice point (x, y) inadmissible if x, y and x + y are all
  10934.    positive perfect squares.
  10935.    For example, (9, 16) is inadmissible, while (0, 4), (3, 1) and (9, 4) are
  10936.    not.
  10937.  
  10938.    Consider a path from point (x[1], y[1]) to point (x[2], y[2]) using only
  10939.    unit steps north or east.
  10940.    Let's call such a path admissible if none of its intermediate points are
  10941.    inadmissible.
  10942.  
  10943.    Let P(n) be the number of admissible paths from (0, 0) to (n, n).
  10944.    It can be verified that P(5) = 252, P(16) = 596994440 and P(1000) mod
  10945.    1 000 000 007 = 341920854.
  10946.  
  10947.    Find P(10 000 000) mod 1 000 000 007.
  10948.  
  10949.    
  10950.    Answer: 2c09e247c6144c16cae2358d316affd9
  10951.  
  10952.  
  10953. Problem 409
  10954. ===========
  10955.  
  10956.  
  10957.    Let n be a positive integer. Consider nim positions where:
  10958.  
  10959.      • There are n non-empty piles.
  10960.      • Each pile has size less than 2^n.
  10961.      • No two piles have the same size.
  10962.  
  10963.    Let W(n) be the number of winning nim positions satisfying the
  10964.    aboveconditions (a position is winning if the first player has a winning
  10965.    strategy). For example, W(1) = 1, W(2) = 6, W(3) = 168, W(5) = 19764360
  10966.    and W(100) mod 1 000 000 007 = 384777056.
  10967.  
  10968.    Find W(10 000 000) mod 1 000 000 007.
  10969.  
  10970.    
  10971.    Answer: 56c32e75a2656ec08ce177089bda2f53
  10972.  
  10973.  
  10974. Problem 410
  10975. ===========
  10976.  
  10977.  
  10978.    Let C be the circle with radius r, x^2 + y^2 = r^2. We choose two points
  10979.    P(a, b) and Q(-a, c) so that the line passing through P and Q is tangent
  10980.    to C.
  10981.  
  10982.    For example, the quadruplet (r, a, b, c) = (2, 6, 2, -7) satisfies this
  10983.    property.
  10984.  
  10985.    Let F(R, X) be the number of the integer quadruplets (r, a, b, c) with
  10986.    this property, and with 0 < r ≤ R and 0 < a ≤ X.
  10987.  
  10988.    We can verify that F(1, 5) = 10, F(2, 10) = 52 and F(10, 100) = 3384.
  10989.    Find F(10^8, 10^9) + F(10^9, 10^8).
  10990.  
  10991.    
  10992.    Answer: 45826f3a23aa321f97acb1d2a8f2170b
  10993.  
  10994.  
  10995. Problem 411
  10996. ===========
  10997.  
  10998.  
  10999.    Let n be a positive integer. Suppose there are stations at the coordinates
  11000.    (x, y) = (2^i mod n, 3^i mod n) for 0 ≤ i ≤ 2n. We will consider stations
  11001.    with the same coordinates as the same station.
  11002.  
  11003.    We wish to form a path from (0, 0) to (n, n) such that the x and y
  11004.    coordinates never decrease.
  11005.    Let S(n) be the maximum number of stations such a path can pass through.
  11006.  
  11007.    For example, if n = 22, there are 11 distinct stations, and a valid path
  11008.    can pass through at most 5 stations. Therefore, S(22) = 5.The case is
  11009.    illustrated below, with an example of an optimal path:
  11010.  
  11011.    It can also be verified that S(123) = 14 and S(10000) = 48.
  11012.  
  11013.    Find ∑ S(k^5) for 1 ≤ k ≤ 30.
  11014.  
  11015.    
  11016.    Answer: 9936352
  11017.  
  11018.  
  11019. Problem 412
  11020. ===========
  11021.  
  11022.  
  11023.    For integers m, n (0 ≤ n < m), let L(m, n) be an m×m grid with the
  11024.    top-right n×n grid removed.
  11025.  
  11026.    For example, L(5, 3) looks like this:
  11027.  
  11028.    We want to number each cell of L(m, n) with consecutive integers 1, 2, 3,
  11029.    ... such that the number in every cell is smaller than the number below it
  11030.    and to the left of it.
  11031.  
  11032.    For example, here are two valid numberings of L(5, 3):
  11033.  
  11034.    Let LC(m, n) be the number of valid numberings of L(m, n).
  11035.    It can be verified that LC(3, 0) = 42, LC(5, 3) = 250250, LC(6, 3) =
  11036.    406029023400 and LC(10, 5) mod 76543217 = 61251715.
  11037.  
  11038.    Find LC(10000, 5000) mod 76543217.
  11039.  
  11040.    
  11041.    Answer: 38788800
  11042.  
  11043.  
  11044. Problem 413
  11045. ===========
  11046.  
  11047.  
  11048.    We say that a d-digit positive number (no leading zeros) is a one-child
  11049.    number if exactly one of its sub-strings is divisible by d.
  11050.  
  11051.    For example, 5671 is a 4-digit one-child number. Among all its sub-strings
  11052.    5, 6, 7, 1, 56, 67, 71, 567, 671 and 5671, only 56 is divisible by 4.
  11053.    Similarly, 104 is a 3-digit one-child number because only 0 is divisible
  11054.    by 3.
  11055.    1132451 is a 7-digit one-child number because only 245 is divisible by 7.
  11056.  
  11057.    Let F(N) be the number of the one-child numbers less than N.
  11058.    We can verify that F(10) = 9, F(10^3) = 389 and F(10^7) = 277674.
  11059.  
  11060.    Find F(10^19).
  11061.  
  11062.    
  11063.    Answer: 569ad33af889215704df5a9e278aa004
  11064.  
  11065.  
  11066. Problem 414
  11067. ===========
  11068.  
  11069.  
  11070.    6174 is a remarkable number; if we sort its digits in increasing order and
  11071.    subtract that number from the number you get when you sort the digits in
  11072.    decreasing order, we get 7641-1467=6174.
  11073.    Even more remarkable is that if we start from any 4 digit number and
  11074.    repeat this process of sorting and subtracting, we'll eventually end up
  11075.    with 6174 or immediately with 0 if all digits are equal.
  11076.    This also works with numbers that have less than 4 digits if we pad the
  11077.    number with leading zeroes until we have 4 digits.
  11078.    E.g. let's start with the number 0837:
  11079.    8730-0378=8352
  11080.    8532-2358=6174
  11081.  
  11082.    6174 is called the Kaprekar constant. The process of sorting and
  11083.    subtracting and repeating this until either 0 or the Kaprekar constant is
  11084.    reached is called the Kaprekar routine.
  11085.  
  11086.    We can consider the Kaprekar routine for other bases and number of digits.
  11087.    Unfortunately, it is not guaranteed a Kaprekar constant exists in all
  11088.    cases; either the routine can end up in a cycle for some input numbers or
  11089.    the constant the routine arrives at can be different for different input
  11090.    numbers.
  11091.    However, it can be shown that for 5 digits and a base b = 6t+3≠9, a
  11092.    Kaprekar constant exists.
  11093.    E.g. base 15: (10,4,14,9,5)[15]
  11094.    base 21: (14,6,20,13,7)[21]
  11095.  
  11096.    Define C[b] to be the Kaprekar constant in base b for 5 digits.Define the
  11097.    function sb(i) to be
  11098.  
  11099.      • 0 if i = C[b] or if i written in base b consists of 5 identical digits
  11100.      • the number of iterations it takes the Kaprekar routine in base b to
  11101.        arrive at C[b], otherwise
  11102.  
  11103.    Note that we can define sb(i) for all integers i < b^5. If i written in
  11104.    base b takes less than 5 digits, the number is padded with leading zero
  11105.    digits until we have 5 digits before applying the Kaprekar routine.
  11106.  
  11107.    Define S(b) as the sum of sb(i) for 0 < i < b^5.
  11108.    E.g. S(15) = 5274369
  11109.    S(111) = 400668930299
  11110.  
  11111.    Find the sum of S(6k+3) for 2 ≤ k ≤ 300.
  11112.    Give the last 18 digits as your answer.
  11113.  
  11114.    
  11115.    Answer: 42f095bdfd71e1ae4ae0ceead1bb1802
  11116.  
  11117.  
  11118. Problem 415
  11119. ===========
  11120.  
  11121.  
  11122.    A set of lattice points S is called a titanic set if there exists a line
  11123.    passing through exactly two points in S.
  11124.  
  11125.    An example of a titanic set is S = {(0, 0), (0, 1), (0, 2), (1, 1), (2,
  11126.    0), (1, 0)}, where the line passing through (0, 1) and (2, 0) does not
  11127.    pass through any other point in S.
  11128.  
  11129.    On the other hand, the set {(0, 0), (1, 1), (2, 2), (4, 4)} is not a
  11130.    titanic set since the line passing through any two points in the set also
  11131.    passes through the other two.
  11132.  
  11133.    For any positive integer N, let T(N) be the number of titanic sets S whose
  11134.    every point (x, y) satisfies 0 ≤ x, y ≤ N.It can be verified that T(1) =
  11135.    11, T(2) = 494, T(4) = 33554178, T(111) mod 10^8 = 13500401 and
  11136.    T(10^5) mod 10^8 = 63259062.
  11137.  
  11138.    Find T(10^11) mod 10^8.
  11139.  
  11140.    
  11141.    Answer: 55859742
  11142.  
  11143.  
  11144. Problem 416
  11145. ===========
  11146.  
  11147.  
  11148.    A row of n squares contains a frog in the leftmost square. By successive
  11149.    jumps the frog goes to the rightmost square and then back to the leftmost
  11150.    square. On the outward trip he jumps one, two or three squares to the
  11151.    right, and on the homeward trip he jumps to the left in a similar manner.
  11152.    He cannot jump outside the squares. He repeats the round-trip travel m
  11153.    times.
  11154.  
  11155.    Let F(m, n) be the number of the ways the frog can travel so that at most
  11156.    one square remains unvisited.
  11157.    For example, F(1, 3) = 4, F(1, 4) = 15, F(1, 5) = 46, F(2, 3) = 16 and
  11158.    F(2, 100) mod 10^9 = 429619151.
  11159.  
  11160.    Find the last 9 digits of F(10, 10^12).
  11161.  
  11162.    
  11163.    Answer: 6f398386fdfec57ac166d4970c2bcad2
  11164.  
  11165.  
  11166. Problem 417
  11167. ===========
  11168.  
  11169.  
  11170.    A unit fraction contains 1 in the numerator. The decimal representation of
  11171.    the unit fractions with denominators 2 to 10 are given:
  11172.  
  11173.      1/2  =  0.5
  11174.      1/3  =  0.(3)
  11175.      1/4  =  0.25
  11176.      1/5  =  0.2
  11177.      1/6  =  0.1(6)
  11178.      1/7  =  0.(142857)
  11179.      1/8  =  0.125
  11180.      1/9  =  0.(1)
  11181.      1/10 =  0.1
  11182.  
  11183.    Where 0.1(6) means 0.166666..., and has a 1-digit recurring cycle. It can
  11184.    be seen that 1/7 has a 6-digit recurring cycle.
  11185.  
  11186.    Unit fractions whose denominator has no other prime factors than 2 and/or
  11187.    5 are not considered to have a recurring cycle.
  11188.    We define the length of the recurring cycle of those unit fractions as 0.
  11189.  
  11190.    Let L(n) denote the length of the recurring cycle of 1/n.You are given
  11191.    that ∑L(n) for 3 ≤ n ≤ 1 000 000 equals 55535191115.
  11192.  
  11193.    Find ∑L(n) for 3 ≤ n ≤ 100 000 000
  11194.  
  11195.    
  11196.    Answer: 93a7df08c972f1e7788516d056a7e016
  11197.  
  11198.  
  11199. Problem 418
  11200. ===========
  11201.  
  11202.  
  11203.    Let n be a positive integer. An integer triple (a, b, c) is called a
  11204.    factorisation triple of n if:
  11205.  
  11206.      • 1 ≤ a ≤ b ≤ c
  11207.      • a·b·c = n.
  11208.  
  11209.    Define f(n) to be a + b + c for the factorisation triple (a, b, c) of n
  11210.    which minimises c / a. One can show that this triple is unique.
  11211.  
  11212.    For example, f(165) = 19, f(100100) = 142 and f(20!) = 4034872.
  11213.  
  11214.    Find f(43!).
  11215.  
  11216.    
  11217.    Answer: b032468ddb4847d8a2273789379753f5
  11218.  
  11219.  
  11220. Problem 419
  11221. ===========
  11222.  
  11223.  
  11224.    The look and say sequence goes 1, 11, 21, 1211, 111221, 312211, 13112221,
  11225.    1113213211, ...
  11226.    The sequence starts with 1 and all other members are obtained by
  11227.    describing the previous member in terms of consecutive digits.
  11228.    It helps to do this out loud:
  11229.    1 is 'one one' → 11
  11230.    11 is 'two ones' → 21
  11231.    21 is 'one two and one one' → 1211
  11232.    1211 is 'one one, one two and two ones' → 111221
  11233.    111221 is 'three ones, two twos and one one' → 312211
  11234.    ...
  11235.  
  11236.    Define A(n), B(n) and C(n) as the number of ones, twos and threes in the
  11237.    n'th element of the sequence respectively.
  11238.    One can verify that A(40) = 31254, B(40) = 20259 and C(40) = 11625.
  11239.  
  11240.    Find A(n), B(n) and C(n) for n = 10^12.
  11241.    Give your answer modulo 2^30 and separate your values for A, B and C by a
  11242.    comma.
  11243.    E.g. for n = 40 the answer would be 31254,20259,11625
  11244.  
  11245.    
  11246.    Answer: b27db655498b3d64ad4338fcdc9d178f
  11247.  
  11248.  
  11249. Problem 420
  11250. ===========
  11251.  
  11252.  
  11253.    A positive integer matrix is a matrix whose elements are all positive
  11254.    integers.
  11255.    Some positive integer matrices can be expressed as a square of a positive
  11256.    integer matrix in two different ways. Here is an example:
  11257.  
  11258.    We define F(N) as the number of the 2x2 positive integer matrices which
  11259.    have a trace less than N and which can be expressed as a square of a
  11260.    positive integer matrix in two different ways.
  11261.    We can verify that F(50) = 7 and F(1000) = 1019.
  11262.  
  11263.    Find F(10^7).
  11264.  
  11265.    
  11266.    p_420_matrix.gif
  11267.    Answer: 145159332
  11268.  
  11269.  
  11270. Problem 421
  11271. ===========
  11272.  
  11273.  
  11274.    Numbers of the form n^15+1 are composite for every integer n > 1.
  11275.    For positive integers n and m let s(n,m) be defined as the sum of the
  11276.    distinct prime factors of n^15+1 not exceeding m.
  11277.  
  11278.    E.g. 2^15+1 = 3×3×11×331.
  11279.    So s(2,10) = 3 and s(2,1000) = 3+11+331 = 345.
  11280.  
  11281.    Also 10^15+1 = 7×11×13×211×241×2161×9091.
  11282.    So s(10,100) = 31 and s(10,1000) = 483.
  11283.  
  11284.    Find &Sum; s(n,10^8) for 1 ≤ n ≤ 10^11.
  11285.  
  11286.    
  11287.    Answer: 481fcc5ff16ccf1645fb136c123ed660
  11288.  
  11289.  
  11290. Problem 422
  11291. ===========
  11292.  
  11293.  
  11294.    Let H be the hyperbola defined by the equation 12x^2 + 7xy - 12y^2 = 625.
  11295.  
  11296.    Next, define X as the point (7, 1). It can be seen that X is in H.
  11297.  
  11298.    Now we define a sequence of points in H, {P[i] : i ≥ 1}, as:
  11299.  
  11300.      • P[1] = (13, 61/4).
  11301.      • P[2] = (-43/6, -4).
  11302.      • For i > 2, P[i] is the unique point in H that is different from P[i-1]
  11303.        and such that line P[i]P[i-1] is parallel to line P[i-2]X. It can be
  11304.        shown that P[i] is well-defined, and that its coordinates are always
  11305.        rational.
  11306.  
  11307.    You are given that P[3] = (-19/2, -229/24), P[4] = (1267/144, -37/12) and
  11308.    P[7] = (17194218091/143327232, 274748766781/1719926784).
  11309.  
  11310.    Find P[n] for n = 11^14 in the following format:
  11311.    If P[n] = (a/b, c/d) where the fractions are in lowest terms and the
  11312.    denominators are positive, then the answer is (a + b + c + d) mod
  11313.    1 000 000 007.
  11314.  
  11315.    For n = 7, the answer would have been: 806236837.
  11316.  
  11317.    
  11318.    Answer: 92060460
  11319.  
  11320.  
  11321. Problem 423
  11322. ===========
  11323.  
  11324.  
  11325.    Let n be a positive integer.
  11326.    A 6-sided die is thrown n times. Let c be the number of pairs of
  11327.    consecutive throws that give the same value.
  11328.  
  11329.    For example, if n = 7 and the values of the die throws are
  11330.    (1,1,5,6,6,6,3), then the following pairs of consecutive throws give the
  11331.    same value:
  11332.    (1,1,5,6,6,6,3)
  11333.    (1,1,5,6,6,6,3)
  11334.    (1,1,5,6,6,6,3)
  11335.    Therefore, c = 3 for (1,1,5,6,6,6,3).
  11336.  
  11337.    Define C(n) as the number of outcomes of throwing a 6-sided die n times
  11338.    such that c does not exceed π(n).^1
  11339.    For example, C(3) = 216, C(4) = 1290, C(11) = 361912500 and C(24) =
  11340.    4727547363281250000.
  11341.  
  11342.    Define S(L) as ∑ C(n) for 1 ≤ n ≤ L.
  11343.    For example, S(50) mod 1 000 000 007 = 832833871.
  11344.  
  11345.    Find S(50 000 000) mod 1 000 000 007.
  11346.  
  11347.    ^1 π denotes the prime-counting function, i.e. π(n) is the number of
  11348.    primes ≤ n.
  11349.  
  11350.    
  11351.    Answer: e2add9d46ebd8ba59a07dca791cd629b
  11352.  
  11353.  
  11354. Problem 424
  11355. ===========
  11356.  
  11357.  
  11358.    The above is an example of a cryptic kakuro (also known as cross sums, or
  11359.    even sums cross) puzzle, with its final solution on the right. (The common
  11360.    rules of kakuro puzzles can be found easily on numerous internet sites.
  11361.    Other related information can also be currently found at [1]krazydad.com
  11362.    whose author has provided the puzzle data for this challenge.)
  11363.  
  11364.    The downloadable text file ([2]kakuro200.txt) contains the description of
  11365.    200 such puzzles, a mix of 5x5 and 6x6 types. The first puzzle in the file
  11366.    is the above example which is coded as follows:
  11367.  
  11368.    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
  11369.  
  11370.    The first character is a numerical digit indicating the size of the
  11371.    information grid. It would be either a 6 (for a 5x5 kakuro puzzle) or a 7
  11372.    (for a 6x6 puzzle) followed by a comma (,). The extra top line and left
  11373.    column are needed to insert information.
  11374.  
  11375.    The content of each cell is then described and followed by a comma, going
  11376.    left to right and starting with the top line.
  11377.    X = Gray cell, not required to be filled by a digit.
  11378.    O (upper case letter)= White empty cell to be filled by a digit.
  11379.    A = Or any one of the upper case letters from A to J to be replaced by its
  11380.    equivalent digit in the solved puzzle.
  11381.    ( ) = Location of the encrypted sums. Horizontal sums are preceded by a
  11382.    lower case "h" and vertical sums are preceded by a lower case "v". Those
  11383.    are followed by one or two upper case letters depending if the sum is a
  11384.    single digit or double digit one. For double digit sums, the first letter
  11385.    would be for the "tens" and the second one for the "units". When the cell
  11386.    must contain information for both a horizontal and a vertical sum, the
  11387.    first one is always for the horizontal sum and the two are separated by a
  11388.    comma within the same set of brackets, ex.: (hFE,vD). Each set of brackets
  11389.    is also immediately followed by a comma.
  11390.  
  11391.    The description of the last cell is followed by a Carriage Return/Line
  11392.    Feed (CRLF) instead of a comma.
  11393.  
  11394.    The required answer to each puzzle is based on the value of each letter
  11395.    necessary to arrive at the solution and according to the alphabetical
  11396.    order. As indicated under the example puzzle, its answer would be
  11397.    8426039571. At least 9 out of the 10 encrypting letters are always part of
  11398.    the problem description. When only 9 are given, the missing one must be
  11399.    assigned the remaining digit.
  11400.  
  11401.    You are given that the sum of the answers for the first 10 puzzles in the
  11402.    file is 64414157580.
  11403.  
  11404.    Find the sum of the answers for the 200 puzzles.
  11405.  
  11406.  
  11407.    Visible links
  11408.    1. http://krazydad.com/
  11409.    2. kakuro200.txt
  11410.    Answer: 1059760019628
  11411.  
  11412.  
  11413. Problem 425
  11414. ===========
  11415.  
  11416.  
  11417.    Two positive numbers A and B are said to be connected (denoted by "A ↔ B")
  11418.    if one of these conditions holds:
  11419.    (1) A and B have the same length and differ in exactly one digit; for
  11420.    example, 123 ↔ 173.
  11421.    (2) Adding one digit to the left of A (or B) makes B (or A); for example,
  11422.    23 ↔ 223 and 123 ↔ 23.
  11423.  
  11424.    We call a prime P a 2's relative if there exists a chain of connected
  11425.    primes between 2 and P and no prime in the chain exceeds P.
  11426.  
  11427.    For example, 127 is a 2's relative. One of the possible chains is shown
  11428.    below:
  11429.    2 ↔ 3 ↔ 13 ↔ 113 ↔ 103 ↔ 107 ↔ 127
  11430.    However, 11 and 103 are not 2's relatives.
  11431.  
  11432.    Let F(N) be the sum of the primes ≤ N which are not 2's relatives.
  11433.    We can verify that F(10^3) = 431 and F(10^4) = 78728.
  11434.  
  11435.    Find F(10^7).
  11436.  
  11437.    
  11438.    Answer: 3d229894ba4c585138125e802af2d06e
  11439.  
  11440.  
  11441. Problem 426
  11442. ===========
  11443.  
  11444.  
  11445.    Consider an infinite row of boxes. Some of the boxes contain a ball. For
  11446.    example, an initial configuration of 2 consecutive occupied boxes followed
  11447.    by 2 empty boxes, 2 occupied boxes, 1 empty box, and 2 occupied boxes can
  11448.    be denoted by the sequence (2, 2, 2, 1, 2), in which the number of
  11449.    consecutive occupied and empty boxes appear alternately.
  11450.  
  11451.    A turn consists of moving each ball exactly once according to the
  11452.    following rule: Transfer the leftmost ball which has not been moved to the
  11453.    nearest empty box to its right.
  11454.  
  11455.    After one turn the sequence (2, 2, 2, 1, 2) becomes (2, 2, 1, 2, 3) as can
  11456.    be seen below; note that we begin the new sequence starting at the first
  11457.    occupied box.
  11458.  
  11459.    A system like this is called a Box-Ball System or BBS for short.
  11460.  
  11461.    It can be shown that after a sufficient number of turns, the system
  11462.    evolves to a state where the consecutive numbers of occupied boxes is
  11463.    invariant. In the example below, the consecutive numbers of occupied boxes
  11464.    evolves to [1, 2, 3]; we shall call this the final state.
  11465.  
  11466.    We define the sequence {t[i]}:
  11467.  
  11468.      • s[0] = 290797
  11469.      • s[k+1] = s[k]^2 mod 50515093
  11470.      • t[k] = (s[k] mod 64) + 1
  11471.  
  11472.    Starting from the initial configuration (t[0], t[1], …, t[10]), the final
  11473.    state becomes [1, 3, 10, 24, 51, 75].
  11474.    Starting from the initial configuration (t[0], t[1], …, t[10 000 000]),
  11475.    find the final state.
  11476.    Give as your answer the sum of the squares of the elements of the final
  11477.    state. For example, if the final state is [1, 2, 3] then 14 ( = 1^2 + 2^2
  11478.    + 3^2) is your answer.
  11479.  
  11480.    
  11481.    p_426_baxball1.gif
  11482.    p_426_baxball2.gif
  11483.    Answer: b5d8157a351482da47da0512ca374007
  11484.  
  11485.  
  11486. Problem 427
  11487. ===========
  11488.  
  11489.  
  11490.    A sequence of integers S = {s[i]} is called an n-sequence if it has n
  11491.    elements and each element s[i] satisfies 1 ≤ s[i] ≤ n. Thus there are n^n
  11492.    distinct n-sequences in total.For example, the sequence S = {1, 5, 5, 10,
  11493.    7, 7, 7, 2, 3, 7} is a 10-sequence.
  11494.  
  11495.    For any sequence S, let L(S) be the length of the longest contiguous
  11496.    subsequence of S with the same value.For example, for the given sequence S
  11497.    above, L(S) = 3, because of the three consecutive 7's.
  11498.  
  11499.    Let f(n) = ∑ L(S) for all n-sequences S.
  11500.  
  11501.    For example, f(3) = 45, f(7) = 1403689 and f(11) = 481496895121.
  11502.  
  11503.    Find f(7 500 000) mod 1 000 000 009.
  11504.  
  11505.    
  11506.    Answer: 97138867
  11507.  
  11508.  
  11509. Problem 428
  11510. ===========
  11511.  
  11512.  
  11513.    Let a, b and c be positive numbers.
  11514.    Let W, X, Y, Z be four collinear points where |WX| = a, |XY| = b, |YZ| = c
  11515.    and |WZ| = a + b + c.
  11516.    Let C[in] be the circle having the diameter XY.
  11517.    Let C[out] be the circle having the diameter WZ.
  11518.  
  11519.    The triplet (a, b, c) is called a necklace triplet if you can place k ≥ 3
  11520.    distinct circles C[1], C[2], ..., C[k] such that:
  11521.  
  11522.      • C[i] has no common interior points with any C[j] for 1 ≤ i, j ≤ k and
  11523.        i ≠ j,
  11524.      • C[i] is tangent to both C[in] and C[out] for 1 ≤ i ≤ k,
  11525.      • C[i] is tangent to C[i+1] for 1 ≤ i < k, and
  11526.      • C[k] is tangent to C[1].
  11527.  
  11528.    For example, (5, 5, 5) and (4, 3, 21) are necklace triplets, while it can
  11529.    be shown that (2, 2, 5) is not.
  11530.  
  11531.    Let T(n) be the number of necklace triplets (a, b, c) such that a, b and c
  11532.    are positive integers, and b ≤ n.For example, T(1) = 9, T(20) = 732 and
  11533.    T(3000) = 438106.
  11534.  
  11535.    Find T(1 000 000 000).
  11536.  
  11537.    
  11538.    Answer: c6010c109b66b34bf3594e63eb58b446
  11539.  
  11540.  
  11541. Problem 429
  11542. ===========
  11543.  
  11544.  
  11545.    A unitary divisor d of a number n is a divisor of n that has the property
  11546.    gcd(d, n/d) = 1.
  11547.    The unitary divisors of 4! = 24 are 1, 3, 8 and 24.
  11548.    The sum of their squares is 1^2 + 3^2 + 8^2 + 24^2 = 650.
  11549.  
  11550.    Let S(n) represent the sum of the squares of the unitary divisors of n.
  11551.    Thus S(4!)=650.
  11552.  
  11553.    Find S(100 000 000!) modulo 1 000 000 009.
  11554.  
  11555.    
  11556.    Answer: 98792821
  11557.  
  11558.  
  11559. Problem 430
  11560. ===========
  11561.  
  11562.  
  11563.    N disks are placed in a row, indexed 1 to N from left to right.
  11564.    Each disk has a black side and white side. Initially all disks show their
  11565.    white side.
  11566.  
  11567.    At each turn, two, not necessarily distinct, integers A and B between 1
  11568.    and N (inclusive) are chosen uniformly at random.
  11569.    All disks with an index from A to B (inclusive) are flipped.
  11570.  
  11571.    The following example shows the case N = 8. At the first turn A = 5 and B
  11572.    = 2, and at the second turn A = 4 and B = 6.
  11573.  
  11574.    Let E(N, M) be the expected number of disks that show their white side
  11575.    after M turns.
  11576.    We can verify that E(3, 1) = 10/9, E(3, 2) = 5/3, E(10, 4) ≈ 5.157 and
  11577.    E(100, 10) ≈ 51.893.
  11578.  
  11579.    Find E(10^10, 4000).
  11580.    Give your answer rounded to 2 decimal places behind the decimal point.
  11581.  
  11582.    
  11583.    p_430_flips.gif
  11584.    Answer: 32b0825d7a110a1a220e80629c413411
  11585.  
  11586.  
  11587. Problem 431
  11588. ===========
  11589.  
  11590.  
  11591.    Fred the farmer arranges to have a new storage silo installed on his farm
  11592.    and having an obsession for all things square he is absolutely devastated
  11593.    when he discovers that it is circular. Quentin, the representative from
  11594.    the company that installed the silo, explains that they only manufacture
  11595.    cylindrical silos, but he points out that it is resting on a square base.
  11596.    Fred is not amused and insists that it is removed from his property.
  11597.  
  11598.    Quick thinking Quentin explains that when granular materials are delivered
  11599.    from above a conical slope is formed and the natural angle made with the
  11600.    horizontal is called the angle of repose. For example if the angle of
  11601.    repose, $\alpha = 30$ degrees, and grain is delivered at the centre of the
  11602.    silo then a perfect cone will form towards the top of the cylinder. In the
  11603.    case of this silo, which has a diameter of 6m, the amount of space wasted
  11604.    would be approximately 32.648388556 m^3. However, if grain is delivered at
  11605.    a point on the top which has a horizontal distance of $x$ metres from the
  11606.    centre then a cone with a strangely curved and sloping base is formed. He
  11607.    shows Fred a picture.
  11608.  
  11609.    We shall let the amount of space wasted in cubic metres be given by
  11610.    $V(x)$. If $x = 1.114785284$, which happens to have three squared decimal
  11611.    places, then the amount of space wasted, $V(1.114785284) \approx 36$.
  11612.    Given the range of possible solutions to this problem there is exactly one
  11613.    other option: $V(2.511167869) \approx 49$. It would be like knowing that
  11614.    the square is king of the silo, sitting in splendid glory on top of your
  11615.    grain.
  11616.  
  11617.    Fred's eyes light up with delight at this elegant resolution, but on
  11618.    closer inspection of Quentin's drawings and calculations his happiness
  11619.    turns to despondency once more. Fred points out to Quentin that it's the
  11620.    radius of the silo that is 6 metres, not the diameter, and the angle of
  11621.    repose for his grain is 40 degrees. However, if Quentin can find a set of
  11622.    solutions for this particular silo then he will be more than happy to keep
  11623.    it.
  11624.  
  11625.    If Quick thinking Quentin is to satisfy frustratingly fussy Fred the
  11626.    farmer's appetite for all things square then determine the values of $x$
  11627.    for all possible square space wastage options and calculate $\sum x$
  11628.    correct to 9 decimal places.
  11629.  
  11630.    
  11631.    p_431_grain_silo.png
  11632.    Answer: 5e5d81aa8bfaf92f68cdef0154c5c238
  11633.  
  11634.  
  11635. Problem 432
  11636. ===========
  11637.  
  11638.  
  11639.    Let S(n,m) = ∑φ(n × i) for 1 ≤ i ≤ m. (φ is Euler's totient function)
  11640.    You are given that S(510510,10^6 )= 45480596821125120.
  11641.  
  11642.    Find S(510510,10^11).
  11643.    Give the last 9 digits of your answer.
  11644.  
  11645.    
  11646.    Answer: e171c2872d650e47589842faa80f5707
  11647.  
  11648.  
  11649. Problem 433
  11650. ===========
  11651.  
  11652.  
  11653.    Let E(x[0], y[0]) be the number of steps it takes to determine the
  11654.    greatest common divisor of x[0] and y[0] with Euclid's algorithm. More
  11655.    formally:
  11656.    x[1] = y[0], y[1] = x[0] mod y[0]
  11657.    x[n] = y[n-1], y[n] = x[n-1] mod y[n-1]
  11658.    E(x[0], y[0]) is the smallest n such that y[n] = 0.
  11659.  
  11660.    We have E(1,1) = 1, E(10,6) = 3 and E(6,10) = 4.
  11661.  
  11662.    Define S(N) as the sum of E(x,y) for 1 ≤ x,y ≤ N.
  11663.    We have S(1) = 1, S(10) = 221 and S(100) = 39826.
  11664.  
  11665.    Find S(5·10^6).
  11666.  
  11667.    
  11668.    Answer: 0eeca9fa5cf25a2bfae01f1f04d6cd35
  11669.  
  11670.  
  11671. Problem 434
  11672. ===========
  11673.  
  11674.  
  11675.    Recall that a graph is a collection of vertices and edges connecting the
  11676.    vertices, and that two vertices connected by an edge are called adjacent.
  11677.    Graphs can be embedded in Euclidean space by associating each vertex with
  11678.    a point in the Euclidean space.
  11679.    A flexible graph is an embedding of a graph where it is possible to move
  11680.    one or more vertices continuously so that the distance between at least
  11681.    two nonadjacent vertices is altered while the distances between each pair
  11682.    of adjacent vertices is kept constant.
  11683.    A rigid graph is an embedding of a graph which is not flexible.
  11684.    Informally, a graph is rigid if by replacing the vertices with fully
  11685.    rotating hinges and the edges with rods that are unbending and inelastic,
  11686.    no parts of the graph can be moved independently from the rest of the
  11687.    graph.
  11688.  
  11689.    The grid graphs embedded in the Euclidean plane are not rigid, as the
  11690.    following animation demonstrates:
  11691.  
  11692.    However, one can make them rigid by adding diagonal edges to the cells.
  11693.    For example, for the 2x3 grid graph, there are 19 ways to make the graph
  11694.    rigid:
  11695.  
  11696.    Note that for the purposes of this problem, we do not consider changing
  11697.    the orientation of a diagonal edge or adding both diagonal edges to a cell
  11698.    as a different way of making a grid graph rigid.
  11699.  
  11700.    Let R(m,n) be the number of ways to make the m × n grid graph rigid.
  11701.    E.g. R(2,3) = 19 and R(5,5) = 23679901
  11702.  
  11703.    Define S(N) as ∑R(i,j) for 1 ≤ i, j ≤ N.
  11704.    E.g. S(5) = 25021721.
  11705.    Find S(100), give your answer modulo 1000000033
  11706.  
  11707.    
  11708.    Answer: f51d9fd41a8ce217682321a020be6fec
  11709.  
  11710.  
  11711. Problem 435
  11712. ===========
  11713.  
  11714.  
  11715.    The Fibonacci numbers {f[n], n ≥ 0} are defined recursively as f[n] =
  11716.    f[n-1] + f[n-2] with base cases f[0] = 0 and f[1] = 1.
  11717.  
  11718.    Define the polynomials {F[n], n ≥ 0} as F[n](x) = ∑f[i]x^i for 0 ≤ i ≤ n.
  11719.  
  11720.    For example, F[7](x) = x + x^2 + 2x^3 + 3x^4 + 5x^5 + 8x^6 + 13x^7, and
  11721.    F[7](11) = 268357683.
  11722.  
  11723.    Let n = 10^15. Find the sum [∑[0≤x≤100] F[n](x)] mod 1307674368000 (=
  11724.    15!).
  11725.  
  11726.    
  11727.    Answer: 0f08231a97e872f565a085de75743a1c
  11728.  
  11729.  
  11730. Problem 436
  11731. ===========
  11732.  
  11733.  
  11734.    Julie proposes the following wager to her sister Louise.
  11735.    She suggests they play a game of chance to determine who will wash the
  11736.    dishes.
  11737.    For this game, they shall use a generator of independent random numbers
  11738.    uniformly distributed between 0 and 1.
  11739.    The game starts with S = 0.
  11740.    The first player, Louise, adds to S different random numbers from the
  11741.    generator until S > 1 and records her last random number 'x'.
  11742.    The second player, Julie, continues adding to S different random numbers
  11743.    from the generator until S > 2 and records her last random number 'y'.
  11744.    The player with the highest number wins and the loser washes the dishes,
  11745.    i.e. if y > x the second player wins.
  11746.  
  11747.    For example, if the first player draws 0.62 and 0.44, the first player
  11748.    turn ends since 0.62+0.44 > 1 and x = 0.44.
  11749.    If the second players draws 0.1, 0.27 and 0.91, the second player turn
  11750.    ends since 0.62+0.44+0.1+0.27+0.91 > 2 and y = 0.91.Since y > x, the
  11751.    second player wins.
  11752.  
  11753.    Louise thinks about it for a second, and objects: "That's not fair".
  11754.    What is the probability that the second player wins?
  11755.    Give your answer rounded to 10 places behind the decimal point in the form
  11756.    0.abcdefghij
  11757.  
  11758.    
  11759.    Answer: d797ed72189f045e8ea48aa960fec1f3
  11760.  
  11761.  
  11762. Problem 437
  11763. ===========
  11764.  
  11765.  
  11766.    When we calculate 8^n modulo 11 for n=0 to 9 we get: 1, 8, 9, 6, 4, 10, 3,
  11767.    2, 5, 7.
  11768.    As we see all possible values from 1 to 10 occur. So 8 is a primitive root
  11769.    of 11.
  11770.    But there is more:
  11771.    If we take a closer look we see:
  11772.    1+8=9
  11773.    8+9=17≡6 mod 11
  11774.    9+6=15≡4 mod 11
  11775.    6+4=10
  11776.    4+10=14≡3 mod 11
  11777.    10+3=13≡2 mod 11
  11778.    3+2=5
  11779.    2+5=7
  11780.    5+7=12≡1 mod 11.
  11781.  
  11782.    So the powers of 8 mod 11 are cyclic with period 10, and 8^n + 8^n+1 ≡
  11783.    8^n+2 (mod 11).
  11784.    8 is called a Fibonacci primitive root of 11.
  11785.    Not every prime has a Fibonacci primitive root.
  11786.    There are 323 primes less than 10000 with one or more Fibonacci primitive
  11787.    roots and the sum of these primes is 1480491.
  11788.    Find the sum of the primes less than 100,000,000 with at least one
  11789.    Fibonacci primitive root.
  11790.    
  11791.    Answer: 74204709657207
  11792.  
  11793.  
  11794. Problem 438
  11795. ===========
  11796.  
  11797.  
  11798.    For an n-tuple of integers t = (a[1], ..., a[n]), let (x[1], ..., x[n]) be
  11799.    the solutions of the polynomial equation x^n + a[1