Archived Problems - Project Euler
Archived Problems - Project Euler
Problem1:Multiplesof3and5
Ifwelistallthenaturalnumbersbelow10thataremultiplesof3or5,weget3,5,6and9.Thesumofthese
multiplesis23.
Findthesumofallthemultiplesof3or5below1000.
Problem2:EvenFibonaccinumbers
EachnewtermintheFibonaccisequenceisgeneratedbyaddingtheprevioustwoterms.Bystartingwith1
and2,thefirst10termswillbe:
1,2,3,5,8,13,21,34,55,89,...
ByconsideringthetermsintheFibonaccisequencewhosevaluesdonotexceedfourmillion,findthesum
oftheevenvaluedterms.
Problem3:Largestprimefactor
Theprimefactorsof13195are5,7,13and29.
Whatisthelargestprimefactorofthenumber600851475143?
Problem4:Largestpalindromeproduct
Apalindromicnumberreadsthesamebothways.Thelargestpalindromemadefromtheproductoftwo2
digitnumbersis9009=9199.
Findthelargestpalindromemadefromtheproductoftwo3digitnumbers.
Problem5:Smallestmultiple
2520isthesmallestnumberthatcanbedividedbyeachofthenumbersfrom1to10withoutany
remainder.
Whatisthesmallestpositivenumberthatisevenlydivisiblebyallofthenumbersfrom1to20?
Problem6:Sumsquaredifference
Thesumofthesquaresofthefirsttennaturalnumbersis,
12+22+...+102=385
Thesquareofthesumofthefirsttennaturalnumbersis,
(1+2+...+10)2=552=3025
Hencethedifferencebetweenthesumofthesquaresofthefirsttennaturalnumbersandthesquareofthe
sumis3025385=2640.
Findthedifferencebetweenthesumofthesquaresofthefirstonehundrednaturalnumbersandthesquare
ofthesum.
Problem7:10001stprime
Bylistingthefirstsixprimenumbers:2,3,5,7,11,and13,wecanseethatthe6thprimeis13.
Whatisthe10001stprimenumber?
https://projecteuler.net/show=all
1/163
5/2/2015
Problem8:Largestproductinaseries
Thefouradjacentdigitsinthe1000digitnumberthathavethegreatestproductare9989=5832.
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450
Findthethirteenadjacentdigitsinthe1000digitnumberthathavethegreatestproduct.Whatisthevalueof
thisproduct?
Problem9:SpecialPythagoreantriplet
APythagoreantripletisasetofthreenaturalnumbers,a<b<c,forwhich,
a2+b2=c2
Forexample,32+42=9+16=25=52.
ThereexistsexactlyonePythagoreantripletforwhicha+b+c=1000.
Findtheproductabc.
Problem10:Summationofprimes
Thesumoftheprimesbelow10is2+3+5+7=17.
Findthesumofalltheprimesbelowtwomillion.
Problem11:Largestproductinagrid
Inthe2020gridbelow,fournumbersalongadiagonallinehavebeenmarkedinred.
0802229738150040007504050778521250779108
4949994017811857608717409843694804566200
8149317355791429937140675388300349133665
5270952304601142692468560132567137023691
2231167151676389419236542240402866331380
2447326099034502447533537836842035171250
3298812864236710263840675954706618386470
6726206802621220956394396308409166499421
2455580566739926971778789683148834896372
2136230975007644204535140061339734313395
7817532822753167159403800462161409535692
1639054296353147555888240017542436298557
8656004835718907054444374460215851541758
1980816805944769287392138652177704895540
0452088397359916079757321626267933279866
8836688757622072034633674655123263935369
0442167338253911249472180846293240627636
2069364172302388346299698267598574043616
2073352978319001743149714886811623570554
0170547183515469169233486143520189196748
Theproductofthesenumbersis26637814=1788696.
https://projecteuler.net/show=all
2/163
5/2/2015
Whatisthegreatestproductoffouradjacentnumbersinthesamedirection(up,down,left,right,or
diagonally)inthe2020grid?
Problem12:Highlydivisibletriangularnumber
Thesequenceoftrianglenumbersisgeneratedbyaddingthenaturalnumbers.Sothe7thtrianglenumber
wouldbe1+2+3+4+5+6+7=28.Thefirsttentermswouldbe:
1,3,6,10,15,21,28,36,45,55,...
Letuslistthefactorsofthefirstseventrianglenumbers:
1:1
3:1,3
6:1,2,3,6
10:1,2,5,10
15:1,3,5,15
21:1,3,7,21
28:1,2,4,7,14,28
Wecanseethat28isthefirsttrianglenumbertohaveoverfivedivisors.
Whatisthevalueofthefirsttrianglenumbertohaveoverfivehundreddivisors?
Problem13:Largesum
Workoutthefirsttendigitsofthesumofthefollowingonehundred50digitnumbers.
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
62176457141856560629502157223196586755079324193331
64906352462741904929101432445813822663347944758178
92575867718337217661963751590579239728245598838407
58203565325359399008402633568948830189458628227828
80181199384826282014278194139940567587151170094390
35398664372827112653829987240784473053190104293586
86515506006295864861532075273371959191420517255829
71693888707715466499115593487603532921714970056938
54370070576826684624621495650076471787294438377604
53282654108756828443191190634694037855217779295145
36123272525000296071075082563815656710885258350721
45876576172410976447339110607218265236877223636045
17423706905851860660448207621209813287860733969412
81142660418086830619328460811191061556940512689692
51934325451728388641918047049293215058642563049483
62467221648435076201727918039944693004732956340691
15732444386908125794514089057706229429197107928209
55037687525678773091862540744969844508330393682126
18336384825330154686196124348767681297534375946515
80386287592878490201521685554828717201219257766954
78182833757993103614740356856449095527097864797581
16726320100436897842553539920931837441497806860984
48403098129077791799088218795327364475675590848030
87086987551392711854517078544161852424320693150332
59959406895756536782107074926966537676326235447210
69793950679652694742597709739166693763042633987085
41052684708299085211399427365734116182760315001271
65378607361501080857009149939512557028198746004375
35829035317434717326932123578154982629742552737307
94953759765105305946966067683156574377167401875275
88902802571733229619176668713819931811048770190271
25267680276078003013678680992525463401061632866526
36270218540497705585629946580636237993140746255962
24074486908231174977792365466257246923322810917141
91430288197103288597806669760892938638285025333403
34413065578016127815921815005561868836468420090470
23053081172816430487623791969842487255036638784583
11487696932154902810424020138335124462181441773470
63783299490636259666498587618221225225512486764533
67720186971698544312419572409913959008952310058822
95548255300263520781532296796249481641953868218774
76085327132285723110424803456124867697064507995236
37774242535411291684276865538926205024910326572967
23701913275725675285653248258265463092207058596522
29798860272258331913126375147341994889534765745501
https://projecteuler.net/show=all
3/163
5/2/2015
Problem14:LongestCollatzsequence
Thefollowingiterativesequenceisdefinedforthesetofpositiveintegers:
nn/2(niseven)
n3n+1(nisodd)
Usingtheruleaboveandstartingwith13,wegeneratethefollowingsequence:
134020105168421
Itcanbeseenthatthissequence(startingat13andfinishingat1)contains10terms.Althoughithasnot
beenprovedyet(CollatzProblem),itisthoughtthatallstartingnumbersfinishat1.
Whichstartingnumber,underonemillion,producesthelongestchain?
NOTE:Oncethechainstartsthetermsareallowedtogoaboveonemillion.
Problem15:Latticepaths
Startinginthetopleftcornerofa22grid,andonlybeingabletomovetotherightanddown,thereare
exactly6routestothebottomrightcorner.
Howmanysuchroutesaretherethrougha2020grid?
https://projecteuler.net/show=all
4/163
5/2/2015
Problem16:Powerdigitsum
215=32768andthesumofitsdigitsis3+2+7+6+8=26.
Whatisthesumofthedigitsofthenumber21000?
Problem17:Numberlettercounts
Ifthenumbers1to5arewrittenoutinwords:one,two,three,four,five,thenthereare3+3+5+4+4=
19lettersusedintotal.
Ifallthenumbersfrom1to1000(onethousand)inclusivewerewrittenoutinwords,howmanyletterswould
beused?
NOTE:Donotcountspacesorhyphens.Forexample,342(threehundredandfortytwo)contains23lettersand115
(onehundredandfifteen)contains20letters.Theuseof"and"whenwritingoutnumbersisincompliancewithBritish
usage.
Problem18:MaximumpathsumI
Bystartingatthetopofthetrianglebelowandmovingtoadjacentnumbersontherowbelow,themaximum
totalfromtoptobottomis23.
3
74
246
8593
Thatis,3+7+4+9=23.
Findthemaximumtotalfromtoptobottomofthetrianglebelow:
75
9564
174782
18358710
2004824765
190123750334
88027773076367
9965042806167092
414126568340807033
41487233473237169429
5371446525439152975114
701133287773177839681757
91715238171491435850272948
6366046889536730731669874031
046298272309709873933853600423
NOTE:Asthereareonly16384routes,itispossibletosolvethisproblembytryingeveryroute.However,Problem67,
isthesamechallengewithatrianglecontainingonehundredrowsitcannotbesolvedbybruteforce,andrequiresa
clevermethod!o)
Problem19:CountingSundays
Youaregiventhefollowinginformation,butyoumayprefertodosomeresearchforyourself.
1Jan1900wasaMonday.
ThirtydayshasSeptember,
April,JuneandNovember.
Alltheresthavethirtyone,
SavingFebruaryalone,
Whichhastwentyeight,rainorshine.
Andonleapyears,twentynine.
Aleapyearoccursonanyyearevenlydivisibleby4,butnotonacenturyunlessitisdivisibleby400.
HowmanySundaysfellonthefirstofthemonthduringthetwentiethcentury(1Jan1901to31Dec2000)?
Problem20:Factorialdigitsum
https://projecteuler.net/show=all
5/163
5/2/2015
n!meansn(n1)...321
Forexample,10!=109...321=3628800,
andthesumofthedigitsinthenumber10!is3+6+2+8+8+0+0=27.
Findthesumofthedigitsinthenumber100!
Problem21:Amicablenumbers
Letd(n)bedefinedasthesumofproperdivisorsofn(numberslessthannwhichdivideevenlyinton).
Ifd(a)=bandd(b)=a,whereab,thenaandbareanamicablepairandeachofaandbarecalled
amicablenumbers.
Forexample,theproperdivisorsof220are1,2,4,5,10,11,20,22,44,55and110therefored(220)=
284.Theproperdivisorsof284are1,2,4,71and142sod(284)=220.
Evaluatethesumofalltheamicablenumbersunder10000.
Problem22:Namesscores
Usingnames.txt(rightclickand'SaveLink/TargetAs...'),a46Ktextfilecontainingoverfivethousandfirst
names,beginbysortingitintoalphabeticalorder.Thenworkingoutthealphabeticalvalueforeachname,
multiplythisvaluebyitsalphabeticalpositioninthelisttoobtainanamescore.
Forexample,whenthelistissortedintoalphabeticalorder,COLIN,whichisworth3+15+12+9+14=
53,isthe938thnameinthelist.So,COLINwouldobtainascoreof93853=49714.
Whatisthetotalofallthenamescoresinthefile?
Problem23:Nonabundantsums
Aperfectnumberisanumberforwhichthesumofitsproperdivisorsisexactlyequaltothenumber.For
example,thesumoftheproperdivisorsof28wouldbe1+2+4+7+14=28,whichmeansthat28isa
perfectnumber.
Anumberniscalleddeficientifthesumofitsproperdivisorsislessthannanditiscalledabundantifthis
sumexceedsn.
As12isthesmallestabundantnumber,1+2+3+4+6=16,thesmallestnumberthatcanbewrittenas
thesumoftwoabundantnumbersis24.Bymathematicalanalysis,itcanbeshownthatallintegersgreater
than28123canbewrittenasthesumoftwoabundantnumbers.However,thisupperlimitcannotbe
reducedanyfurtherbyanalysiseventhoughitisknownthatthegreatestnumberthatcannotbeexpressed
asthesumoftwoabundantnumbersislessthanthislimit.
Findthesumofallthepositiveintegerswhichcannotbewrittenasthesumoftwoabundantnumbers.
Problem24:Lexicographicpermutations
Apermutationisanorderedarrangementofobjects.Forexample,3124isonepossiblepermutationofthe
digits1,2,3and4.Ifallofthepermutationsarelistednumericallyoralphabetically,wecallitlexicographic
order.Thelexicographicpermutationsof0,1and2are:
012021102120201210
Whatisthemillionthlexicographicpermutationofthedigits0,1,2,3,4,5,6,7,8and9?
Problem25:1000digitFibonaccinumber
TheFibonaccisequenceisdefinedbytherecurrencerelation:
Fn=Fn1+Fn2,whereF1=1andF2=1.
Hencethefirst12termswillbe:
F1=1
https://projecteuler.net/show=all
6/163
5/2/2015
F2=1
F3=2
F4=3
F5=5
F6=8
F7=13
F8=21
F9=34
F10=55
F11=89
F12=144
The12thterm,F12,isthefirsttermtocontainthreedigits.
WhatistheindexofthefirsttermintheFibonaccisequencetocontain1000digits?
Problem26:Reciprocalcycles
Aunitfractioncontains1inthenumerator.Thedecimalrepresentationoftheunitfractionswith
denominators2to10aregiven:
1/
2
1/
3
1/
4
1/
5
1/
6
1/
7
1/
8
1/
9
1/
10
= 0.5
= 0.(3)
= 0.25
= 0.2
= 0.1(6)
= 0.(142857)
= 0.125
= 0.(1)
= 0.1
Where0.1(6)means0.166666...,andhasa1digitrecurringcycle.Itcanbeseenthat1/7hasa6digit
recurringcycle.
Findthevalueofd<1000forwhich1/dcontainsthelongestrecurringcycleinitsdecimalfractionpart.
Problem27:Quadraticprimes
Eulerdiscoveredtheremarkablequadraticformula:
n+n+41
Itturnsoutthattheformulawillproduce40primesfortheconsecutivevaluesn=0to39.However,whenn
=40,402+40+41=40(40+1)+41isdivisibleby41,andcertainlywhenn=41,41+41+41isclearly
divisibleby41.
Theincredibleformulan79n+1601wasdiscovered,whichproduces80primesfortheconsecutive
valuesn=0to79.Theproductofthecoefficients,79and1601,is126479.
Consideringquadraticsoftheform:
n+an+b,where|a|<1000and|b|<1000
where|n|isthemodulus/absolutevalueofn
e.g.|11|=11and|4|=4
Findtheproductofthecoefficients,aandb,forthequadraticexpressionthatproducesthemaximum
numberofprimesforconsecutivevaluesofn,startingwithn=0.
Problem28:Numberspiraldiagonals
Startingwiththenumber1andmovingtotherightinaclockwisedirectiona5by5spiralisformedas
follows:
https://projecteuler.net/show=all
7/163
5/2/2015
2122232425
2078910
1961211
1854312
1716151413
Itcanbeverifiedthatthesumofthenumbersonthediagonalsis101.
Whatisthesumofthenumbersonthediagonalsina1001by1001spiralformedinthesameway?
Problem29:Distinctpowers
Considerallintegercombinationsofabfor2a5and2b5:
22=4,23=8,24=16,25=32
32=9,33=27,34=81,35=243
42=16,43=64,44=256,45=1024
52=25,53=125,54=625,55=3125
Iftheyarethenplacedinnumericalorder,withanyrepeatsremoved,wegetthefollowingsequenceof15
distinctterms:
4,8,9,16,25,27,32,64,81,125,243,256,625,1024,3125
Howmanydistincttermsareinthesequencegeneratedbyabfor2a100and2b100?
Problem30:Digitfifthpowers
Surprisinglythereareonlythreenumbersthatcanbewrittenasthesumoffourthpowersoftheirdigits:
1634=14+64+34+44
8208=84+24+04+84
9474=94+44+74+44
As1=14isnotasumitisnotincluded.
Thesumofthesenumbersis1634+8208+9474=19316.
Findthesumofallthenumbersthatcanbewrittenasthesumoffifthpowersoftheirdigits.
Problem31:Coinsums
InEnglandthecurrencyismadeupofpound,,andpence,p,andthereareeightcoinsingeneral
circulation:
1p,2p,5p,10p,20p,50p,1(100p)and2(200p).
Itispossibletomake2inthefollowingway:
11+150p+220p+15p+12p+31p
Howmanydifferentwayscan2bemadeusinganynumberofcoins?
Problem32:Pandigitalproducts
Weshallsaythatanndigitnumberispandigitalifitmakesuseofallthedigits1tonexactlyoncefor
example,the5digitnumber,15234,is1through5pandigital.
Theproduct7254isunusual,astheidentity,39186=7254,containingmultiplicand,multiplier,and
productis1through9pandigital.
Findthesumofallproductswhosemultiplicand/multiplier/productidentitycanbewrittenasa1through9
pandigital.
HINT:Someproductscanbeobtainedinmorethanonewaysobesuretoonlyincludeitonceinyoursum.
https://projecteuler.net/show=all
8/163
5/2/2015
Problem33:Digitcancellingfractions
Thefraction49/98isacuriousfraction,asaninexperiencedmathematicianinattemptingtosimplifyitmay
incorrectlybelievethat49/98=4/8,whichiscorrect,isobtainedbycancellingthe9s.
Weshallconsiderfractionslike,30/50=3/5,tobetrivialexamples.
Thereareexactlyfournontrivialexamplesofthistypeoffraction,lessthanoneinvalue,andcontainingtwo
digitsinthenumeratoranddenominator.
Iftheproductofthesefourfractionsisgiveninitslowestcommonterms,findthevalueofthedenominator.
Problem34:Digitfactorials
145isacuriousnumber,as1!+4!+5!=1+24+120=145.
Findthesumofallnumberswhichareequaltothesumofthefactorialoftheirdigits.
Note:as1!=1and2!=2arenotsumstheyarenotincluded.
Problem35:Circularprimes
Thenumber,197,iscalledacircularprimebecauseallrotationsofthedigits:197,971,and719,are
themselvesprime.
Therearethirteensuchprimesbelow100:2,3,5,7,11,13,17,31,37,71,73,79,and97.
Howmanycircularprimesaretherebelowonemillion?
Problem36:Doublebasepalindromes
Thedecimalnumber,585=10010010012(binary),ispalindromicinbothbases.
Findthesumofallnumbers,lessthanonemillion,whicharepalindromicinbase10andbase2.
(Pleasenotethatthepalindromicnumber,ineitherbase,maynotincludeleadingzeros.)
Problem37:Truncatableprimes
Thenumber3797hasaninterestingproperty.Beingprimeitself,itispossibletocontinuouslyremovedigits
fromlefttoright,andremainprimeateachstage:3797,797,97,and7.Similarlywecanworkfromrightto
left:3797,379,37,and3.
Findthesumoftheonlyelevenprimesthatarebothtruncatablefromlefttorightandrighttoleft.
NOTE:2,3,5,and7arenotconsideredtobetruncatableprimes.
Problem38:Pandigitalmultiples
Takethenumber192andmultiplyitbyeachof1,2,and3:
1921=192
1922=384
1923=576
Byconcatenatingeachproductwegetthe1to9pandigital,192384576.Wewillcall192384576the
concatenatedproductof192and(1,2,3)
Thesamecanbeachievedbystartingwith9andmultiplyingby1,2,3,4,and5,givingthepandigital,
918273645,whichistheconcatenatedproductof9and(1,2,3,4,5).
Whatisthelargest1to9pandigital9digitnumberthatcanbeformedastheconcatenatedproductofan
integerwith(1,2,...,n)wheren>1?
https://projecteuler.net/show=all
9/163
5/2/2015
Problem39:Integerrighttriangles
Ifpistheperimeterofarightangletrianglewithintegrallengthsides,{a,b,c},thereareexactlythree
solutionsforp=120.
{20,48,52},{24,45,51},{30,40,50}
Forwhichvalueofp1000,isthenumberofsolutionsmaximised?
Problem40:Champernowne'sconstant
Anirrationaldecimalfractioniscreatedbyconcatenatingthepositiveintegers:
0.123456789101112131415161718192021...
Itcanbeseenthatthe12thdigitofthefractionalpartis1.
Ifdnrepresentsthenthdigitofthefractionalpart,findthevalueofthefollowingexpression.
d1d10d100d1000d10000d100000d1000000
Problem41:Pandigitalprime
Weshallsaythatanndigitnumberispandigitalifitmakesuseofallthedigits1tonexactlyonce.For
example,2143isa4digitpandigitalandisalsoprime.
Whatisthelargestndigitpandigitalprimethatexists?
Problem42:Codedtrianglenumbers
Thenthtermofthesequenceoftrianglenumbersisgivenby,tn=n(n+1)sothefirsttentrianglenumbers
are:
1,3,6,10,15,21,28,36,45,55,...
Byconvertingeachletterinawordtoanumbercorrespondingtoitsalphabeticalpositionandaddingthese
valuesweformawordvalue.Forexample,thewordvalueforSKYis19+11+25=55=t10.Iftheword
valueisatrianglenumberthenweshallcallthewordatriangleword.
Usingwords.txt(rightclickand'SaveLink/TargetAs...'),a16Ktextfilecontainingnearlytwothousand
commonEnglishwords,howmanyaretrianglewords?
Problem43:Substringdivisibility
Thenumber,1406357289,isa0to9pandigitalnumberbecauseitismadeupofeachofthedigits0to9in
someorder,butitalsohasaratherinterestingsubstringdivisibilityproperty.
Letd1bethe1stdigit,d2bethe2nddigit,andsoon.Inthisway,wenotethefollowing:
d2d3d4=406isdivisibleby2
d3d4d5=063isdivisibleby3
d4d5d6=635isdivisibleby5
d5d6d7=357isdivisibleby7
d6d7d8=572isdivisibleby11
d7d8d9=728isdivisibleby13
d8d9d10=289isdivisibleby17
Findthesumofall0to9pandigitalnumberswiththisproperty.
Problem44:Pentagonnumbers
Pentagonalnumbersaregeneratedbytheformula,Pn=n(3n1)/2.Thefirsttenpentagonalnumbersare:
https://projecteuler.net/show=all
10/163
5/2/2015
1,5,12,22,35,51,70,92,117,145,...
ItcanbeseenthatP4+P7=22+70=92=P8.However,theirdifference,7022=48,isnotpentagonal.
Findthepairofpentagonalnumbers,PjandPk,forwhichtheirsumanddifferencearepentagonalandD=
|PkPj|isminimisedwhatisthevalueofD?
Problem45:Triangular,pentagonal,andhexagonal
Triangle,pentagonal,andhexagonalnumbersaregeneratedbythefollowingformulae:
Triangle
Tn=n(n+1)/2 1,3,6,10,15,...
Problem46:Goldbach'sotherconjecture
ItwasproposedbyChristianGoldbachthateveryoddcompositenumbercanbewrittenasthesumofa
primeandtwiceasquare.
9=7+212
15=7+222
21=3+232
25=7+232
27=19+222
33=31+212
Itturnsoutthattheconjecturewasfalse.
Whatisthesmallestoddcompositethatcannotbewrittenasthesumofaprimeandtwiceasquare?
Problem47:Distinctprimesfactors
Thefirsttwoconsecutivenumberstohavetwodistinctprimefactorsare:
14=27
15=35
Thefirstthreeconsecutivenumberstohavethreedistinctprimefactorsare:
644=2723
645=3543
646=21719.
Findthefirstfourconsecutiveintegerstohavefourdistinctprimefactors.Whatisthefirstofthese
numbers?
Problem48:Selfpowers
Theseries,11+22+33+...+1010=10405071317.
Findthelasttendigitsoftheseries,11+22+33+...+10001000.
Problem49:Primepermutations
Thearithmeticsequence,1487,4817,8147,inwhicheachofthetermsincreasesby3330,isunusualintwo
ways:(i)eachofthethreetermsareprime,and,(ii)eachofthe4digitnumbersarepermutationsofone
another.
https://projecteuler.net/show=all
11/163
5/2/2015
Therearenoarithmeticsequencesmadeupofthree1,2,or3digitprimes,exhibitingthisproperty,but
thereisoneother4digitincreasingsequence.
What12digitnumberdoyouformbyconcatenatingthethreetermsinthissequence?
Problem50:Consecutiveprimesum
Theprime41,canbewrittenasthesumofsixconsecutiveprimes:
41=2+3+5+7+11+13
Thisisthelongestsumofconsecutiveprimesthataddstoaprimebelowonehundred.
Thelongestsumofconsecutiveprimesbelowonethousandthataddstoaprime,contains21terms,andis
equalto953.
Whichprime,belowonemillion,canbewrittenasthesumofthemostconsecutiveprimes?
Problem51:Primedigitreplacements
Byreplacingthe1stdigitofthe2digitnumber*3,itturnsoutthatsixoftheninepossiblevalues:13,23,43,
53,73,and83,areallprime.
Byreplacingthe3rdand4thdigitsof56**3withthesamedigit,this5digitnumberisthefirstexamplehaving
sevenprimesamongthetengeneratednumbers,yieldingthefamily:56003,56113,56333,56443,56663,
56773,and56993.Consequently56003,beingthefirstmemberofthisfamily,isthesmallestprimewiththis
property.
Findthesmallestprimewhich,byreplacingpartofthenumber(notnecessarilyadjacentdigits)withthe
samedigit,ispartofaneightprimevaluefamily.
Problem52:Permutedmultiples
Itcanbeseenthatthenumber,125874,anditsdouble,251748,containexactlythesamedigits,butina
differentorder.
Findthesmallestpositiveinteger,x,suchthat2x,3x,4x,5x,and6x,containthesamedigits.
Problem53:Combinatoricselections
Thereareexactlytenwaysofselectingthreefromfive,12345:
123,124,125,134,135,145,234,235,245,and345
Incombinatorics,weusethenotation,5C3=10.
Ingeneral,
n!
nC =
r r!(nr)! ,wherern,n!=n(n1)...321,and0!=1.
Itisnotuntiln=23,thatavalueexceedsonemillion:23C10=1144066.
Howmany,notnecessarilydistinct,valuesofnCr,for1n100,aregreaterthanonemillion?
Problem54:Pokerhands
Inthecardgamepoker,ahandconsistsoffivecardsandareranked,fromlowesttohighest,inthe
followingway:
HighCard:Highestvaluecard.
OnePair:Twocardsofthesamevalue.
TwoPairs:Twodifferentpairs.
ThreeofaKind:Threecardsofthesamevalue.
https://projecteuler.net/show=all
12/163
5/2/2015
Straight:Allcardsareconsecutivevalues.
Flush:Allcardsofthesamesuit.
FullHouse:Threeofakindandapair.
FourofaKind:Fourcardsofthesamevalue.
StraightFlush:Allcardsareconsecutivevaluesofsamesuit.
RoyalFlush:Ten,Jack,Queen,King,Ace,insamesuit.
Thecardsarevaluedintheorder:
2,3,4,5,6,7,8,9,10,Jack,Queen,King,Ace.
Iftwoplayershavethesamerankedhandsthentherankmadeupofthehighestvaluewinsforexample,a
pairofeightsbeatsapairoffives(seeexample1below).Butiftworankstie,forexample,bothplayers
haveapairofqueens,thenhighestcardsineachhandarecompared(seeexample4below)ifthehighest
cardstiethenthenexthighestcardsarecompared,andsoon.
Considerthefollowingfivehandsdealttotwoplayers:
Hand
Player1
Player2
Winner
1
5H5C6S7SKD 2C3S8S8DTD Player2
PairofFives
2
3
4
5
5D8C9SJSAC
HighestcardAce
2D9CASAHAC
ThreeAces
PairofEights
2C5C7D8SQH
HighestcardQueen
3D6D7DTDQD
FlushwithDiamonds
Player1
Player2
4D6S9HQHQC
3D6D7HQDQS
Player1
2H2D4C4D4S
3C3D3S9S9D
Player1
PairofQueens
PairofQueens
HighestcardNine
HighestcardSeven
FullHouse
FullHouse
WithThreeFours
withThreeThrees
Thefile,poker.txt,containsonethousandrandomhandsdealttotwoplayers.Eachlineofthefilecontains
tencards(separatedbyasinglespace):thefirstfivearePlayer1'scardsandthelastfivearePlayer2's
cards.Youcanassumethatallhandsarevalid(noinvalidcharactersorrepeatedcards),eachplayer'shand
isinnospecificorder,andineachhandthereisaclearwinner.
HowmanyhandsdoesPlayer1win?
Problem55:Lychrelnumbers
Ifwetake47,reverseandadd,47+74=121,whichispalindromic.
Notallnumbersproducepalindromessoquickly.Forexample,
349+943=1292,
1292+2921=4213
4213+3124=7337
Thatis,349tookthreeiterationstoarriveatapalindrome.
Althoughnoonehasprovedityet,itisthoughtthatsomenumbers,like196,neverproduceapalindrome.A
numberthatneverformsapalindromethroughthereverseandaddprocessiscalledaLychrelnumber.Due
tothetheoreticalnatureofthesenumbers,andforthepurposeofthisproblem,weshallassumethata
numberisLychreluntilprovenotherwise.Inadditionyouaregiventhatforeverynumberbelowten
thousand,itwilleither(i)becomeapalindromeinlessthanfiftyiterations,or,(ii)noone,withallthe
computingpowerthatexists,hasmanagedsofartomapittoapalindrome.Infact,10677isthefirst
numbertobeshowntorequireoverfiftyiterationsbeforeproducingapalindrome:
4668731596684224866951378664(53iterations,28digits).
Surprisingly,therearepalindromicnumbersthatarethemselvesLychrelnumbersthefirstexampleis4994.
HowmanyLychrelnumbersaretherebelowtenthousand?
NOTE:Wordingwasmodifiedslightlyon24April2007toemphasisethetheoreticalnatureofLychrelnumbers.
Problem56:Powerfuldigitsum
Agoogol(10100)isamassivenumber:onefollowedbyonehundredzeros100100isalmostunimaginably
large:onefollowedbytwohundredzeros.Despitetheirsize,thesumofthedigitsineachnumberisonly1.
Consideringnaturalnumbersoftheform,ab,wherea,b<100,whatisthemaximumdigitalsum?
https://projecteuler.net/show=all
13/163
5/2/2015
Problem57:Squarerootconvergents
Itispossibletoshowthatthesquarerootoftwocanbeexpressedasaninfinitecontinuedfraction.
2=1+1/(2+1/(2+1/(2+...)))=1.414213...
Byexpandingthisforthefirstfouriterations,weget:
1+1/2=3/2=1.5
1+1/(2+1/2)=7/5=1.4
1+1/(2+1/(2+1/2))=17/12=1.41666...
1+1/(2+1/(2+1/(2+1/2)))=41/29=1.41379...
Thenextthreeexpansionsare99/70,239/169,and577/408,buttheeighthexpansion,1393/985,isthefirst
examplewherethenumberofdigitsinthenumeratorexceedsthenumberofdigitsinthedenominator.
Inthefirstonethousandexpansions,howmanyfractionscontainanumeratorwithmoredigitsthan
denominator?
Problem58:Spiralprimes
Startingwith1andspirallinganticlockwiseinthefollowingway,asquarespiralwithsidelength7isformed.
37363534333231
38171615141330
39185431229
40196121128
41207891027
42212223242526
43444546474849
Itisinterestingtonotethattheoddsquaresliealongthebottomrightdiagonal,butwhatismoreinteresting
isthat8outofthe13numberslyingalongbothdiagonalsareprimethatis,aratioof8/1362%.
Ifonecompletenewlayeriswrappedaroundthespiralabove,asquarespiralwithsidelength9willbe
formed.Ifthisprocessiscontinued,whatisthesidelengthofthesquarespiralforwhichtheratioofprimes
alongbothdiagonalsfirstfallsbelow10%?
Problem59:XORdecryption
EachcharacteronacomputerisassignedauniquecodeandthepreferredstandardisASCII(American
StandardCodeforInformationInterchange).Forexample,uppercaseA=65,asterisk(*)=42,and
lowercasek=107.
Amodernencryptionmethodistotakeatextfile,convertthebytestoASCII,thenXOReachbytewitha
givenvalue,takenfromasecretkey.TheadvantagewiththeXORfunctionisthatusingthesame
encryptionkeyontheciphertext,restorestheplaintextforexample,65XOR42=107,then107XOR42=
65.
Forunbreakableencryption,thekeyisthesamelengthastheplaintextmessage,andthekeyismadeup
ofrandombytes.Theuserwouldkeeptheencryptedmessageandtheencryptionkeyindifferentlocations,
andwithoutboth"halves",itisimpossibletodecryptthemessage.
Unfortunately,thismethodisimpracticalformostusers,sothemodifiedmethodistouseapasswordasa
key.Ifthepasswordisshorterthanthemessage,whichislikely,thekeyisrepeatedcyclicallythroughout
themessage.Thebalanceforthismethodisusingasufficientlylongpasswordkeyforsecurity,butshort
enoughtobememorable.
Yourtaskhasbeenmadeeasy,astheencryptionkeyconsistsofthreelowercasecharacters.Using
cipher.txt(rightclickand'SaveLink/TargetAs...'),afilecontainingtheencryptedASCIIcodes,andthe
knowledgethattheplaintextmustcontaincommonEnglishwords,decryptthemessageandfindthesumof
theASCIIvaluesintheoriginaltext.
Problem60:Primepairsets
Theprimes3,7,109,and673,arequiteremarkable.Bytakinganytwoprimesandconcatenatingthemin
anyordertheresultwillalwaysbeprime.Forexample,taking7and109,both7109and1097areprime.
Thesumofthesefourprimes,792,representsthelowestsumforasetoffourprimeswiththisproperty.
Findthelowestsumforasetoffiveprimesforwhichanytwoprimesconcatenatetoproduceanotherprime.
https://projecteuler.net/show=all
14/163
5/2/2015
Problem61:Cyclicalfiguratenumbers
Triangle,square,pentagonal,hexagonal,heptagonal,andoctagonalnumbersareallfigurate(polygonal)
numbersandaregeneratedbythefollowingformulae:
Triangle
P3,n=n(n+1)/2 1,3,6,10,15,...
Square
P4,n=n2
1,4,9,16,25,...
1,8,21,40,65,...
Theorderedsetofthree4digitnumbers:8128,2882,8281,hasthreeinterestingproperties.
1. Thesetiscyclic,inthatthelasttwodigitsofeachnumberisthefirsttwodigitsofthenextnumber
(includingthelastnumberwiththefirst).
2. Eachpolygonaltype:triangle(P3,127=8128),square(P4,91=8281),andpentagonal(P5,44=2882),is
representedbyadifferentnumberintheset.
3. Thisistheonlysetof4digitnumberswiththisproperty.
Findthesumoftheonlyorderedsetofsixcyclic4digitnumbersforwhicheachpolygonaltype:triangle,
square,pentagonal,hexagonal,heptagonal,andoctagonal,isrepresentedbyadifferentnumberintheset.
Problem62:Cubicpermutations
Thecube,41063625(3453),canbepermutedtoproducetwoothercubes:56623104(3843)and66430125
(4053).Infact,41063625isthesmallestcubewhichhasexactlythreepermutationsofitsdigitswhichare
alsocube.
Findthesmallestcubeforwhichexactlyfivepermutationsofitsdigitsarecube.
Problem63:Powerfuldigitcounts
The5digitnumber,16807=75,isalsoafifthpower.Similarly,the9digitnumber,134217728=89,isaninth
power.
Howmanyndigitpositiveintegersexistwhicharealsoannthpower?
Problem64:Oddperiodsquareroots
Allsquarerootsareperiodicwhenwrittenascontinuedfractionsandcanbewrittenintheform:
N=a0+
a1+
a2+
1
1
a3+...
Forexample,letusconsider23:
23=4+234=4+
1 =4+
1
1
233
1+
234
7
Ifwecontinuewewouldgetthefollowingexpansion:
23=4+
1
1+
1
3+
1
1+ 1
8+...
Theprocesscanbesummarisedasfollows:
1
23+4
233
a0=4, 234
=
=1+
7
7
7
7(23+3)
https://projecteuler.net/show=all
233
15/163
5/2/2015
a1=1, 233=
14
=3+
2
2(23+3)
234
a2=3, 233
=
=1+
14
7
7
7(23+4)
a3=1, 234
=
=8+234
7
1
23+4
233
a4=8, 234
=
=1+
7
7
7
7(23+3)
233
a5=1, 233
=
=3+
14
2
2
2(23+3)
234
a6=3, 233
=
=1+
14
7
7
7(23+4)
a7=1, 234
=
=8+234
7
Itcanbeseenthatthesequenceisrepeating.Forconciseness,weusethenotation23=[4(1,3,1,8)],to
indicatethattheblock(1,3,1,8)repeatsindefinitely.
Thefirsttencontinuedfractionrepresentationsof(irrational)squarerootsare:
2=[1(2)],period=1
3=[1(1,2)],period=2
5=[2(4)],period=1
6=[2(2,4)],period=2
7=[2(1,1,1,4)],period=4
8=[2(1,4)],period=2
10=[3(6)],period=1
11=[3(3,6)],period=2
12=[3(2,6)],period=2
13=[3(1,1,1,1,6)],period=5
Exactlyfourcontinuedfractions,forN13,haveanoddperiod.
HowmanycontinuedfractionsforN10000haveanoddperiod?
Problem65:Convergentsofe
Thesquarerootof2canbewrittenasaninfinitecontinuedfraction.
2=1+
1
2+
1
2+
1
2+ 1
2+...
Theinfinitecontinuedfractioncanbewritten,2=[1(2)],(2)indicatesthat2repeatsadinfinitum.Ina
similarway,23=[4(1,3,1,8)].
Itturnsoutthatthesequenceofpartialvaluesofcontinuedfractionsforsquarerootsprovidethebest
rationalapproximations.Letusconsidertheconvergentsfor2.
1+1=3/2
2
1+ 1 =7/5
2+1
2
1+ 1 =17/12
2+ 1
2+1
2
1+
1
=41/29
2+ 1
2+ 1
2+1
2
Hencethesequenceofthefirsttenconvergentsfor2are:
1,3/2,7/5,17/12,41/29,99/70,239/169,577/408,1393/985,3363/2378,...
Whatismostsurprisingisthattheimportantmathematicalconstant,
e=[21,2,1,1,4,1,1,6,1,...,1,2k,1,...].
Thefirsttentermsinthesequenceofconvergentsforeare:
2,3,8/3,11/4,19/7,87/32,106/39,193/71,1264/465,1457/536,...
https://projecteuler.net/show=all
16/163
5/2/2015
Thesumofdigitsinthenumeratorofthe10thconvergentis1+4+5+7=17.
Findthesumofdigitsinthenumeratorofthe100thconvergentofthecontinuedfractionfore.
Problem66:Diophantineequation
ConsiderquadraticDiophantineequationsoftheform:
x2Dy2=1
Forexample,whenD=13,theminimalsolutioninxis6492131802=1.
ItcanbeassumedthattherearenosolutionsinpositiveintegerswhenDissquare.
ByfindingminimalsolutionsinxforD={2,3,5,6,7},weobtainthefollowing:
32222=1
22312=1
92542=1
52622=1
82732=1
Hence,byconsideringminimalsolutionsinxforD7,thelargestxisobtainedwhenD=5.
FindthevalueofD1000inminimalsolutionsofxforwhichthelargestvalueofxisobtained.
Problem67:MaximumpathsumII
Bystartingatthetopofthetrianglebelowandmovingtoadjacentnumbersontherowbelow,themaximum
totalfromtoptobottomis23.
3
74
246
8593
Thatis,3+7+4+9=23.
Findthemaximumtotalfromtoptobottomintriangle.txt(rightclickand'SaveLink/TargetAs...'),a15Ktext
filecontainingatrianglewithonehundredrows.
NOTE:ThisisamuchmoredifficultversionofProblem18.Itisnotpossibletotryeveryroutetosolvethisproblem,as
thereare299altogether!Ifyoucouldcheckonetrillion(1012)routeseveryseconditwouldtakeovertwentybillionyears
tocheckthemall.Thereisanefficientalgorithmtosolveit.o)
Problem68:Magic5gonring
Considerthefollowing"magic"3gonring,filledwiththenumbers1to6,andeachlineaddingtonine.
Workingclockwise,andstartingfromthegroupofthreewiththenumericallylowestexternalnode(4,3,2in
thisexample),eachsolutioncanbedescribeduniquely.Forexample,theabovesolutioncanbedescribed
bytheset:4,3,26,2,15,1,3.
Itispossibletocompletetheringwithfourdifferenttotals:9,10,11,and12.Thereareeightsolutionsin
total.
https://projecteuler.net/show=all
17/163
5/2/2015
Total
9
9
10
10
11
11
12
12
SolutionSet
4,2,35,3,16,1,2
4,3,26,2,15,1,3
2,3,54,5,16,1,3
2,5,36,3,14,1,5
1,4,63,6,25,2,4
1,6,45,4,23,2,6
1,5,62,6,43,4,5
1,6,53,5,42,4,6
Byconcatenatingeachgroupitispossibletoform9digitstringsthemaximumstringfora3gonringis
432621513.
Usingthenumbers1to10,anddependingonarrangements,itispossibletoform16and17digitstrings.
Whatisthemaximum16digitstringfora"magic"5gonring?
Problem69:Totientmaximum
Euler'sTotientfunction,(n)[sometimescalledthephifunction],isusedtodeterminethenumberof
numberslessthannwhicharerelativelyprimeton.Forexample,as1,2,4,5,7,and8,arealllessthan
nineandrelativelyprimetonine,(9)=6.
n RelativelyPrime (n) n/(n)
2 1
3 1,2
1.5
4 1,3
5 1,2,3,4
1.25
6 1,5
7 1,2,3,4,5,6
1.1666...
8 1,3,5,7
9 1,2,4,5,7,8
1.5
10 1,3,7,9
2.5
Itcanbeseenthatn=6producesamaximumn/(n)forn10.
Findthevalueofn1,000,000forwhichn/(n)isamaximum.
Problem70:Totientpermutation
Euler'sTotientfunction,(n)[sometimescalledthephifunction],isusedtodeterminethenumberof
positivenumberslessthanorequaltonwhicharerelativelyprimeton.Forexample,as1,2,4,5,7,and8,
arealllessthannineandrelativelyprimetonine,(9)=6.
Thenumber1isconsideredtoberelativelyprimetoeverypositivenumber,so(1)=1.
Interestingly,(87109)=79180,anditcanbeseenthat87109isapermutationof79180.
Findthevalueofn,1<n<107,forwhich(n)isapermutationofnandtheration/(n)producesa
minimum.
Problem71:Orderedfractions
https://projecteuler.net/show=all
18/163
5/2/2015
Considerthefraction,n/d,wherenanddarepositiveintegers.Ifn<dandHCF(n,d)=1,itiscalledareduced
properfraction.
Ifwelistthesetofreducedproperfractionsford8inascendingorderofsize,weget:
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,5/7,3/4,4/5,5/6,6/7,7/8
Itcanbeseenthat2/5isthefractionimmediatelytotheleftof3/7.
Bylistingthesetofreducedproperfractionsford1,000,000inascendingorderofsize,findthenumerator
ofthefractionimmediatelytotheleftof3/7.
Problem72:Countingfractions
Considerthefraction,n/d,wherenanddarepositiveintegers.Ifn<dandHCF(n,d)=1,itiscalledareduced
properfraction.
Ifwelistthesetofreducedproperfractionsford8inascendingorderofsize,weget:
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,5/7,3/4,4/5,5/6,6/7,7/8
Itcanbeseenthatthereare21elementsinthisset.
Howmanyelementswouldbecontainedinthesetofreducedproperfractionsford1,000,000?
Problem73:Countingfractionsinarange
Considerthefraction,n/d,wherenanddarepositiveintegers.Ifn<dandHCF(n,d)=1,itiscalledareduced
properfraction.
Ifwelistthesetofreducedproperfractionsford8inascendingorderofsize,weget:
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,5/7,3/4,4/5,5/6,6/7,7/8
Itcanbeseenthatthereare3fractionsbetween1/3and1/2.
Howmanyfractionsliebetween1/3and1/2inthesortedsetofreducedproperfractionsford12,000?
Problem74:Digitfactorialchains
Thenumber145iswellknownforthepropertythatthesumofthefactorialofitsdigitsisequalto145:
1!+4!+5!=1+24+120=145
Perhapslesswellknownis169,inthatitproducesthelongestchainofnumbersthatlinkbackto169it
turnsoutthatthereareonlythreesuchloopsthatexist:
1693636011454169
87145361871
87245362872
ItisnotdifficulttoprovethatEVERYstartingnumberwilleventuallygetstuckinaloop.Forexample,
693636001454169363601(1454)
784536087145361(871)
540145(145)
Startingwith69producesachainoffivenonrepeatingterms,butthelongestnonrepeatingchainwitha
startingnumberbelowonemillionissixtyterms.
Howmanychains,withastartingnumberbelowonemillion,containexactlysixtynonrepeatingterms?
Problem75:Singularintegerrighttriangles
Itturnsoutthat12cmisthesmallestlengthofwirethatcanbebenttoformanintegersidedrightangle
triangleinexactlyoneway,buttherearemanymoreexamples.
12cm:(3,4,5)
24cm:(6,8,10)
https://projecteuler.net/show=all
19/163
5/2/2015
30cm:(5,12,13)
36cm:(9,12,15)
40cm:(8,15,17)
48cm:(12,16,20)
Incontrast,somelengthsofwire,like20cm,cannotbebenttoformanintegersidedrightangletriangle,
andotherlengthsallowmorethanonesolutiontobefoundforexample,using120cmitispossibletoform
exactlythreedifferentintegersidedrightangletriangles.
120cm:(30,40,50),(20,48,52),(24,45,51)
GiventhatListhelengthofthewire,forhowmanyvaluesofL1,500,000canexactlyoneintegersided
rightangletrianglebeformed?
Problem76:Countingsummations
Itispossibletowritefiveasasuminexactlysixdifferentways:
4+1
3+2
3+1+1
2+2+1
2+1+1+1
1+1+1+1+1
Howmanydifferentwayscanonehundredbewrittenasasumofatleasttwopositiveintegers?
Problem77:Primesummations
Itispossibletowritetenasthesumofprimesinexactlyfivedifferentways:
7+3
5+5
5+3+2
3+3+2+2
2+2+2+2+2
Whatisthefirstvaluewhichcanbewrittenasthesumofprimesinoverfivethousanddifferentways?
Problem78:Coinpartitions
Letp(n)representthenumberofdifferentwaysinwhichncoinscanbeseparatedintopiles.Forexample,
fivecoinscanbeseparatedintopilesinexactlysevendifferentways,sop(5)=7.
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
OOOOO
Findtheleastvalueofnforwhichp(n)isdivisiblebyonemillion.
Problem79:Passcodederivation
Acommonsecuritymethodusedforonlinebankingistoasktheuserforthreerandomcharactersfroma
passcode.Forexample,ifthepasscodewas531278,theymayaskforthe2nd,3rd,and5thcharactersthe
expectedreplywouldbe:317.
Thetextfile,keylog.txt,containsfiftysuccessfulloginattempts.
https://projecteuler.net/show=all
20/163
5/2/2015
Giventhatthethreecharactersarealwaysaskedforinorder,analysethefilesoastodeterminethe
shortestpossiblesecretpasscodeofunknownlength.
Problem80:Squarerootdigitalexpansion
Itiswellknownthatifthesquarerootofanaturalnumberisnotaninteger,thenitisirrational.Thedecimal
expansionofsuchsquarerootsisinfinitewithoutanyrepeatingpatternatall.
Thesquarerootoftwois1.41421356237309504880...,andthedigitalsumofthefirstonehundreddecimal
digitsis475.
Forthefirstonehundrednaturalnumbers,findthetotalofthedigitalsumsofthefirstonehundreddecimal
digitsforalltheirrationalsquareroots.
Problem81:Pathsum:twoways
Inthe5by5matrixbelow,theminimalpathsumfromthetoplefttothebottomright,byonlymovingtothe
rightanddown,isindicatedinboldredandisequalto2427.
131
201
630
537
805
673
234
103
96
342
965
803
746
422
699
497
121
732
524
37
18
150
111
956
331
Findtheminimalpathsum,inmatrix.txt(rightclickand"SaveLink/TargetAs..."),a31Ktextfilecontaininga
80by80matrix,fromthetoplefttothebottomrightbyonlymovingrightanddown.
Problem82:Pathsum:threeways
NOTE:ThisproblemisamorechallengingversionofProblem81.
Theminimalpathsuminthe5by5matrixbelow,bystartinginanycellintheleftcolumnandfinishingin
anycellintherightcolumn,andonlymovingup,down,andright,isindicatedinredandboldthesumis
equalto994.
131
201
630
537
805
673
234
103
96
342
965
803
746
422
699
497
121
732
524
37
18
150
111
956
331
Findtheminimalpathsum,inmatrix.txt(rightclickand"SaveLink/TargetAs..."),a31Ktextfilecontaininga
80by80matrix,fromtheleftcolumntotherightcolumn.
Problem83:Pathsum:fourways
NOTE:ThisproblemisasignificantlymorechallengingversionofProblem81.
Inthe5by5matrixbelow,theminimalpathsumfromthetoplefttothebottomright,bymovingleft,right,
up,anddown,isindicatedinboldredandisequalto2297.
131
201
630
537
805
673
234
103
96
342
965
803
746
422
699
497
121
732
524
37
18
150
111
956
331
Findtheminimalpathsum,inmatrix.txt(rightclickand"SaveLink/TargetAs..."),a31Ktextfilecontaininga
80by80matrix,fromthetoplefttothebottomrightbymovingleft,right,up,anddown.
https://projecteuler.net/show=all
21/163
5/2/2015
Problem84:Monopolyodds
Inthegame,Monopoly,thestandardboardissetupinthefollowingway:
GO A1 CC1 A2 T1 R1 B1 CH1
B2
B3 JAIL
H2
C1
T2
U1
H1
C2
CH3
C3
R4
R2
G3
D1
CC3
CC2
G2
D2
G1
D3
G2J F3
U2
F2 F1 R3 E3
E2
CH2 E1
FP
AplayerstartsontheGOsquareandaddsthescoresontwo6sideddicetodeterminethenumberof
squarestheyadvanceinaclockwisedirection.Withoutanyfurtherruleswewouldexpecttovisiteach
squarewithequalprobability:2.5%.However,landingonG2J(GoToJail),CC(communitychest),andCH
(chance)changesthisdistribution.
InadditiontoG2J,andonecardfromeachofCCandCH,thatorderstheplayertogodirectlytojail,ifa
playerrollsthreeconsecutivedoubles,theydonotadvancetheresultoftheir3rdroll.Insteadtheyproceed
directlytojail.
Atthebeginningofthegame,theCCandCHcardsareshuffled.WhenaplayerlandsonCCorCHthey
takeacardfromthetopoftherespectivepileand,afterfollowingtheinstructions,itisreturnedtothebottom
ofthepile.Therearesixteencardsineachpile,butforthepurposeofthisproblemweareonlyconcerned
withcardsthatorderamovementanyinstructionnotconcernedwithmovementwillbeignoredandthe
playerwillremainontheCC/CHsquare.
CommunityChest(2/16cards):
1. AdvancetoGO
2. GotoJAIL
Chance(10/16cards):
1. AdvancetoGO
2. GotoJAIL
3. GotoC1
4. GotoE3
5. GotoH2
6. GotoR1
7. GotonextR(railwaycompany)
8. GotonextR
9. GotonextU(utilitycompany)
10. Goback3squares.
Theheartofthisproblemconcernsthelikelihoodofvisitingaparticularsquare.Thatis,theprobabilityof
finishingatthatsquareafteraroll.Forthisreasonitshouldbeclearthat,withtheexceptionofG2Jforwhich
theprobabilityoffinishingonitiszero,theCHsquareswillhavethelowestprobabilities,as5/8requesta
movementtoanothersquare,anditisthefinalsquarethattheplayerfinishesatoneachrollthatweare
interestedin.Weshallmakenodistinctionbetween"JustVisiting"andbeingsenttoJAIL,andweshallalso
ignoretheruleaboutrequiringadoubleto"getoutofjail",assumingthattheypaytogetoutontheirnext
turn.
BystartingatGOandnumberingthesquaressequentiallyfrom00to39wecanconcatenatethesetwodigit
numberstoproducestringsthatcorrespondwithsetsofsquares.
Statisticallyitcanbeshownthatthethreemostpopularsquares,inorder,areJAIL(6.24%)=Square10,E3
(3.18%)=Square24,andGO(3.09%)=Square00.Sothesethreemostpopularsquarescanbelistedwith
thesixdigitmodalstring:102400.
If,insteadofusingtwo6sideddice,two4sideddiceareused,findthesixdigitmodalstring.
Problem85:Countingrectangles
Bycountingcarefullyitcanbeseenthatarectangulargridmeasuring3by2containseighteenrectangles:
https://projecteuler.net/show=all
22/163
5/2/2015
Althoughthereexistsnorectangulargridthatcontainsexactlytwomillionrectangles,findtheareaofthe
gridwiththenearestsolution.
Problem86:Cuboidroute
Aspider,S,sitsinonecornerofacuboidroom,measuring6by5by3,andafly,F,sitsintheopposite
corner.Bytravellingonthesurfacesoftheroomtheshortest"straightline"distancefromStoFis10and
thepathisshownonthediagram.
However,thereareuptothree"shortest"pathcandidatesforanygivencuboidandtheshortestroute
doesn'talwayshaveintegerlength.
Itcanbeshownthatthereareexactly2060distinctcuboids,ignoringrotations,withintegerdimensions,up
toamaximumsizeofMbyMbyM,forwhichtheshortestroutehasintegerlengthwhenM=100.Thisis
theleastvalueofMforwhichthenumberofsolutionsfirstexceedstwothousandthenumberofsolutions
whenM=99is1975.
FindtheleastvalueofMsuchthatthenumberofsolutionsfirstexceedsonemillion.
Problem87:Primepowertriples
Thesmallestnumberexpressibleasthesumofaprimesquare,primecube,andprimefourthpoweris28.
Infact,thereareexactlyfournumbersbelowfiftythatcanbeexpressedinsuchaway:
28=22+23+24
33=32+23+24
49=52+23+24
47=22+33+24
Howmanynumbersbelowfiftymillioncanbeexpressedasthesumofaprimesquare,primecube,and
primefourthpower?
Problem88:Productsumnumbers
Anaturalnumber,N,thatcanbewrittenasthesumandproductofagivensetofatleasttwonatural
numbers,{a1,a2,...,ak}iscalledaproductsumnumber:N=a1+a2+...+ak=a1a2...ak.
Forexample,6=1+2+3=123.
Foragivensetofsize,k,weshallcallthesmallestNwiththispropertyaminimalproductsumnumber.The
minimalproductsumnumbersforsetsofsize,k=2,3,4,5,and6areasfollows.
k=2:4=22=2+2
k=3:6=123=1+2+3
k=4:8=1124=1+1+2+4
k=5:8=11222=1+1+2+2+2
k=6:12=111126=1+1+1+1+2+6
https://projecteuler.net/show=all
23/163
5/2/2015
Hencefor2k6,thesumofalltheminimalproductsumnumbersis4+6+8+12=30notethat8isonly
countedonceinthesum.
Infact,asthecompletesetofminimalproductsumnumbersfor2k12is{4,6,8,12,15,16},thesumis
61.
Whatisthesumofalltheminimalproductsumnumbersfor2k12000?
Problem89:Romannumerals
ForanumberwritteninRomannumeralstobeconsideredvalidtherearebasicruleswhichmustbe
followed.Eventhoughtherulesallowsomenumberstobeexpressedinmorethanonewaythereisalways
a"best"wayofwritingaparticularnumber.
Forexample,itwouldappearthatthereareatleastsixwaysofwritingthenumbersixteen:
IIIIIIIIIIIIIIII
VIIIIIIIIIII
VVIIIIII
XIIIIII
VVVI
XVI
However,accordingtotherulesonlyXIIIIIIandXVIarevalid,andthelastexampleisconsideredtobe
themostefficient,asitusestheleastnumberofnumerals.
The11Ktextfile,roman.txt(rightclickand'SaveLink/TargetAs...'),containsonethousandnumberswritten
invalid,butnotnecessarilyminimal,RomannumeralsseeAbout...RomanNumeralsforthedefinitiverules
forthisproblem.
Findthenumberofcharacterssavedbywritingeachoftheseintheirminimalform.
Note:YoucanassumethatalltheRomannumeralsinthefilecontainnomorethanfourconsecutiveidenticalunits.
Problem90:Cubedigitpairs
Eachofthesixfacesonacubehasadifferentdigit(0to9)writtenonitthesameisdonetoasecondcube.
Byplacingthetwocubessidebysideindifferentpositionswecanformavarietyof2digitnumbers.
Forexample,thesquarenumber64couldbeformed:
Infact,bycarefullychoosingthedigitsonbothcubesitispossibletodisplayallofthesquarenumbers
belowonehundred:01,04,09,16,25,36,49,64,and81.
Forexample,onewaythiscanbeachievedisbyplacing{0,5,6,7,8,9}ononecubeand{1,2,3,4,8,9}
ontheothercube.
However,forthisproblemweshallallowthe6or9tobeturnedupsidedownsothatanarrangementlike{0,
5,6,7,8,9}and{1,2,3,4,6,7}allowsforallninesquarenumberstobedisplayedotherwiseitwouldbe
impossibletoobtain09.
Indeterminingadistinctarrangementweareinterestedinthedigitsoneachcube,nottheorder.
{1,2,3,4,5,6}isequivalentto{3,6,4,1,2,5}
{1,2,3,4,5,6}isdistinctfrom{1,2,3,4,5,9}
Butbecauseweareallowing6and9tobereversed,thetwodistinctsetsinthelastexamplebothrepresent
theextendedset{1,2,3,4,5,6,9}forthepurposeofforming2digitnumbers.
Howmanydistinctarrangementsofthetwocubesallowforallofthesquarenumberstobedisplayed?
Problem91:Righttriangleswithintegercoordinates
ThepointsP(x1,y1)andQ(x2,y2)areplottedatintegercoordinatesandarejoinedtotheorigin,O(0,0),to
https://projecteuler.net/show=all
24/163
5/2/2015
formOPQ.
Thereareexactlyfourteentrianglescontainingarightanglethatcanbeformedwheneachcoordinatelies
between0and2inclusivethatis,
0x1,y1,x2,y22.
Giventhat0x1,y1,x2,y250,howmanyrighttrianglescanbeformed?
Problem92:Squaredigitchains
Anumberchainiscreatedbycontinuouslyaddingthesquareofthedigitsinanumbertoformanew
numberuntilithasbeenseenbefore.
Forexample,
4432131011
85891454220416375889
Thereforeanychainthatarrivesat1or89willbecomestuckinanendlessloop.Whatismostamazingis
thatEVERYstartingnumberwilleventuallyarriveat1or89.
Howmanystartingnumbersbelowtenmillionwillarriveat89?
Problem93:Arithmeticexpressions
Byusingeachofthedigitsfromtheset,{1,2,3,4},exactlyonce,andmakinguseofthefourarithmetic
operations(+,,*,/)andbrackets/parentheses,itispossibletoformdifferentpositiveintegertargets.
Forexample,
8=(4*(1+3))/2
14=4*(3+1/2)
19=4*(2+3)1
36=3*4*(2+1)
Notethatconcatenationsofthedigits,like12+34,arenotallowed.
Usingtheset,{1,2,3,4},itispossibletoobtainthirtyonedifferenttargetnumbersofwhich36isthe
maximum,andeachofthenumbers1to28canbeobtainedbeforeencounteringthefirstnonexpressible
number.
Findthesetoffourdistinctdigits,a<b<c<d,forwhichthelongestsetofconsecutivepositiveintegers,1
ton,canbeobtained,givingyouranswerasastring:abcd.
https://projecteuler.net/show=all
25/163
5/2/2015
Problem94:Almostequilateraltriangles
Itiseasilyprovedthatnoequilateraltriangleexistswithintegrallengthsidesandintegralarea.However,the
almostequilateraltriangle556hasanareaof12squareunits.
Weshalldefineanalmostequilateraltriangletobeatriangleforwhichtwosidesareequalandthethird
differsbynomorethanoneunit.
Findthesumoftheperimetersofallalmostequilateraltriangleswithintegralsidelengthsandareaand
whoseperimetersdonotexceedonebillion(1,000,000,000).
Problem95:Amicablechains
Theproperdivisorsofanumberareallthedivisorsexcludingthenumberitself.Forexample,theproper
divisorsof28are1,2,4,7,and14.Asthesumofthesedivisorsisequalto28,wecallitaperfectnumber.
Interestinglythesumoftheproperdivisorsof220is284andthesumoftheproperdivisorsof284is220,
formingachainoftwonumbers.Forthisreason,220and284arecalledanamicablepair.
Perhapslesswellknownarelongerchains.Forexample,startingwith12496,weformachainoffive
numbers:
1249614288154721453614264(12496...)
Sincethischainreturnstoitsstartingpoint,itiscalledanamicablechain.
Findthesmallestmemberofthelongestamicablechainwithnoelementexceedingonemillion.
Problem96:SuDoku
SuDoku(Japanesemeaningnumberplace)isthenamegiventoapopularpuzzleconcept.Itsoriginis
unclear,butcreditmustbeattributedtoLeonhardEulerwhoinventedasimilar,andmuchmoredifficult,
puzzleideacalledLatinSquares.TheobjectiveofSuDokupuzzles,however,istoreplacetheblanks(or
zeros)ina9by9gridinsuchthateachrow,column,and3by3boxcontainseachofthedigits1to9.
Belowisanexampleofatypicalstartingpuzzlegridanditssolutiongrid.
AwellconstructedSuDokupuzzlehasauniquesolutionandcanbesolvedbylogic,althoughitmaybe
necessarytoemploy"guessandtest"methodsinordertoeliminateoptions(thereismuchcontested
opinionoverthis).Thecomplexityofthesearchdeterminesthedifficultyofthepuzzletheexampleaboveis
consideredeasybecauseitcanbesolvedbystraightforwarddirectdeduction.
The6Ktextfile,sudoku.txt(rightclickand'SaveLink/TargetAs...'),containsfiftydifferentSuDokupuzzles
rangingindifficulty,butallwithuniquesolutions(thefirstpuzzleinthefileistheexampleabove).
Bysolvingallfiftypuzzlesfindthesumofthe3digitnumbersfoundinthetopleftcornerofeachsolution
gridforexample,483isthe3digitnumberfoundinthetopleftcornerofthesolutiongridabove.
Problem97:LargenonMersenneprime
Thefirstknownprimefoundtoexceedonemilliondigitswasdiscoveredin1999,andisaMersenneprime
oftheform269725931itcontainsexactly2,098,960digits.SubsequentlyotherMersenneprimes,ofthe
form2p1,havebeenfoundwhichcontainmoredigits.
However,in2004therewasfoundamassivenonMersenneprimewhichcontains2,357,207digits:
2843327830457+1.
Findthelasttendigitsofthisprimenumber.
https://projecteuler.net/show=all
26/163
5/2/2015
Problem98:Anagramicsquares
ByreplacingeachofthelettersinthewordCAREwith1,2,9,and6respectively,weformasquare
number:1296=362.Whatisremarkableisthat,byusingthesamedigitalsubstitutions,theanagram,
RACE,alsoformsasquarenumber:9216=962.WeshallcallCARE(andRACE)asquareanagramword
pairandspecifyfurtherthatleadingzeroesarenotpermitted,neithermayadifferentletterhavethesame
digitalvalueasanotherletter.
Usingwords.txt(rightclickand'SaveLink/TargetAs...'),a16Ktextfilecontainingnearlytwothousand
commonEnglishwords,findallthesquareanagramwordpairs(apalindromicwordisNOTconsideredto
beananagramofitself).
Whatisthelargestsquarenumberformedbyanymemberofsuchapair?
NOTE:Allanagramsformedmustbecontainedinthegiventextfile.
Problem99:Largestexponential
Comparingtwonumberswritteninindexformlike211and37isnotdifficult,asanycalculatorwouldconfirm
that211=2048<37=2187.
However,confirmingthat632382518061>519432525806wouldbemuchmoredifficult,asbothnumbers
containoverthreemilliondigits.
Usingbase_exp.txt(rightclickand'SaveLink/TargetAs...'),a22Ktextfilecontainingonethousandlines
withabase/exponentpaironeachline,determinewhichlinenumberhasthegreatestnumericalvalue.
NOTE:Thefirsttwolinesinthefilerepresentthenumbersintheexamplegivenabove.
Problem100:Arrangedprobability
Ifaboxcontainstwentyonecoloureddiscs,composedoffifteenbluediscsandsixreddiscs,andtwodiscs
weretakenatrandom,itcanbeseenthattheprobabilityoftakingtwobluediscs,P(BB)=(15/21)(14/20)=
1/2.
Thenextsucharrangement,forwhichthereisexactly50%chanceoftakingtwobluediscsatrandom,isa
boxcontainingeightyfivebluediscsandthirtyfivereddiscs.
Byfindingthefirstarrangementtocontainover1012=1,000,000,000,000discsintotal,determinethe
numberofbluediscsthattheboxwouldcontain.
Problem101:Optimumpolynomial
Ifwearepresentedwiththefirstktermsofasequenceitisimpossibletosaywithcertaintythevalueofthe
nextterm,asthereareinfinitelymanypolynomialfunctionsthatcanmodelthesequence.
Asanexample,letusconsiderthesequenceofcubenumbers.Thisisdefinedbythegeneratingfunction,
un=n3:1,8,27,64,125,216,...
Supposewewereonlygiventhefirsttwotermsofthissequence.Workingontheprinciplethat"simpleis
best"weshouldassumealinearrelationshipandpredictthenexttermtobe15(commondifference7).
Evenifwewerepresentedwiththefirstthreeterms,bythesameprincipleofsimplicity,aquadratic
relationshipshouldbeassumed.
WeshalldefineOP(k,n)tobethenthtermoftheoptimumpolynomialgeneratingfunctionforthefirstk
termsofasequence.ItshouldbeclearthatOP(k,n)willaccuratelygeneratethetermsofthesequencefor
nk,andpotentiallythefirstincorrectterm(FIT)willbeOP(k,k+1)inwhichcaseweshallcallitabadOP
(BOP).
Asabasis,ifwewereonlygiventhefirsttermofsequence,itwouldbemostsensibletoassumeconstancy
thatis,forn2,OP(1,n)=u1.
HenceweobtainthefollowingOPsforthecubicsequence:
OP(1,n)=1
https://projecteuler.net/show=all
1,1,1,1,...
27/163
5/2/2015
OP(2,n)=7n6
1,8,15,...
OP(3,n)=6n211n+6
1,8,27,58,...
OP(4,n)=n3
1,8,27,64,125,...
ClearlynoBOPsexistfork4.
ByconsideringthesumofFITsgeneratedbytheBOPs(indicatedinredabove),weobtain1+15+58=
74.
Considerthefollowingtenthdegreepolynomialgeneratingfunction:
un=1n+n2n3+n4n5+n6n7+n8n9+n10
FindthesumofFITsfortheBOPs.
Problem102:Trianglecontainment
ThreedistinctpointsareplottedatrandomonaCartesianplane,forwhich1000x,y1000,suchthata
triangleisformed.
Considerthefollowingtwotriangles:
A(340,495),B(153,910),C(835,947)
X(175,41),Y(421,714),Z(574,645)
ItcanbeverifiedthattriangleABCcontainstheorigin,whereastriangleXYZdoesnot.
Usingtriangles.txt(rightclickand'SaveLink/TargetAs...'),a27Ktextfilecontainingthecoordinatesofone
thousand"random"triangles,findthenumberoftrianglesforwhichtheinteriorcontainstheorigin.
NOTE:Thefirsttwoexamplesinthefilerepresentthetrianglesintheexamplegivenabove.
Problem103:Specialsubsetsums:optimum
LetS(A)representthesumofelementsinsetAofsizen.Weshallcallitaspecialsumsetifforanytwo
nonemptydisjointsubsets,BandC,thefollowingpropertiesaretrue:
i. S(B)S(C)thatis,sumsofsubsetscannotbeequal.
ii. IfBcontainsmoreelementsthanCthenS(B)>S(C).
IfS(A)isminimisedforagivenn,weshallcallitanoptimumspecialsumset.Thefirstfiveoptimumspecial
sumsetsaregivenbelow.
n=1:{1}
n=2:{1,2}
n=3:{2,3,4}
n=4:{3,5,6,7}
n=5:{6,9,11,12,13}
Itseemsthatforagivenoptimumset,A={a1,a2,...,an},thenextoptimumsetisoftheformB={b,a1+b,
a2+b,...,an+b},wherebisthe"middle"elementonthepreviousrow.
Byapplyingthis"rule"wewouldexpecttheoptimumsetforn=6tobeA={11,17,20,22,23,24},with
S(A)=117.However,thisisnottheoptimumset,aswehavemerelyappliedanalgorithmtoprovideanear
optimumset.Theoptimumsetforn=6isA={11,18,19,20,22,25},withS(A)=115andcorresponding
setstring:111819202225.
GiventhatAisanoptimumspecialsumsetforn=7,finditssetstring.
NOTE:ThisproblemisrelatedtoProblem105andProblem106.
Problem104:PandigitalFibonacciends
TheFibonaccisequenceisdefinedbytherecurrencerelation:
Fn=Fn1+Fn2,whereF1=1andF2=1.
ItturnsoutthatF541,whichcontains113digits,isthefirstFibonaccinumberforwhichthelastninedigits
are19pandigital(containallthedigits1to9,butnotnecessarilyinorder).AndF2749,whichcontains575
https://projecteuler.net/show=all
28/163
5/2/2015
digits,isthefirstFibonaccinumberforwhichthefirstninedigitsare19pandigital.
GiventhatFkisthefirstFibonaccinumberforwhichthefirstninedigitsANDthelastninedigitsare19
pandigital,findk.
Problem105:Specialsubsetsums:testing
LetS(A)representthesumofelementsinsetAofsizen.Weshallcallitaspecialsumsetifforanytwo
nonemptydisjointsubsets,BandC,thefollowingpropertiesaretrue:
i. S(B)S(C)thatis,sumsofsubsetscannotbeequal.
ii. IfBcontainsmoreelementsthanCthenS(B)>S(C).
Forexample,{81,88,75,42,87,84,86,65}isnotaspecialsumsetbecause65+87+88=75+81+84,
whereas{157,150,164,119,79,159,161,139,158}satisfiesbothrulesforallpossiblesubsetpair
combinationsandS(A)=1286.
Usingsets.txt(rightclickand"SaveLink/TargetAs..."),a4Ktextfilewithonehundredsetscontainingseven
totwelveelements(thetwoexamplesgivenabovearethefirsttwosetsinthefile),identifyallthespecial
sumsets,A1,A2,...,Ak,andfindthevalueofS(A1)+S(A2)+...+S(Ak).
NOTE:ThisproblemisrelatedtoProblem103andProblem106.
Problem106:Specialsubsetsums:metatesting
LetS(A)representthesumofelementsinsetAofsizen.Weshallcallitaspecialsumsetifforanytwo
nonemptydisjointsubsets,BandC,thefollowingpropertiesaretrue:
i. S(B)S(C)thatis,sumsofsubsetscannotbeequal.
ii. IfBcontainsmoreelementsthanCthenS(B)>S(C).
Forthisproblemweshallassumethatagivensetcontainsnstrictlyincreasingelementsanditalready
satisfiesthesecondrule.
Surprisingly,outofthe25possiblesubsetpairsthatcanbeobtainedfromasetforwhichn=4,only1of
thesepairsneedtobetestedforequality(firstrule).Similarly,whenn=7,only70outofthe966subset
pairsneedtobetested.
Forn=12,howmanyofthe261625subsetpairsthatcanbeobtainedneedtobetestedforequality?
NOTE:ThisproblemisrelatedtoProblem103andProblem105.
Problem107:Minimalnetwork
Thefollowingundirectednetworkconsistsofsevenverticesandtwelveedgeswithatotalweightof243.
Thesamenetworkcanberepresentedbythematrixbelow.
https://projecteuler.net/show=all
16 12 21
16
17 20
12
28
21 17 28
31
18 19 23
29/163
5/2/2015
20
18
11
31 19
27
23 11 27
However,itispossibletooptimisethenetworkbyremovingsomeedgesandstillensurethatallpointson
thenetworkremainconnected.Thenetworkwhichachievesthemaximumsavingisshownbelow.Ithasa
weightof93,representingasavingof24393=150fromtheoriginalnetwork.
Usingnetwork.txt(rightclickand'SaveLink/TargetAs...'),a6Ktextfilecontaininganetworkwithforty
vertices,andgiveninmatrixform,findthemaximumsavingwhichcanbeachievedbyremovingredundant
edgeswhilstensuringthatthenetworkremainsconnected.
Problem108:DiophantinereciprocalsI
Inthefollowingequationx,y,andnarepositiveintegers.
1
x y n
Forn=4thereareexactlythreedistinctsolutions:
1 1 1
+
=
5 20 4
1 1 1
+
=
6 12 4
1 1 1
+
=
8 8 4
Whatistheleastvalueofnforwhichthenumberofdistinctsolutionsexceedsonethousand?
NOTE:ThisproblemisaneasierversionofProblem110itisstronglyadvisedthatyousolvethisonefirst.
Problem109:Darts
Inthegameofdartsaplayerthrowsthreedartsatatargetboardwhichissplitintotwentyequalsized
sectionsnumberedonetotwenty.
https://projecteuler.net/show=all
30/163
5/2/2015
Thescoreofadartisdeterminedbythenumberoftheregionthatthedartlandsin.Adartlandingoutside
thered/greenouterringscoreszero.Theblackandcreamregionsinsidethisringrepresentsinglescores.
However,thered/greenouterringandmiddleringscoredoubleandtreblescoresrespectively.
Atthecentreoftheboardaretwoconcentriccirclescalledthebullregion,orbullseye.Theouterbullis
worth25pointsandtheinnerbullisadouble,worth50points.
Therearemanyvariationsofrulesbutinthemostpopulargametheplayerswillbeginwithascore301or
501andthefirstplayertoreducetheirrunningtotaltozeroisawinner.However,itisnormaltoplaya
"doublesout"system,whichmeansthattheplayermustlandadouble(includingthedoublebullseyeatthe
centreoftheboard)ontheirfinaldarttowinanyotherdartthatwouldreducetheirrunningtotaltooneor
lowermeansthescoreforthatsetofthreedartsis"bust".
Whenaplayerisabletofinishontheircurrentscoreitiscalleda"checkout"andthehighestcheckoutis
170:T20T20D25(twotreble20sanddoublebull).
Thereareexactlyelevendistinctwaystocheckoutonascoreof6:
D3
D1
D2
S2
D2
D2
D1
S4
D1
S1
S1
D2
S1
T1
D1
S1
S3
D1
D1
D1
D1
D1
S2
D1
S2
S2
D1
NotethatD1D2isconsidereddifferenttoD2D1astheyfinishondifferentdoubles.However,the
combinationS1T1D1isconsideredthesameasT1S1D1.
Inadditionweshallnotincludemissesinconsideringcombinationsforexample,D3isthesameas0D3
and00D3.
Incrediblythereare42336distinctwaysofcheckingoutintotal.
Howmanydistinctwayscanaplayercheckoutwithascorelessthan100?
Problem110:DiophantinereciprocalsII
Inthefollowingequationx,y,andnarepositiveintegers.
1
x y n
https://projecteuler.net/show=all
31/163
5/2/2015
Itcanbeverifiedthatwhenn=1260thereare113distinctsolutionsandthisistheleastvalueofnforwhich
thetotalnumberofdistinctsolutionsexceedsonehundred.
Whatistheleastvalueofnforwhichthenumberofdistinctsolutionsexceedsfourmillion?
NOTE:ThisproblemisamuchmoredifficultversionofProblem108andasitiswellbeyondthelimitationsofabrute
forceapproachitrequiresacleverimplementation.
Problem111:Primeswithruns
Considering4digitprimescontainingrepeateddigitsitisclearthattheycannotallbethesame:1111is
divisibleby11,2222isdivisibleby22,andsoon.Buttherearenine4digitprimescontainingthreeones:
1117,1151,1171,1181,1511,1811,2111,4111,8111
WeshallsaythatM(n,d)representsthemaximumnumberofrepeateddigitsforanndigitprimewheredis
therepeateddigit,N(n,d)representsthenumberofsuchprimes,andS(n,d)representsthesumofthese
primes.
SoM(4,1)=3isthemaximumnumberofrepeateddigitsfora4digitprimewhereoneistherepeateddigit,
thereareN(4,1)=9suchprimes,andthesumoftheseprimesisS(4,1)=22275.Itturnsoutthatford=0,
itisonlypossibletohaveM(4,0)=2repeateddigits,butthereareN(4,0)=13suchcases.
Inthesamewayweobtainthefollowingresultsfor4digitprimes.
Digit,d M(4,d) N(4,d) S(4,d)
0
13
67061
22275
2221
12
46214
8888
5557
6661
57863
8887
48073
Ford=0to9,thesumofallS(4,d)is273700.
FindthesumofallS(10,d).
Problem112:Bouncynumbers
Workingfromlefttorightifnodigitisexceededbythedigittoitsleftitiscalledanincreasingnumberfor
example,134468.
Similarlyifnodigitisexceededbythedigittoitsrightitiscalledadecreasingnumberforexample,66420.
Weshallcallapositiveintegerthatisneitherincreasingnordecreasinga"bouncy"numberforexample,
155349.
Clearlytherecannotbeanybouncynumbersbelowonehundred,butjustoverhalfofthenumbersbelow
onethousand(525)arebouncy.Infact,theleastnumberforwhichtheproportionofbouncynumbersfirst
reaches50%is538.
Surprisingly,bouncynumbersbecomemoreandmorecommonandbythetimewereach21780the
proportionofbouncynumbersisequalto90%.
Findtheleastnumberforwhichtheproportionofbouncynumbersisexactly99%.
Problem113:Nonbouncynumbers
Workingfromlefttorightifnodigitisexceededbythedigittoitsleftitiscalledanincreasingnumberfor
example,134468.
https://projecteuler.net/show=all
32/163
5/2/2015
Similarlyifnodigitisexceededbythedigittoitsrightitiscalledadecreasingnumberforexample,66420.
Weshallcallapositiveintegerthatisneitherincreasingnordecreasinga"bouncy"numberforexample,
155349.
Asnincreases,theproportionofbouncynumbersbelownincreasessuchthatthereareonly12951
numbersbelowonemillionthatarenotbouncyandonly277032nonbouncynumbersbelow1010.
Howmanynumbersbelowagoogol(10100)arenotbouncy?
Problem114:CountingblockcombinationsI
Arowmeasuringsevenunitsinlengthhasredblockswithaminimumlengthofthreeunitsplacedonit,
suchthatanytworedblocks(whichareallowedtobedifferentlengths)areseparatedbyatleastoneblack
square.Thereareexactlyseventeenwaysofdoingthis.
Howmanywayscanarowmeasuringfiftyunitsinlengthbefilled?
NOTE:Althoughtheexampleabovedoesnotlenditselftothepossibility,ingeneralitispermittedtomixblocksizes.
Forexample,onarowmeasuringeightunitsinlengthyoucouldusered(3),black(1),andred(4).
Problem115:CountingblockcombinationsII
NOTE:ThisisamoredifficultversionofProblem114.
Arowmeasuringnunitsinlengthhasredblockswithaminimumlengthofmunitsplacedonit,suchthat
anytworedblocks(whichareallowedtobedifferentlengths)areseparatedbyatleastoneblacksquare.
Letthefillcountfunction,F(m,n),representthenumberofwaysthatarowcanbefilled.
Forexample,F(3,29)=673135andF(3,30)=1089155.
Thatis,form=3,itcanbeseenthatn=30isthesmallestvalueforwhichthefillcountfunctionfirst
exceedsonemillion.
Inthesameway,form=10,itcanbeverifiedthatF(10,56)=880711andF(10,57)=1148904,son=57
istheleastvalueforwhichthefillcountfunctionfirstexceedsonemillion.
Form=50,findtheleastvalueofnforwhichthefillcountfunctionfirstexceedsonemillion.
Problem116:Red,greenorbluetiles
Arowoffiveblacksquaretilesistohaveanumberofitstilesreplacedwithcolouredoblongtileschosen
fromred(lengthtwo),green(lengththree),orblue(lengthfour).
Ifredtilesarechosenthereareexactlysevenwaysthiscanbedone.
Ifgreentilesarechosentherearethreeways.
https://projecteuler.net/show=all
33/163
5/2/2015
Andifbluetilesarechosentherearetwoways.
Assumingthatcolourscannotbemixedthereare7+3+2=12waysofreplacingtheblacktilesinarow
measuringfiveunitsinlength.
Howmanydifferentwayscantheblacktilesinarowmeasuringfiftyunitsinlengthbereplacedifcolours
cannotbemixedandatleastonecolouredtilemustbeused?
NOTE:ThisisrelatedtoProblem117.
Problem117:Red,green,andbluetiles
Usingacombinationofblacksquaretilesandoblongtileschosenfrom:redtilesmeasuringtwounits,green
tilesmeasuringthreeunits,andbluetilesmeasuringfourunits,itispossibletotilearowmeasuringfive
unitsinlengthinexactlyfifteendifferentways.
Howmanywayscanarowmeasuringfiftyunitsinlengthbetiled?
NOTE:ThisisrelatedtoProblem116.
Problem118:Pandigitalprimesets
Usingallofthedigits1through9andconcatenatingthemfreelytoformdecimalintegers,differentsetscan
beformed.Interestinglywiththeset{2,5,47,89,631},alloftheelementsbelongingtoitareprime.
Howmanydistinctsetscontainingeachofthedigitsonethroughnineexactlyoncecontainonlyprime
elements?
Problem119:Digitpowersum
Thenumber512isinterestingbecauseitisequaltothesumofitsdigitsraisedtosomepower:5+1+2=
8,and83=512.Anotherexampleofanumberwiththispropertyis614656=284.
Weshalldefineantobethenthtermofthissequenceandinsistthatanumbermustcontainatleasttwo
digitstohaveasum.
Youaregiventhata2=512anda10=614656.
Finda30.
Problem120:Squareremainders
Letrbetheremainderwhen(a1)n+(a+1)nisdividedbya2.
Forexample,ifa=7andn=3,thenr=42:63+83=72842mod49.Andasnvaries,sotoowillr,butfor
a=7itturnsoutthatrmax=42.
For3a1000,findrmax.
Problem121:Discgameprizefund
https://projecteuler.net/show=all
34/163
5/2/2015
Abagcontainsonereddiscandonebluedisc.Inagameofchanceaplayertakesadiscatrandomandits
colourisnoted.Aftereachturnthediscisreturnedtothebag,anextrareddiscisadded,andanotherdisc
istakenatrandom.
Theplayerpays1toplayandwinsiftheyhavetakenmorebluediscsthanreddiscsattheendofthe
game.
Ifthegameisplayedforfourturns,theprobabilityofaplayerwinningisexactly11/120,andsothe
maximumprizefundthebankershouldallocateforwinninginthisgamewouldbe10beforetheywould
expecttoincuraloss.Notethatanypayoutwillbeawholenumberofpoundsandalsoincludestheoriginal
1paidtoplaythegame,sointheexamplegiventheplayeractuallywins9.
Findthemaximumprizefundthatshouldbeallocatedtoasinglegameinwhichfifteenturnsareplayed.
Problem122:Efficientexponentiation
Themostnaivewayofcomputingn15requiresfourteenmultiplications:
nn...n=n15
Butusinga"binary"methodyoucancomputeitinsixmultiplications:
nn=n2
n2n2=n4
n4n4=n8
n8n4=n12
n12n2=n14
n14n=n15
Howeveritisyetpossibletocomputeitinonlyfivemultiplications:
nn=n2
n2n=n3
n3n3=n6
n6n6=n12
n12n3=n15
Weshalldefinem(k)tobetheminimumnumberofmultiplicationstocomputenkforexamplem(15)=5.
For1k200,findm(k).
Problem123:Primesquareremainders
Letpnbethenthprime:2,3,5,7,11,...,andletrbetheremainderwhen(pn1)n+(pn+1)nisdividedby
pn2.
Forexample,whenn=3,p3=5,and43+63=2805mod25.
Theleastvalueofnforwhichtheremainderfirstexceeds109is7037.
Findtheleastvalueofnforwhichtheremainderfirstexceeds1010.
Problem124:Orderedradicals
Theradicalofn,rad(n),istheproductofthedistinctprimefactorsofn.Forexample,504=23327,so
rad(504)=237=42.
Ifwecalculaterad(n)for1n10,thensortthemonrad(n),andsortingonniftheradicalvaluesare
equal,weget:
Unsorted
n
1
2
3
https://projecteuler.net/show=all
rad(n)
1
Sorted
n
1
2
4
rad(n)
1
2
2
k
1
2
3
35/163
5/2/2015
4
5
6
7
8
9
10
2
5
6
7
2
3
10
8
3
9
5
6
7
10
2
3
3
5
6
7
10
4
5
6
7
8
9
10
LetE(k)bethekthelementinthesortedncolumnforexample,E(4)=8andE(6)=9.
Ifrad(n)issortedfor1n100000,findE(10000).
Problem125:Palindromicsums
Thepalindromicnumber595isinterestingbecauseitcanbewrittenasthesumofconsecutivesquares:62
+72+82+92+102+112+122.
Thereareexactlyelevenpalindromesbelowonethousandthatcanbewrittenasconsecutivesquaresums,
andthesumofthesepalindromesis4164.Notethat1=02+12hasnotbeenincludedasthisproblemis
concernedwiththesquaresofpositiveintegers.
Findthesumofallthenumberslessthan108thatarebothpalindromicandcanbewrittenasthesumof
consecutivesquares.
Problem126:Cuboidlayers
Theminimumnumberofcubestocovereveryvisiblefaceonacuboidmeasuring3x2x1istwentytwo.
Ifwethenaddasecondlayertothissoliditwouldrequirefortysixcubestocovereveryvisibleface,the
thirdlayerwouldrequireseventyeightcubes,andthefourthlayerwouldrequireonehundredandeighteen
cubestocovereveryvisibleface.
However,thefirstlayeronacuboidmeasuring5x1x1alsorequirestwentytwocubessimilarlythefirst
layeroncuboidsmeasuring5x3x1,7x2x1,and11x1x1allcontainfortysixcubes.
WeshalldefineC(n)torepresentthenumberofcuboidsthatcontainncubesinoneofitslayers.SoC(22)=
2,C(46)=4,C(78)=5,andC(118)=8.
Itturnsoutthat154istheleastvalueofnforwhichC(n)=10.
FindtheleastvalueofnforwhichC(n)=1000.
Problem127:abchits
Theradicalofn,rad(n),istheproductofdistinctprimefactorsofn.Forexample,504=23327,so
rad(504)=237=42.
Weshalldefinethetripletofpositiveintegers(a,b,c)tobeanabchitif:
1.
2.
3.
4.
GCD(a,b)=GCD(a,c)=GCD(b,c)=1
a<b
a+b=c
rad(abc)<c
Forexample,(5,27,32)isanabchit,because:
https://projecteuler.net/show=all
36/163
5/2/2015
1.
2.
3.
4.
GCD(5,27)=GCD(5,32)=GCD(27,32)=1
5<27
5+27=32
rad(4320)=30<32
Itturnsoutthatabchitsarequiterareandthereareonlythirtyoneabchitsforc<1000,withc=12523.
Findcforc<120000.
Problem128:Hexagonaltiledifferences
Ahexagonaltilewithnumber1issurroundedbyaringofsixhexagonaltiles,startingat"12o'clock"and
numberingthetiles2to7inananticlockwisedirection.
Newringsareaddedinthesamefashion,withthenextringsbeingnumbered8to19,20to37,38to61,
andsoon.Thediagrambelowshowsthefirstthreerings.
ByfindingthedifferencebetweentilenandeachofitssixneighboursweshalldefinePD(n)tobethe
numberofthosedifferenceswhichareprime.
Forexample,workingclockwisearoundtile8thedifferencesare12,29,11,6,1,and13.SoPD(8)=3.
Inthesameway,thedifferencesaroundtile17are1,17,16,1,11,and10,hencePD(17)=2.
ItcanbeshownthatthemaximumvalueofPD(n)is3.
IfallofthetilesforwhichPD(n)=3arelistedinascendingordertoformasequence,the10thtilewouldbe
271.
Findthe2000thtileinthissequence.
Problem129:Repunitdivisibility
Anumberconsistingentirelyofonesiscalledarepunit.WeshalldefineR(k)tobearepunitoflengthkfor
example,R(6)=111111.
GiventhatnisapositiveintegerandGCD(n,10)=1,itcanbeshownthattherealwaysexistsavalue,k,for
whichR(k)isdivisiblebyn,andletA(n)betheleastsuchvalueofkforexample,A(7)=6andA(41)=5.
TheleastvalueofnforwhichA(n)firstexceedstenis17.
FindtheleastvalueofnforwhichA(n)firstexceedsonemillion.
Problem130:Compositeswithprimerepunitproperty
Anumberconsistingentirelyofonesiscalledarepunit.WeshalldefineR(k)tobearepunitoflengthkfor
example,R(6)=111111.
https://projecteuler.net/show=all
37/163
5/2/2015
GiventhatnisapositiveintegerandGCD(n,10)=1,itcanbeshownthattherealwaysexistsavalue,k,for
whichR(k)isdivisiblebyn,andletA(n)betheleastsuchvalueofkforexample,A(7)=6andA(41)=5.
Youaregiventhatforallprimes,p>5,thatp1isdivisiblebyA(p).Forexample,whenp=41,A(41)=5,
and40isdivisibleby5.
However,therearerarecompositevaluesforwhichthisisalsotruethefirstfiveexamplesbeing91,259,
451,481,and703.
Findthesumofthefirsttwentyfivecompositevaluesofnforwhich
GCD(n,10)=1andn1isdivisiblebyA(n).
Problem131:Primecubepartnership
Therearesomeprimevalues,p,forwhichthereexistsapositiveinteger,n,suchthattheexpressionn3+
n2pisaperfectcube.
Forexample,whenp=19,83+8219=123.
Whatisperhapsmostsurprisingisthatforeachprimewiththispropertythevalueofnisunique,andthere
areonlyfoursuchprimesbelowonehundred.
Howmanyprimesbelowonemillionhavethisremarkableproperty?
Problem132:Largerepunitfactors
Anumberconsistingentirelyofonesiscalledarepunit.WeshalldefineR(k)tobearepunitoflengthk.
Forexample,R(10)=1111111111=11412719091,andthesumoftheseprimefactorsis9414.
FindthesumofthefirstfortyprimefactorsofR(109).
Problem133:Repunitnonfactors
Anumberconsistingentirelyofonesiscalledarepunit.WeshalldefineR(k)tobearepunitoflengthkfor
example,R(6)=111111.
LetusconsiderrepunitsoftheformR(10n).
AlthoughR(10),R(100),orR(1000)arenotdivisibleby17,R(10000)isdivisibleby17.Yetthereisnovalue
ofnforwhichR(10n)willdivideby19.Infact,itisremarkablethat11,17,41,and73aretheonlyfour
primesbelowonehundredthatcanbeafactorofR(10n).
FindthesumofalltheprimesbelowonehundredthousandthatwillneverbeafactorofR(10n).
Problem134:Primepairconnection
Considertheconsecutiveprimesp1=19andp2=23.Itcanbeverifiedthat1219isthesmallestnumber
suchthatthelastdigitsareformedbyp1whilstalsobeingdivisiblebyp2.
Infact,withtheexceptionofp1=3andp2=5,foreverypairofconsecutiveprimes,p2>p1,thereexist
valuesofnforwhichthelastdigitsareformedbyp1andnisdivisiblebyp2.LetSbethesmallestofthese
valuesofn.
FindSforeverypairofconsecutiveprimeswith5p11000000.
Problem135:Samedifferences
Giventhepositiveintegers,x,y,andz,areconsecutivetermsofanarithmeticprogression,theleastvalue
ofthepositiveinteger,n,forwhichtheequation,x2y2z2=n,hasexactlytwosolutionsisn=27:
342272202=1229262=27
https://projecteuler.net/show=all
38/163
5/2/2015
Itturnsoutthatn=1155istheleastvaluewhichhasexactlytensolutions.
Howmanyvaluesofnlessthanonemillionhaveexactlytendistinctsolutions?
Problem136:Singletondifference
Thepositiveintegers,x,y,andz,areconsecutivetermsofanarithmeticprogression.Giventhatnisa
positiveinteger,theequation,x2y2z2=n,hasexactlyonesolutionwhenn=20:
13210272=20
Infacttherearetwentyfivevaluesofnbelowonehundredforwhichtheequationhasauniquesolution.
Howmanyvaluesofnlessthanfiftymillionhaveexactlyonesolution?
Problem137:Fibonaccigoldennuggets
ConsidertheinfinitepolynomialseriesAF(x)=xF1+x2F2+x3F3+...,whereFkisthekthterminthe
Fibonaccisequence:1,1,2,3,5,8,...thatis,Fk=Fk1+Fk2,F1=1andF2=1.
ForthisproblemweshallbeinterestedinvaluesofxforwhichAF(x)isapositiveinteger.
SurprisinglyAF(1/2) = (1/2).1+(1/2)2.1+(1/2)3.2+(1/2)4.3+(1/2)5.5+...
=1/2+1/4+2/8+3/16+5/32+...
=2
Thecorrespondingvaluesofxforthefirstfivenaturalnumbersareshownbelow.
x
AF(x)
21
1/2
(132)/3
(895)/8
(343)/5
WeshallcallAF(x)agoldennuggetifxisrational,becausetheybecomeincreasinglyrarerforexample,the
10thgoldennuggetis74049690.
Findthe15thgoldennugget.
Problem138:Specialisoscelestriangles
Considertheisoscelestrianglewithbaselength,b=16,andlegs,L=17.
ByusingthePythagoreantheoremitcanbeseenthattheheightofthetriangle,h=(17282)=15,which
isonelessthanthebaselength.
Withb=272andL=305,wegeth=273,whichisonemorethanthebaselength,andthisisthesecond
smallestisoscelestrianglewiththepropertythath=b1.
FindLforthetwelvesmallestisoscelestrianglesforwhichh=b1andb,Larepositiveintegers.
https://projecteuler.net/show=all
39/163
5/2/2015
Problem139:Pythagoreantiles
Let(a,b,c)representthethreesidesofarightangletrianglewithintegrallengthsides.Itispossibleto
placefoursuchtrianglestogethertoformasquarewithlengthc.
Forexample,(3,4,5)trianglescanbeplacedtogethertoforma5by5squarewitha1by1holeinthe
middleanditcanbeseenthatthe5by5squarecanbetiledwithtwentyfive1by1squares.
However,if(5,12,13)triangleswereusedthentheholewouldmeasure7by7andthesecouldnotbeused
totilethe13by13square.
Giventhattheperimeteroftherighttriangleislessthanonehundredmillion,howmanyPythagorean
triangleswouldallowsuchatilingtotakeplace?
Problem140:ModifiedFibonaccigoldennuggets
ConsidertheinfinitepolynomialseriesAG(x)=xG1+x2G2+x3G3+...,whereGkisthekthtermofthe
secondorderrecurrencerelationGk=Gk1+Gk2,G1=1andG2=4thatis,1,4,5,9,14,23,....
ForthisproblemweshallbeconcernedwithvaluesofxforwhichAG(x)isapositiveinteger.
Thecorrespondingvaluesofxforthefirstfivenaturalnumbersareshownbelow.
x
AG(x)
(51)/4
2/5
(222)/6
(1375)/14
1/2
WeshallcallAG(x)agoldennuggetifxisrational,becausetheybecomeincreasinglyrarerforexample,
the20thgoldennuggetis211345365.
Findthesumofthefirstthirtygoldennuggets.
Problem141:Investigatingprogressivenumbers,n,whicharealsosquare
Apositiveinteger,n,isdividedbydandthequotientandremainderareqandrrespectively.Inadditiond,
q,andrareconsecutivepositiveintegertermsinageometricsequence,butnotnecessarilyinthatorder.
Forexample,58dividedby6hasquotient9andremainder4.Itcanalsobeseenthat4,6,9are
consecutivetermsinageometricsequence(commonratio3/2).
Wewillcallsuchnumbers,n,progressive.
Someprogressivenumbers,suchas9and10404=1022,happentoalsobeperfectsquares.
Thesumofallprogressiveperfectsquaresbelowonehundredthousandis124657.
Findthesumofallprogressiveperfectsquaresbelowonetrillion(1012).
Problem142:PerfectSquareCollection
Findthesmallestx+y+zwithintegersx>y>z>0suchthatx+y,xy,x+z,xz,y+z,yzareall
perfectsquares.
Problem143:InvestigatingtheTorricellipointofatriangle
https://projecteuler.net/show=all
40/163
5/2/2015
LetABCbeatrianglewithallinterioranglesbeinglessthan120degrees.LetXbeanypointinsidethe
triangleandletXA=p,XC=q,andXB=r.
FermatchallengedTorricellitofindthepositionofXsuchthatp+q+rwasminimised.
TorricelliwasabletoprovethatifequilateraltrianglesAOB,BNCandAMCareconstructedoneachsideof
triangleABC,thecircumscribedcirclesofAOB,BNC,andAMCwillintersectatasinglepoint,T,insidethe
triangle.MoreoverheprovedthatT,calledtheTorricelli/Fermatpoint,minimisesp+q+r.Evenmore
remarkable,itcanbeshownthatwhenthesumisminimised,AN=BM=CO=p+q+randthatAN,BM
andCOalsointersectatT.
Ifthesumisminimisedanda,b,c,p,qandrareallpositiveintegersweshallcalltriangleABCaTorricelli
triangle.Forexample,a=399,b=455,c=511isanexampleofaTorricellitriangle,withp+q+r=784.
Findthesumofalldistinctvaluesofp+q+r120000forTorricellitriangles.
Problem144:Investigatingmultiplereflectionsofalaserbeam
Inlaserphysics,a"whitecell"isamirrorsystemthatactsasadelaylineforthelaserbeam.Thebeam
entersthecell,bouncesaroundonthemirrors,andeventuallyworksitswaybackout.
Thespecificwhitecellwewillbeconsideringisanellipsewiththeequation4x2+y2=100
Thesectioncorrespondingto0.01x+0.01atthetopismissing,allowingthelighttoenterandexit
throughthehole.
https://projecteuler.net/show=all
41/163
5/2/2015
Thelightbeaminthisproblemstartsatthepoint(0.0,10.1)justoutsidethewhitecell,andthebeamfirst
impactsthemirrorat(1.4,9.6).
Eachtimethelaserbeamhitsthesurfaceoftheellipse,itfollowstheusuallawofreflection"angleof
incidenceequalsangleofreflection."Thatis,boththeincidentandreflectedbeamsmakethesameangle
withthenormallineatthepointofincidence.
Inthefigureontheleft,theredlineshowsthefirsttwopointsofcontactbetweenthelaserbeamandthe
wallofthewhitecellthebluelineshowsthelinetangenttotheellipseatthepointofincidenceofthefirst
bounce.
Theslopemofthetangentlineatanypoint(x,y)ofthegivenellipseis:m=4x/y
Thenormallineisperpendiculartothistangentlineatthepointofincidence.
Theanimationontherightshowsthefirst10reflectionsofthebeam.
Howmanytimesdoesthebeamhittheinternalsurfaceofthewhitecellbeforeexiting?
Problem145:Howmanyreversiblenumbersaretherebelowonebillion?
Somepositiveintegersnhavethepropertythatthesum[n+reverse(n)]consistsentirelyofodd(decimal)
digits.Forinstance,36+63=99and409+904=1313.Wewillcallsuchnumbersreversibleso36,63,
409,and904arereversible.Leadingzeroesarenotallowedineithernorreverse(n).
Thereare120reversiblenumbersbelowonethousand.
Howmanyreversiblenumbersaretherebelowonebillion(109)?
Problem146:InvestigatingaPrimePattern
Thesmallestpositiveintegernforwhichthenumbersn2+1,n2+3,n2+7,n2+9,n2+13,andn2+27are
consecutiveprimesis10.Thesumofallsuchintegersnbelowonemillionis1242490.
Whatisthesumofallsuchintegersnbelow150million?
Problem147:Rectanglesincrosshatchedgrids
Ina3x2crosshatchedgrid,atotalof37differentrectanglescouldbesituatedwithinthatgridasindicatedin
thesketch.
Thereare5gridssmallerthan3x2,verticalandhorizontaldimensionsbeingimportant,i.e.1x1,2x1,3x1,
1x2and2x2.Ifeachofthemiscrosshatched,thefollowingnumberofdifferentrectanglescouldbesituated
withinthosesmallergrids:
1x1:1
2x1:4
3x1:8
1x2:4
2x2:18
Addingthosetothe37ofthe3x2grid,atotalof72differentrectanglescouldbesituatedwithin3x2and
smallergrids.
Howmanydifferentrectanglescouldbesituatedwithin47x43andsmallergrids?
Problem148:ExploringPascal'striangle
https://projecteuler.net/show=all
42/163
5/2/2015
WecaneasilyverifythatnoneoftheentriesinthefirstsevenrowsofPascal'strianglearedivisibleby7:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
However,ifwecheckthefirstonehundredrows,wewillfindthatonly2361ofthe5050entriesarenot
divisibleby7.
Findthenumberofentrieswhicharenotdivisibleby7inthefirstonebillion(109)rowsofPascal'striangle.
Problem149:Searchingforamaximumsumsubsequence
Lookingatthetablebelow,itiseasytoverifythatthemaximumpossiblesumofadjacentnumbersinany
direction(horizontal,vertical,diagonalorantidiagonal)is16(=8+7+1).
2
9 6
8 4 8
Now,letusrepeatthesearch,butonamuchlargerscale:
First,generatefourmillionpseudorandomnumbersusingaspecificformofwhatisknownasa"Lagged
FibonacciGenerator":
For1k55,sk=[100003200003k+300007k3](modulo1000000)500000.
For56k4000000,sk=[sk24+sk55+1000000](modulo1000000)500000.
Thus,s10=393027ands100=86613.
Thetermsofsarethenarrangedina20002000table,usingthefirst2000numberstofillthefirstrow
(sequentially),thenext2000numberstofillthesecondrow,andsoon.
Finally,findthegreatestsumof(anynumberof)adjacententriesinanydirection(horizontal,vertical,
diagonalorantidiagonal).
Problem150:Searchingatriangulararrayforasubtrianglehavingminimum
sum
Inatriangulararrayofpositiveandnegativeintegers,wewishtofindasubtrianglesuchthatthesumofthe
numbersitcontainsisthesmallestpossible.
Intheexamplebelow,itcanbeeasilyverifiedthatthemarkedtrianglesatisfiesthisconditionhavingasum
of42.
Wewishtomakesuchatriangulararraywithonethousandrows,sowegenerate500500pseudorandom
numbersskintherange219,usingatypeofrandomnumbergenerator(knownasaLinearCongruential
Generator)asfollows:
t:=0
fork=1uptok=500500:
t:=(615949*t+797807)modulo220
https://projecteuler.net/show=all
43/163
5/2/2015
sk:=t219
Thus:s1=273519,s2=153582,s3=450905etc
Ourtriangulararrayisthenformedusingthepseudorandomnumbersthus:
s1
s2s3
s4s5s6
s7s8s9s10
...
Subtrianglescanstartatanyelementofthearrayandextenddownasfaraswelike(takinginthetwo
elementsdirectlybelowitfromthenextrow,thethreeelementsdirectlybelowfromtherowafterthat,and
soon).
The"sumofasubtriangle"isdefinedasthesumofalltheelementsitcontains.
Findthesmallestpossiblesubtrianglesum.
Problem151:Papersheetsofstandardsizes:anexpectedvalueproblem
Aprintingshopruns16batches(jobs)everyweekandeachbatchrequiresasheetofspecialcolour
proofingpaperofsizeA5.
EveryMondaymorning,theforemanopensanewenvelope,containingalargesheetofthespecialpaper
withsizeA1.
Heproceedstocutitinhalf,thusgettingtwosheetsofsizeA2.Thenhecutsoneoftheminhalftogettwo
sheetsofsizeA3andsoonuntilheobtainstheA5sizesheetneededforthefirstbatchoftheweek.
Alltheunusedsheetsareplacedbackintheenvelope.
Atthebeginningofeachsubsequentbatch,hetakesfromtheenvelopeonesheetofpaperatrandom.Ifitis
ofsizeA5,heusesit.Ifitislarger,herepeatsthe'cutinhalf'procedureuntilhehaswhatheneedsandany
remainingsheetsarealwaysplacedbackintheenvelope.
Excludingthefirstandlastbatchoftheweek,findtheexpectednumberoftimes(duringeachweek)thatthe
foremanfindsasinglesheetofpaperintheenvelope.
Giveyouranswerroundedtosixdecimalplacesusingtheformatx.xxxxxx.
Problem152:Writing1/2asasumofinversesquares
Thereareseveralwaystowritethenumber1/2asasumofinversesquaresusingdistinctintegers.
Forinstance,thenumbers{2,3,4,5,7,12,15,20,28,35}canbeused:
Infact,onlyusingintegersbetween2and45inclusive,thereareexactlythreewaystodoit,theremaining
twobeing:{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}.
Howmanywaysaretheretowritethenumber1/2asasumofinversesquaresusingdistinctintegers
between2and80inclusive?
Problem153:InvestigatingGaussianIntegers
https://projecteuler.net/show=all
44/163
5/2/2015
Asweallknowtheequationx2=1hasnosolutionsforrealx.
Ifwehoweverintroducetheimaginarynumberithisequationhastwosolutions:x=iandx=i.
Ifwegoastepfurthertheequation(x3)2=4hastwocomplexsolutions:x=3+2iandx=32i.
x=3+2iandx=32iarecalledeachothers'complexconjugate.
Numbersoftheforma+biarecalledcomplexnumbers.
Ingenerala+biandabiareeachother'scomplexconjugate.
AGaussianIntegerisacomplexnumbera+bisuchthatbothaandbareintegers.
TheregularintegersarealsoGaussianintegers(withb=0).
TodistinguishthemfromGaussianintegerswithb0wecallsuchintegers"rationalintegers."
AGaussianintegeriscalledadivisorofarationalintegerniftheresultisalsoaGaussianinteger.
Ifforexamplewedivide5by1+2iwecansimplify
inthefollowingmanner:
Multiplynumeratoranddenominatorbythecomplexconjugateof1+2i:12i.
Theresultis
So1+2iisadivisorof5.
Notethat1+iisnotadivisorof5because
NotealsothatiftheGaussianInteger(a+bi)isadivisorofarationalintegern,thenitscomplexconjugate
(abi)isalsoadivisorofn.
Infact,5hassixdivisorssuchthattherealpartispositive:{1,1+2i,12i,2+i,2i,5}.
Thefollowingisatableofallofthedivisorsforthefirstfivepositiverationalintegers:
Gaussianintegerdivisors Sums(n)of
thesedivisors
n withpositiverealpart
1
1,1+i,1i,2
1,3
1,1+i,1i,2,2+2i,22i,4 13
1,1+2i,12i,2+i,2i,5
Fordivisorswithpositiverealparts,then,wehave:
12
.
For1n105,s(n)=17924657155.
Whatiss(n)for1n108?
Problem154:ExploringPascal'spyramid
Atriangularpyramidisconstructedusingsphericalballssothateachballrestsonexactlythreeballsofthe
nextlowerlevel.
https://projecteuler.net/show=all
45/163
5/2/2015
Then,wecalculatethenumberofpathsleadingfromtheapextoeachposition:
Apathstartsattheapexandprogressesdownwardstoanyofthethreespheresdirectlybelowthecurrent
position.
Consequently,thenumberofpathstoreachacertainpositionisthesumofthenumbersimmediatelyabove
it(dependingontheposition,thereareuptothreenumbersaboveit).
TheresultisPascal'spyramidandthenumbersateachlevelnarethecoefficientsofthetrinomial
expansion(x+y+z)n.
Howmanycoefficientsintheexpansionof(x+y+z)200000aremultiplesof1012?
Problem155:CountingCapacitorCircuits
AnelectriccircuitusesexclusivelyidenticalcapacitorsofthesamevalueC.
Thecapacitorscanbeconnectedinseriesorinparalleltoformsubunits,whichcanthenbeconnectedin
seriesorinparallelwithothercapacitorsorothersubunitstoformlargersubunits,andsoonuptoafinal
circuit.
Usingthissimpleprocedureanduptonidenticalcapacitors,wecanmakecircuitshavingarangeof
differenttotalcapacitances.Forexample,usingupton=3capacitorsof60 Feach,wecanobtainthe
following7distincttotalcapacitancevalues:
IfwedenotebyD(n)thenumberofdistincttotalcapacitancevalueswecanobtainwhenusingupton
equalvaluedcapacitorsandthesimpleproceduredescribedabove,wehave:D(1)=1,D(2)=3,D(3)=7...
FindD(18).
Reminder:WhenconnectingcapacitorsC1,C2etcinparallel,thetotalcapacitanceisCT=C1+C2+...,
whereaswhenconnectingtheminseries,theoverallcapacitanceisgivenby:
Problem156:CountingDigits
Startingfromzerothenaturalnumbersarewrittendowninbase10likethis:
0123456789101112....
Considerthedigitd=1.Afterwewritedowneachnumbern,wewillupdatethenumberofonesthathave
occurredandcallthisnumberf(n,1).Thefirstvaluesforf(n,1),then,areasfollows:
https://projecteuler.net/show=all
46/163
5/2/2015
n f(n,1)
0
1
2
3
4
5
6
7
8
9
10
11
12
0
1
1
1
1
1
1
1
1
1
2
4
5
Notethatf(n,1)neverequals3.
Sothefirsttwosolutionsoftheequationf(n,1)=naren=0andn=1.Thenextsolutionisn=199981.
Inthesamemannerthefunctionf(n,d)givesthetotalnumberofdigitsdthathavebeenwrittendownafter
thenumbernhasbeenwritten.
Infact,foreverydigitd0,0isthefirstsolutionoftheequationf(n,d)=n.
Lets(d)bethesumofallthesolutionsforwhichf(n,d)=n.
Youaregiventhats(1)=22786974071.
Finds(d)for1d9.
Note:if,forsomen,f(n,d)=nformorethanonevalueofdthisvalueofniscountedagainforeveryvalueof
dforwhichf(n,d)=n.
Problem157:Solvingthediophantineequation1/a+1/b=p/10n
Considerthediophantineequation1/a+1/b=p/10nwitha,b,p,npositiveintegersandab.
Forn=1thisequationhas20solutionsthatarelistedbelow:
1/ +1/ =20/
1
1
10
1/ +1/ =7/
2
5
10
1/ +1/ =3/
4
20
10
1/ +1/
1
=
11
110 /10
1/ +1/ =15/
1
2
10
1/ +1/ =6/
2
10
10
1/ +1/ =4/
5
5
10
1/ +1/ =1/
12
60
10
1/ +1/ =12/
1
5
10
1/ +1/ =5/
3
6
10
1/ +1/ =3/
5
10
10
1/ +1/ =1/
14
35
10
1/ +1/ =11/
1
10
10
1/ +1/ =4/
3
15
10
1/ +1/ =2/
6
30
10
1/ +1/ =1/
15
30
10
1/ +1/ =10/
2
2
10
1/ +1/ =5/
4
4
10
1/ +1/ =2/
10
10
10
1/ +1/ =1/
20
20
10
Howmanysolutionshasthisequationfor1n9?
Problem158:Exploringstringsforwhichonlyonecharactercomes
lexicographicallyafteritsneighbourtotheleft
Takingthreedifferentlettersfromthe26lettersofthealphabet,characterstringsoflengththreecanbe
formed.
Examplesare'abc','hat'and'zyx'.
Whenwestudythesethreeexamplesweseethatfor'abc'twocharacterscomelexicographicallyafterits
neighbourtotheleft.
For'hat'thereisexactlyonecharacterthatcomeslexicographicallyafteritsneighbourtotheleft.For'zyx'
therearezerocharactersthatcomelexicographicallyafteritsneighbourtotheleft.
Inallthereare10400stringsoflength3forwhichexactlyonecharactercomeslexicographicallyafterits
neighbourtotheleft.
Wenowconsiderstringsofn26differentcharactersfromthealphabet.
Foreveryn,p(n)isthenumberofstringsoflengthnforwhichexactlyonecharactercomes
lexicographicallyafteritsneighbourtotheleft.
Whatisthemaximumvalueofp(n)?
Problem159:Digitalrootsumsoffactorisations
https://projecteuler.net/show=all
47/163
5/2/2015
Acompositenumbercanbefactoredmanydifferentways.Forinstance,notincludingmultiplicationbyone,
24canbefactoredin7distinctways:
24=2x2x2x3
24=2x3x4
24=2x2x6
24=4x6
24=3x8
24=2x12
24=24
Recallthatthedigitalrootofanumber,inbase10,isfoundbyaddingtogetherthedigitsofthatnumber,
andrepeatingthatprocessuntilanumberisarrivedatthatislessthan10.Thusthedigitalrootof467is8.
WeshallcallaDigitalRootSum(DRS)thesumofthedigitalrootsoftheindividualfactorsofournumber.
ThechartbelowdemonstratesalloftheDRSvaluesfor24.
Factorisation DigitalRootSum
2x2x2x3
2x3x4
2x2x6
10
4x6
10
3x8
11
2x12
24
ThemaximumDigitalRootSumof24is11.
Thefunctionmdrs(n)givesthemaximumDigitalRootSumofn.Somdrs(24)=11.
Findmdrs(n)for1<n<1,000,000.
Problem160:Factorialtrailingdigits
ForanyN,letf(N)bethelastfivedigitsbeforethetrailingzeroesinN!.
Forexample,
9!=362880sof(9)=36288
10!=3628800sof(10)=36288
20!=2432902008176640000sof(20)=17664
Findf(1,000,000,000,000)
Problem161:Triominoes
Atriominoisashapeconsistingofthreesquaresjoinedviatheedges.Therearetwobasicforms:
Ifallpossibleorientationsaretakenintoaccounttherearesix:
Anynbymgridforwhichnxmisdivisibleby3canbetiledwithtriominoes.
Ifweconsidertilingsthatcanbeobtainedbyreflectionorrotationfromanothertilingasdifferentthereare
41waysa2by9gridcanbetiledwithtriominoes:
https://projecteuler.net/show=all
48/163
5/2/2015
Inhowmanywayscana9by12gridbetiledinthiswaybytriominoes?
Problem162:Hexadecimalnumbers
Inthehexadecimalnumbersystemnumbersarerepresentedusing16differentdigits:
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
ThehexadecimalnumberAFwhenwritteninthedecimalnumbersystemequals10x16+15=175.
Inthe3digithexadecimalnumbers10A,1A0,A10,andA01thedigits0,1andAareallpresent.
Likenumberswritteninbasetenwewritehexadecimalnumberswithoutleadingzeroes.
Howmanyhexadecimalnumberscontainingatmostsixteenhexadecimaldigitsexistwithallofthedigits
0,1,andApresentatleastonce?
Giveyouranswerasahexadecimalnumber.
(A,B,C,D,EandFinuppercase,withoutanyleadingortrailingcodethatmarksthenumberashexadecimal
andwithoutleadingzeroes,e.g.1A3Fandnot:1a3fandnot0x1a3fandnot$1A3Fandnot#1A3Fandnot
0000001A3F)
Problem163:Crosshatchedtriangles
Consideranequilateraltriangleinwhichstraightlinesaredrawnfromeachvertextothemiddleofthe
oppositeside,suchasinthesize1triangleinthesketchbelow.
Sixteentrianglesofeitherdifferentshapeorsizeororientationorlocationcannowbeobservedinthat
triangle.Usingsize1trianglesasbuildingblocks,largertrianglescanbeformed,suchasthesize2triangle
intheabovesketch.Onehundredandfourtrianglesofeitherdifferentshapeorsizeororientationor
locationcannowbeobservedinthatsize2triangle.
Itcanbeobservedthatthesize2trianglecontains4size1trianglebuildingblocks.Asize3trianglewould
contain9size1trianglebuildingblocksandasizentrianglewouldthuscontainn2size1trianglebuilding
blocks.
IfwedenoteT(n)asthenumberoftrianglespresentinatriangleofsizen,then
T(1)=16
T(2)=104
FindT(36).
https://projecteuler.net/show=all
49/163
5/2/2015
Problem164:Numbersforwhichnothreeconsecutivedigitshaveasumgreater
thanagivenvalue
Howmany20digitnumbersn(withoutanyleadingzero)existsuchthatnothreeconsecutivedigitsofn
haveasumgreaterthan9?
Problem165:Intersections
Asegmentisuniquelydefinedbyitstwoendpoints.
Byconsideringtwolinesegmentsinplanegeometrytherearethreepossibilities:
thesegmentshavezeropoints,onepoint,orinfinitelymanypointsincommon.
Moreoverwhentwosegmentshaveexactlyonepointincommonitmightbethecasethatthatcommon
pointisanendpointofeitheroneofthesegmentsorofboth.Ifacommonpointoftwosegmentsisnotan
endpointofeitherofthesegmentsitisaninteriorpointofbothsegments.
WewillcallacommonpointToftwosegmentsL1andL2atrueintersectionpointofL1andL2ifTisthe
onlycommonpointofL1andL2andTisaninteriorpointofbothsegments.
ConsiderthethreesegmentsL1,L2,andL3:
L1:(27,44)to(12,32)
L2:(46,53)to(17,62)
L3:(46,70)to(22,40)
ItcanbeverifiedthatlinesegmentsL2andL3haveatrueintersectionpoint.Wenotethatastheoneofthe
endpointsofL3:(22,40)liesonL1thisisnotconsideredtobeatruepointofintersection.L1andL2haveno
commonpoint.Soamongthethreelinesegments,wefindonetrueintersectionpoint.
Nowletusdothesamefor5000linesegments.Tothisend,wegenerate20000numbersusingtheso
called"BlumBlumShub"pseudorandomnumbergenerator.
s0=290797
sn+1=snsn(modulo50515093)
tn=sn(modulo500)
Tocreateeachlinesegment,weusefourconsecutivenumberstn.Thatis,thefirstlinesegmentisgivenby:
(t1,t2)to(t3,t4)
Thefirstfournumberscomputedaccordingtotheabovegeneratorshouldbe:27,144,12and232.Thefirst
segmentwouldthusbe(27,144)to(12,232).
Howmanydistincttrueintersectionpointsarefoundamongthe5000linesegments?
Problem166:CrissCross
A4x4gridisfilledwithdigitsd,0d9.
Itcanbeseenthatinthegrid
6330
5043
0714
1245
thesumofeachrowandeachcolumnhasthevalue12.Moreoverthesumofeachdiagonalisalso12.
Inhowmanywayscanyoufilla4x4gridwiththedigitsd,0d9sothateachrow,eachcolumn,andboth
diagonalshavethesamesum?
Problem167:InvestigatingUlamsequences
Fortwopositiveintegersaandb,theUlamsequenceU(a,b)isdefinedbyU(a,b)1=a,U(a,b)2=bandfork
>2,U(a,b)kisthesmallestintegergreaterthanU(a,b)(k1)whichcanbewritteninexactlyonewayasthe
sumoftwodistinctpreviousmembersofU(a,b).
Forexample,thesequenceU(1,2)beginswith
https://projecteuler.net/show=all
50/163
5/2/2015
1,2,3=1+2,4=1+3,6=2+4,8=2+6,11=3+8
5doesnotbelongtoitbecause5=1+4=2+3hastworepresentationsasthesumoftwoprevious
members,likewise7=1+6=3+4.
FindU(2,2n+1)kfor2n10,wherek=1011.
Problem168:NumberRotations
Considerthenumber142857.Wecanrightrotatethisnumberbymovingthelastdigit(7)tothefrontofit,
givingus714285.
Itcanbeverifiedthat714285=5142857.
Thisdemonstratesanunusualpropertyof142857:itisadivisorofitsrightrotation.
Findthelast5digitsofthesumofallintegersn,10<n<10100,thathavethisproperty.
Problem169:Exploringthenumberofdifferentwaysanumbercanbeexpressed
asasumofpowersof2
Definef(0)=1andf(n)tobethenumberofdifferentwaysncanbeexpressedasasumofintegerpowersof
2usingeachpowernomorethantwice.
Forexample,f(10)=5sincetherearefivedifferentwaystoexpress10:
1+1+8
1+1+4+4
1+1+2+2+4
2+4+4
2+8
Whatisf(1025)?
Problem170:Findthelargest0to9pandigitalthatcanbeformedby
concatenatingproducts
Takethenumber6andmultiplyitbyeachof1273and9854:
61273=7638
69854=59124
Byconcatenatingtheseproductswegetthe1to9pandigital763859124.Wewillcall763859124the
"concatenatedproductof6and(1273,9854)".Noticetoo,thattheconcatenationoftheinputnumbers,
612739854,isalso1to9pandigital.
Thesamecanbedonefor0to9pandigitalnumbers.
Whatisthelargest0to9pandigital10digitconcatenatedproductofanintegerwithtwoormoreother
integers,suchthattheconcatenationoftheinputnumbersisalsoa0to9pandigital10digitnumber?
Problem171:Findingnumbersforwhichthesumofthesquaresofthedigits
isasquare
Forapositiveintegern,letf(n)bethesumofthesquaresofthedigits(inbase10)ofn,e.g.
f(3)=32=9,
f(25)=22+52=4+25=29,
f(442)=42+42+22=16+16+4=36
Findthelastninedigitsofthesumofalln,0<n<1020,suchthatf(n)isaperfectsquare.
Problem172:Investigatingnumberswithfewrepeateddigits
Howmany18digitnumbersn(withoutleadingzeros)aretheresuchthatnodigitoccursmorethanthree
timesinn?
https://projecteuler.net/show=all
51/163
5/2/2015
Problem173:Usinguptoonemilliontileshowmanydifferent"hollow"square
laminaecanbeformed?
Weshalldefineasquarelaminatobeasquareoutlinewithasquare"hole"sothattheshapepossesses
verticalandhorizontalsymmetry.Forexample,usingexactlythirtytwosquaretileswecanformtwo
differentsquarelaminae:
Withonehundredtiles,andnotnecessarilyusingallofthetilesatonetime,itispossibletoformfortyone
differentsquarelaminae.
Usinguptoonemilliontileshowmanydifferentsquarelaminaecanbeformed?
Problem174:Countingthenumberof"hollow"squarelaminaethatcanform
one,two,three,...distinctarrangements
Weshalldefineasquarelaminatobeasquareoutlinewithasquare"hole"sothattheshapepossesses
verticalandhorizontalsymmetry.
Giveneighttilesitispossibletoformalaminainonlyoneway:3x3squarewitha1x1holeinthemiddle.
However,usingthirtytwotilesitispossibletoformtwodistinctlaminae.
Iftrepresentsthenumberoftilesused,weshallsaythatt=8istypeL(1)andt=32istypeL(2).
LetN(n)bethenumberoft1000000suchthattistypeL(n)forexample,N(15)=832.
WhatisN(n)for1n10?
Problem175:Fractionsinvolvingthenumberofdifferentwaysanumbercanbe
expressedasasumofpowersof2
Definef(0)=1andf(n)tobethenumberofwaystowritenasasumofpowersof2wherenopoweroccurs
morethantwice.
Forexample,f(10)=5sincetherearefivedifferentwaystoexpress10:
10=8+2=8+1+1=4+4+2=4+2+2+1+1=4+4+1+1
Itcanbeshownthatforeveryfractionp/q(p>0,q>0)thereexistsatleastoneintegernsuchthat
https://projecteuler.net/show=all
52/163
5/2/2015
f(n)/f(n1)=p/q.
Forinstance,thesmallestnforwhichf(n)/f(n1)=13/17is241.
Thebinaryexpansionof241is11110001.
Readingthisbinarynumberfromthemostsignificantbittotheleastsignificantbitthereare4one's,3
zeroesand1one.Weshallcallthestring4,3,1theShortenedBinaryExpansionof241.
FindtheShortenedBinaryExpansionofthesmallestnforwhich
f(n)/f(n1)=123456789/987654321.
Giveyouranswerascommaseparatedintegers,withoutanywhitespaces.
Problem176:Rightangledtrianglesthatshareacathetus
Thefourrightangledtriangleswithsides(9,12,15),(12,16,20),(5,12,13)and(12,35,37)allhaveoneofthe
shortersides(catheti)equalto12.Itcanbeshownthatnootherintegersidedrightangledtriangleexists
withoneofthecathetiequalto12.
Findthesmallestintegerthatcanbethelengthofacathetusofexactly47547differentintegersidedright
angledtriangles.
Problem177:IntegerangledQuadrilaterals
LetABCDbeaconvexquadrilateral,withdiagonalsACandBD.Ateachvertexthediagonalmakesan
anglewitheachofthetwosides,creatingeightcornerangles.
Forexample,atvertexA,thetwoanglesareCAD,CAB.
Wecallsuchaquadrilateralforwhichalleightcornerangleshaveintegervalueswhenmeasuredin
degreesan"integerangledquadrilateral".Anexampleofanintegerangledquadrilateralisasquare,where
alleightcorneranglesare45.AnotherexampleisgivenbyDAC=20,BAC=60,ABD=50,CBD=30,
BCA=40,DCA=30,CDB=80,ADB=50.
Whatisthetotalnumberofnonsimilarintegerangledquadrilaterals?
Note:Inyourcalculationsyoumayassumethatacalculatedangleisintegralifitiswithinatoleranceof109
ofanintegervalue.
Problem178:StepNumbers
Considerthenumber45656.
Itcanbeseenthateachpairofconsecutivedigitsof45656hasadifferenceofone.
Anumberforwhicheverypairofconsecutivedigitshasadifferenceofoneiscalledastepnumber.
Apandigitalnumbercontainseverydecimaldigitfrom0to9atleastonce.
Howmanypandigitalstepnumberslessthan1040arethere?
Problem179:Consecutivepositivedivisors
Findthenumberofintegers1<n<107,forwhichnandn+1havethesamenumberofpositivedivisors.
Forexample,14hasthepositivedivisors1,2,7,14while15has1,3,5,15.
Problem180:Rationalzerosofafunctionofthreevariables
Foranyintegern,considerthethreefunctions
f1,n(x,y,z)=xn+1+yn+1zn+1
https://projecteuler.net/show=all
53/163
5/2/2015
f2,n(x,y,z)=(xy+yz+zx)*(xn1+yn1zn1)
f3,n(x,y,z)=xyz*(xn2+yn2zn2)
andtheircombination
fn(x,y,z)=f1,n(x,y,z)+f2,n(x,y,z)f3,n(x,y,z)
Wecall(x,y,z)agoldentripleoforderkifx,y,andzareallrationalnumbersoftheforma/bwith
0<a<bkandthereis(atleast)oneintegern,sothatfn(x,y,z)=0.
Lets(x,y,z)=x+y+z.
Lett=u/vbethesumofalldistincts(x,y,z)forallgoldentriples(x,y,z)oforder35.
Allthes(x,y,z)andtmustbeinreducedform.
Findu+v.
Problem181:Investigatinginhowmanywaysobjectsoftwodifferentcolours
canbegrouped
HavingthreeblackobjectsBandonewhiteobjectWtheycanbegroupedin7wayslikethis:
(BBBW)
(B,BBW)
(B,B,BW)
(B,B,B,W)
(B,BB,W)
(BBB,W)
(BB,BW)
InhowmanywayscansixtyblackobjectsBandfortywhiteobjectsWbethusgrouped?
Problem182:RSAencryption
TheRSAencryptionisbasedonthefollowingprocedure:
Generatetwodistinctprimespandq.
Computen=pqand=(p1)(q1).
Findanintegere,1<e<,suchthatgcd(e,)=1.
Amessageinthissystemisanumberintheinterval[0,n1].
Atexttobeencryptedisthensomehowconvertedtomessages(numbersintheinterval[0,n1]).
Toencryptthetext,foreachmessage,m,c=memodniscalculated.
Todecryptthetext,thefollowingprocedureisneeded:calculatedsuchthated=1mod,thenforeach
encryptedmessage,c,calculatem=cdmodn.
Thereexistvaluesofeandmsuchthatmemodn=m.
Wecallmessagesmforwhichmemodn=munconcealedmessages.
Anissuewhenchoosingeisthatthereshouldnotbetoomanyunconcealedmessages.
Forinstance,letp=19andq=37.
Thenn=19*37=703and=18*36=648.
Ifwechoosee=181,then,althoughgcd(181,648)=1itturnsoutthatallpossiblemessages
m(0mn1)areunconcealedwhencalculatingmemodn.
Foranyvalidchoiceofethereexistsomeunconcealedmessages.
It'simportantthatthenumberofunconcealedmessagesisataminimum.
Choosep=1009andq=3643.
Findthesumofallvaluesofe,1<e<(1009,3643)andgcd(e,)=1,sothatthenumberofunconcealed
messagesforthisvalueofeisataminimum.
Problem183:Maximumproductofparts
LetNbeapositiveintegerandletNbesplitintokequalparts,r=N/k,sothatN=r+r+...+r.
LetPbetheproductoftheseparts,P=rr...r=rk.
Forexample,if11issplitintofiveequalparts,11=2.2+2.2+2.2+2.2+2.2,thenP=2.25=51.53632.
https://projecteuler.net/show=all
54/163
5/2/2015
LetM(N)=PmaxforagivenvalueofN.
ItturnsoutthatthemaximumforN=11isfoundbysplittingelevenintofourequalpartswhichleadsto
Pmax=(11/4)4thatis,M(11)=14641/256=57.19140625,whichisaterminatingdecimal.
However,forN=8themaximumisachievedbysplittingitintothreeequalparts,soM(8)=512/27,whichis
anonterminatingdecimal.
LetD(N)=NifM(N)isanonterminatingdecimalandD(N)=NifM(N)isaterminatingdecimal.
Forexample,D(N)for5N100is2438.
FindD(N)for5N10000.
Problem184:Trianglescontainingtheorigin
ConsiderthesetIrofpoints(x,y)withintegercoordinatesintheinteriorofthecirclewithradiusr,centered
attheorigin,i.e.x2+y2<r2.
Foraradiusof2,I2containstheninepoints(0,0),(1,0),(1,1),(0,1),(1,1),(1,0),(1,1),(0,1)and(1,1).
ThereareeighttriangleshavingallthreeverticesinI2whichcontaintheoriginintheinterior.Twoofthem
areshownbelow,theothersareobtainedfromthesebyrotation.
Foraradiusof3,thereare360trianglescontainingtheoriginintheinteriorandhavingallverticesinI3and
forI5thenumberis10600.
HowmanytrianglesaretherecontainingtheoriginintheinteriorandhavingallthreeverticesinI105?
Problem185:NumberMind
ThegameNumberMindisavariantofthewellknowngameMasterMind.
Insteadofcolouredpegs,youhavetoguessasecretsequenceofdigits.Aftereachguessyou'reonlytoldin
howmanyplacesyou'veguessedthecorrectdigit.So,ifthesequencewas1234andyouguessed2036,
you'dbetoldthatyouhaveonecorrectdigithowever,youwouldNOTbetoldthatyoualsohaveanother
digitinthewrongplace.
Forinstance,giventhefollowingguessesfora5digitsecretsequence,
903422correct
707940correct
394582correct
341091correct
515452correct
125311correct
Thecorrectsequence39542isunique.
Basedonthefollowingguesses,
56161856505182932correct
38474396472930471correct
58554629408105873correct
97428555070683533correct
42968496436075433correct
31742484394658581correct
45135590941461172correct
78909715489080673correct
81573563441184831correct
26152507443868992correct
86900958515262543correct
63757119150770501correct
69138591731213601correct
64428890550427682correct
23213861043038450correct
https://projecteuler.net/show=all
55/163
5/2/2015
23265094712714482correct
52515833796443222correct
17482704767582763correct
48957226521903061correct
30416311172246353correct
18412364543245893correct
26598626373168672correct
Findtheunique16digitsecretsequence.
Problem186:Connectednessofanetwork
Herearetherecordsfromabusytelephonesystemwithonemillionusers:
RecNr Caller
Called
200007 100053
600183 500439
600863 701497
...
...
...
ThetelephonenumberofthecallerandthecallednumberinrecordnareCaller(n)=S2n1andCalled(n)=
S2nwhereS1,2,3,...comefromthe"LaggedFibonacciGenerator":
For1k55,Sk=[100003200003k+300007k3](modulo1000000)
For56k,Sk=[Sk24+Sk55](modulo1000000)
IfCaller(n)=Called(n)thentheuserisassumedtohavemisdialledandthecallfailsotherwisethecallis
successful.
Fromthestartoftherecords,wesaythatanypairofusersXandYarefriendsifXcallsYorviceversa.
Similarly,XisafriendofafriendofZifXisafriendofYandYisafriendofZandsoonforlongerchains.
ThePrimeMinister'sphonenumberis524287.Afterhowmanysuccessfulcalls,notcountingmisdials,will
99%oftheusers(includingthePM)beafriend,orafriendofafriendetc.,ofthePrimeMinister?
Problem187:Semiprimes
Acompositeisanumbercontainingatleasttwoprimefactors.Forexample,15=359=3312=2
23.
Therearetencompositesbelowthirtycontainingpreciselytwo,notnecessarilydistinct,primefactors:4,6,
9,10,14,15,21,22,25,26.
Howmanycompositeintegers,n<108,havepreciselytwo,notnecessarilydistinct,primefactors?
Problem188:Thehyperexponentiationofanumber
Thehyperexponentiationortetrationofanumberabyapositiveintegerb,denotedbyaborba,is
recursivelydefinedby:
a1=a,
a(k+1)=a(ak).
Thuswehavee.g.32=33=27,hence33=327=7625597484987and34isroughly
103.6383346400240996*10^12.
Findthelast8digitsof17771855.
Problem189:Tricolouringatriangulargrid
Considerthefollowingconfigurationof64triangles:
https://projecteuler.net/show=all
56/163
5/2/2015
Wewishtocolourtheinteriorofeachtrianglewithoneofthreecolours:red,greenorblue,sothatnotwo
neighbouringtriangleshavethesamecolour.Suchacolouringshallbecalledvalid.Here,twotrianglesare
saidtobeneighbouringiftheyshareanedge.
Note:iftheyonlyshareavertex,thentheyarenotneighbours.
Forexample,hereisavalidcolouringoftheabovegrid:
AcolouringC'whichisobtainedfromacolouringCbyrotationorreflectionisconsidereddistinctfromC
unlessthetwoareidentical.
Howmanydistinctvalidcolouringsaretherefortheaboveconfiguration?
Problem190:Maximisingaweightedproduct
LetSm=(x1,x2,...,xm)bethemtupleofpositiverealnumberswithx1+x2+...+xm=mforwhichPm=
x1*x22*...*xmmismaximised.
Forexample,itcanbeverifiedthat[P10]=4112([]istheintegerpartfunction).
Find[Pm]for2m15.
Problem191:PrizeStrings
Aparticularschoolofferscashrewardstochildrenwithgoodattendanceandpunctuality.Iftheyareabsent
forthreeconsecutivedaysorlateonmorethanoneoccasionthentheyforfeittheirprize.
DuringanndayperiodatrinarystringisformedforeachchildconsistingofL's(late),O's(ontime),andA's
(absent).
Althoughthereareeightyonetrinarystringsfora4dayperiodthatcanbeformed,exactlyfortythree
stringswouldleadtoaprize:
OOOOOOOAOOOLOOAOOOAAOOALOOLOOOLAOAOOOAOA
OAOLOAAOOAALOALOOALAOLOOOLOAOLAOOLAAAOOO
AOOAAOOLAOAOAOAAAOALAOLOAOLAAAOOAAOAAAOL
AALOAALAALOOALOAALAOALAALOOOLOOALOAOLOAA
LAOOLAOALAAO
https://projecteuler.net/show=all
57/163
5/2/2015
Howmany"prize"stringsexistovera30dayperiod?
Problem192:BestApproximations
Letxbearealnumber.
Abestapproximationtoxforthedenominatorbounddisarationalnumberr/sinreducedform,withsd,
suchthatanyrationalnumberwhichisclosertoxthanr/shasadenominatorlargerthand:
|p/qx|<|r/sx|q>d
Forexample,thebestapproximationto13forthedenominatorbound20is18/5andthebest
approximationto13forthedenominatorbound30is101/28.
Findthesumofalldenominatorsofthebestapproximationstonforthedenominatorbound1012,wheren
isnotaperfectsquareand1<n100000.
Problem193:SquarefreeNumbers
Apositiveintegerniscalledsquarefree,ifnosquareofaprimedividesn,thus1,2,3,5,6,7,10,11are
squarefree,butnot4,8,9,12.
Howmanysquarefreenumbersaretherebelow250?
Problem194:ColouredConfigurations
ConsidergraphsbuiltwiththeunitsA:
edgesasinthegraph
andB:
,wheretheunitsaregluedalongthevertical
Aconfigurationoftype(a,b,c)isagraphthusbuiltofaunitsAandbunitsB,wherethegraph'sverticesare
colouredusinguptoccolours,sothatnotwoadjacentverticeshavethesamecolour.
Thecompoundgraphaboveisanexampleofaconfigurationoftype(2,2,6),infactoftype(2,2,c)forallc
4.
LetN(a,b,c)bethenumberofconfigurationsoftype(a,b,c).
Forexample,N(1,0,3)=24,N(0,2,4)=92928andN(2,2,3)=20736.
Findthelast8digitsofN(25,75,1984).
Problem195:Inscribedcirclesoftriangleswithoneangleof60degrees
Let'scallanintegersidedtrianglewithexactlyoneangleof60degreesa60degreetriangle.
Letrbetheradiusoftheinscribedcircleofsucha60degreetriangle.
Thereare123460degreetrianglesforwhichr100.
LetT(n)bethenumberof60degreetrianglesforwhichrn,so
T(100)=1234,T(1000)=22767,andT(10000)=359912.
FindT(1053779).
Problem196:Primetriplets
Buildatrianglefromallpositiveintegersinthefollowingway:
1
23
456
78910
1112131415
https://projecteuler.net/show=all
58/163
5/2/2015
161718192021
22232425262728
2930313233343536
373839404142434445
46474849505152535455
5657585960616263646566
...
Eachpositiveintegerhasuptoeightneighboursinthetriangle.
Asetofthreeprimesiscalledaprimetripletifoneofthethreeprimeshastheothertwoasneighboursin
thetriangle.
Forexample,inthesecondrow,theprimenumbers2and3areelementsofsomeprimetriplet.
Ifrow8isconsidered,itcontainstwoprimeswhichareelementsofsomeprimetriplet,i.e.29and31.
Ifrow9isconsidered,itcontainsonlyoneprimewhichisanelementofsomeprimetriplet:37.
DefineS(n)asthesumoftheprimesinrownwhichareelementsofanyprimetriplet.
ThenS(8)=60andS(9)=37.
YouaregiventhatS(10000)=950007619.
FindS(5678027)+S(7208785).
Problem197:Investigatingthebehaviourofarecursivelydefinedsequence
2
Givenisthefunctionf(x)=230.403243784x 109(isthefloorfunction),
thesequenceunisdefinedbyu0=1andun+1=f(un).
Findun+un+1forn=1012.
Giveyouranswerwith9digitsafterthedecimalpoint.
Problem198:AmbiguousNumbers
Abestapproximationtoarealnumberxforthedenominatorbounddisarationalnumberr/s(inreduced
form)withsd,sothatanyrationalnumberp/qwhichisclosertoxthanr/shasq>d.
Usuallythebestapproximationtoarealnumberisuniquelydeterminedforalldenominatorbounds.
However,therearesomeexceptions,e.g.9/40hasthetwobestapproximations1/4and1/5forthe
denominatorbound6.Weshallcallarealnumberxambiguous,ifthereisatleastonedenominatorbound
forwhichxpossessestwobestapproximations.Clearly,anambiguousnumberisnecessarilyrational.
Howmanyambiguousnumbersx=p/q,0<x<1/100,aretherewhosedenominatorqdoesnotexceed
108?
Problem199:IterativeCirclePacking
Threecirclesofequalradiusareplacedinsidealargercirclesuchthateachpairofcirclesistangenttoone
anotherandtheinnercirclesdonotoverlap.Therearefouruncovered"gaps"whicharetobefilled
iterativelywithmoretangentcircles.
https://projecteuler.net/show=all
59/163
5/2/2015
Ateachiteration,amaximallysizedcircleisplacedineachgap,whichcreatesmoregapsforthenext
iteration.After3iterations(pictured),thereare108gapsandthefractionoftheareawhichisnotcoveredby
circlesis0.06790342,roundedtoeightdecimalplaces.
Whatfractionoftheareaisnotcoveredbycirclesafter10iterations?
Giveyouranswerroundedtoeightdecimalplacesusingtheformatx.xxxxxxxx.
Problem200:Findthe200thprimeproofsqubecontainingthecontiguoussub
string"200"
Weshalldefineasqubetobeanumberoftheform,p2q3,wherepandqaredistinctprimes.
Forexample,200=5223or120072949=232613.
Thefirstfivesqubesare72,108,200,392,and500.
Interestingly,200isalsothefirstnumberforwhichyoucannotchangeanysingledigittomakeaprimewe
shallcallsuchnumbers,primeproof.Thenextprimeproofsqubewhichcontainsthecontiguoussubstring
"200"is1992008.
Findthe200thprimeproofsqubecontainingthecontiguoussubstring"200".
Problem201:Subsetswithauniquesum
ForanysetAofnumbers,letsum(A)bethesumoftheelementsofA.
ConsiderthesetB={1,3,6,8,10,11}.
Thereare20subsetsofBcontainingthreeelements,andtheirsumsare:
sum({1,3,6})=10,
sum({1,3,8})=12,
sum({1,3,10})=14,
sum({1,3,11})=15,
sum({1,6,8})=15,
sum({1,6,10})=17,
sum({1,6,11})=18,
sum({1,8,10})=19,
sum({1,8,11})=20,
sum({1,10,11})=22,
sum({3,6,8})=17,
sum({3,6,10})=19,
sum({3,6,11})=20,
sum({3,8,10})=21,
sum({3,8,11})=22,
sum({3,10,11})=24,
sum({6,8,10})=24,
sum({6,8,11})=25,
sum({6,10,11})=27,
sum({8,10,11})=29.
Someofthesesumsoccurmorethanonce,othersareunique.
https://projecteuler.net/show=all
60/163
5/2/2015
ForasetA,letU(A,k)bethesetofuniquesumsofkelementsubsetsofA,inourexamplewefindU(B,3)=
{10,12,14,18,21,25,27,29}andsum(U(B,3))=156.
Nowconsiderthe100elementsetS={12,22,...,1002}.
Shas10089134454556419333481249725650elementsubsets.
Determinethesumofallintegerswhicharethesumofexactlyoneofthe50elementsubsetsofS,i.e.find
sum(U(S,50)).
Problem202:Laserbeam
Threemirrorsarearrangedintheshapeofanequilateraltriangle,withtheirreflectivesurfacespointing
inwards.Thereisaninfinitesimalgapateachvertexofthetrianglethroughwhichalaserbeammaypass.
LabeltheverticesA,BandC.Thereare2waysinwhichalaserbeammayentervertexC,bounceoff11
surfaces,thenexitthroughthesamevertex:onewayisshownbelowtheotheristhereverseofthat.
Thereare80840waysinwhichalaserbeammayentervertexC,bounceoff1000001surfaces,thenexit
throughthesamevertex.
InhowmanywayscanalaserbeamenteratvertexC,bounceoff12017639147surfaces,thenexitthrough
thesamevertex?
Problem203:SquarefreeBinomialCoefficients
ThebinomialcoefficientsnCkcanbearrangedintriangularform,Pascal'striangle,likethis:
1
1
1
1
1
1
1
1
3
4
5
6
1
3
6
10
15
21
1
2
1
4
10
20
35
35
.........
1
5
15
1
6
21
1
7
ItcanbeseenthatthefirsteightrowsofPascal'strianglecontaintwelvedistinctnumbers:
1,2,3,4,5,6,7,10,15,20,21and35.
Apositiveintegerniscalledsquarefreeifnosquareofaprimedividesn.Ofthetwelvedistinctnumbersin
thefirsteightrowsofPascal'striangle,allexcept4and20aresquarefree.Thesumofthedistinct
squarefreenumbersinthefirsteightrowsis105.
Findthesumofthedistinctsquarefreenumbersinthefirst51rowsofPascal'striangle.
Problem204:GeneralisedHammingNumbers
AHammingnumberisapositivenumberwhichhasnoprimefactorlargerthan5.
SothefirstfewHammingnumbersare1,2,3,4,5,6,8,9,10,12,15.
Thereare1105Hammingnumbersnotexceeding108.
https://projecteuler.net/show=all
61/163
5/2/2015
WewillcallapositivenumberageneralisedHammingnumberoftypen,ifithasnoprimefactorlargerthan
n.
HencetheHammingnumbersarethegeneralisedHammingnumbersoftype5.
HowmanygeneralisedHammingnumbersoftype100aretherewhichdon'texceed109?
Problem205:DiceGame
Peterhasninefoursided(pyramidal)dice,eachwithfacesnumbered1,2,3,4.
Colinhassixsixsided(cubic)dice,eachwithfacesnumbered1,2,3,4,5,6.
PeterandColinrolltheirdiceandcomparetotals:thehighesttotalwins.Theresultisadrawifthetotalsare
equal.
WhatistheprobabilitythatPyramidalPetebeatsCubicColin?Giveyouranswerroundedtosevendecimal
placesintheform0.abcdefg
Problem206:ConcealedSquare
Findtheuniquepositiveintegerwhosesquarehastheform1_2_3_4_5_6_7_8_9_0,
whereeach_isasingledigit.
Problem207:Integerpartitionequations
Forsomepositiveintegersk,thereexistsanintegerpartitionoftheform4t=2t+k,
where4t,2t,andkareallpositiveintegersandtisarealnumber.
Thefirsttwosuchpartitionsare41=21+2and41.5849625...=21.5849625...+6.
Partitionswheretisalsoanintegerarecalledperfect.
Foranym1letP(m)betheproportionofsuchpartitionsthatareperfectwithkm.
ThusP(6)=1/2.
InthefollowingtablearelistedsomevaluesofP(m)
P(5)=1/1
P(10)=1/2
P(15)=2/3
P(20)=1/2
P(25)=1/2
P(30)=2/5
...
P(180)=1/4
P(185)=3/13
FindthesmallestmforwhichP(m)<1/12345
Problem208:RobotWalks
Arobotmovesinaseriesofonefifthcirculararcs(72),withafreechoiceofaclockwiseoran
anticlockwisearcforeachstep,butnoturningonthespot.
Oneof70932possibleclosedpathsof25arcsstartingnorthwardis
https://projecteuler.net/show=all
62/163
5/2/2015
GiventhattherobotstartsfacingNorth,howmanyjourneysof70arcsinlengthcanittakethatreturnit,
afterthefinalarc,toitsstartingposition?
(Anyarcmaybetraversedmultipletimes.)
Problem209:CircularLogic
Akinputbinarytruthtableisamapfromkinputbits(binarydigits,0[false]or1[true])to1outputbit.For
example,the2inputbinarytruthtablesforthelogicalANDandXORfunctionsare:
y xANDy
y xXORy
Howmany6inputbinarytruthtables,,satisfytheformula
(a,b,c,d,e,f)AND(b,c,d,e,f,aXOR(bANDc))=0
forall6bitinputs(a,b,c,d,e,f)?
Problem210:ObtuseAngledTriangles
ConsiderthesetS(r)ofpoints(x,y)withintegercoordinatessatisfying|x|+|y|r.
LetObethepoint(0,0)andCthepoint(r/4,r/4).
LetN(r)bethenumberofpointsBinS(r),sothatthetriangleOBChasanobtuseangle,i.e.thelargest
anglesatisfies90<<180.
So,forexample,N(4)=24andN(8)=100.
WhatisN(1,000,000,000)?
Problem211:DivisorSquareSum
Forapositiveintegern,let2(n)bethesumofthesquaresofitsdivisors.Forexample,
2(10)=1+4+25+100=130.
Findthesumofalln,0<n<64,000,000suchthat2(n)isaperfectsquare.
Problem212:CombinedVolumeofCuboids
Anaxisalignedcuboid,specifiedbyparameters{(x0,y0,z0),(dx,dy,dz)},consistsofallpoints(X,Y,Z)such
thatx0Xx0+dx,y0Yy0+dyandz0Zz0+dz.Thevolumeofthecuboidistheproduct,dxdy
dz.Thecombinedvolumeofacollectionofcuboidsisthevolumeoftheirunionandwillbelessthanthe
sumoftheindividualvolumesifanycuboidsoverlap.
LetC1,...,C50000beacollectionof50000axisalignedcuboidssuchthatCnhasparameters
x0=S6n5modulo10000
https://projecteuler.net/show=all
63/163
5/2/2015
y0=S6n4modulo10000
z0=S6n3modulo10000
dx=1+(S6n2modulo399)
dy=1+(S6n1modulo399)
dz=1+(S6nmodulo399)
whereS1,...,S300000comefromthe"LaggedFibonacciGenerator":
For1k55,Sk=[100003200003k+300007k3](modulo1000000)
For56k,Sk=[Sk24+Sk55](modulo1000000)
Thus,C1hasparameters{(7,53,183),(94,369,56)},C2hasparameters{(2383,3563,5079),(42,212,344)},
andsoon.
Thecombinedvolumeofthefirst100cuboids,C1,...,C100,is723581599.
Whatisthecombinedvolumeofall50000cuboids,C1,...,C50000?
Problem213:FleaCircus
A3030gridofsquarescontains900fleas,initiallyonefleapersquare.
Whenabellisrung,eachfleajumpstoanadjacentsquareatrandom(usually4possibilities,exceptfor
fleasontheedgeofthegridoratthecorners).
Whatistheexpectednumberofunoccupiedsquaresafter50ringsofthebell?Giveyouranswerroundedto
sixdecimalplaces.
Problem214:TotientChains
LetbeEuler'stotientfunction,i.e.foranaturalnumbern,(n)isthenumberofk,1kn,forwhich
gcd(k,n)=1.
Byiterating,eachpositiveintegergeneratesadecreasingchainofnumbersendingin1.
E.g.ifwestartwith5thesequence5,4,2,1isgenerated.
Hereisalistingofallchainswithlength4:
5,4,2,1
7,6,2,1
8,4,2,1
9,6,2,1
10,4,2,1
12,4,2,1
14,6,2,1
18,6,2,1
Onlytwoofthesechainsstartwithaprime,theirsumis12.
Whatisthesumofallprimeslessthan40000000whichgenerateachainoflength25?
Problem215:CrackfreeWalls
Considertheproblemofbuildingawalloutof21and31bricks(horizontalverticaldimensions)suchthat,
forextrastrength,thegapsbetweenhorizontallyadjacentbricksneverlineupinconsecutivelayers,i.e.
neverforma"runningcrack".
Forexample,thefollowing93wallisnotacceptableduetotherunningcrackshowninred:
Thereareeightwaysofformingacrackfree93wall,writtenW(9,3)=8.
CalculateW(32,10).
https://projecteuler.net/show=all
64/163
5/2/2015
Problem216:Investigatingtheprimalityofnumbersoftheform2n21
Considernumberst(n)oftheformt(n)=2n21withn>1.
Thefirstsuchnumbersare7,17,31,49,71,97,127and161.
Itturnsoutthatonly49=7*7and161=7*23arenotprime.
Forn10000thereare2202numberst(n)thatareprime.
Howmanynumberst(n)areprimeforn50,000,000?
Problem217:BalancedNumbers
Apositiveintegerwithk(decimal)digitsiscalledbalancedifitsfirstk/2digitssumtothesamevalueasits
lastk/ digits,wherex,pronouncedceilingofx,isthesmallestintegerx,thus=4and5=5.
2
So,forexample,allpalindromesarebalanced,asis13722.
LetT(n)bethesumofallbalancednumberslessthan10n.
Thus:T(1)=45,T(2)=540andT(5)=334795890.
FindT(47)mod315
Problem218:Perfectrightangledtriangles
Considertherightangledtrianglewithsidesa=7,b=24andc=25.Theareaofthistriangleis84,whichis
divisiblebytheperfectnumbers6and28.
Moreoveritisaprimitiverightangledtriangleasgcd(a,b)=1andgcd(b,c)=1.
Alsocisaperfectsquare.
Wewillcallarightangledtriangleperfectif
itisaprimitiverightangledtriangle
itshypotenuseisaperfectsquare
Wewillcallarightangledtrianglesuperperfectif
itisaperfectrightangledtriangleand
itsareaisamultipleoftheperfectnumbers6and28.
Howmanyperfectrightangledtriangleswithc1016existthatarenotsuperperfect?
Problem219:Skewcostcoding
LetAandBbebitstrings(sequencesof0'sand1's).
IfAisequaltotheleftmostlength(A)bitsofB,thenAissaidtobeaprefixofB.
Forexample,00110isaprefixof001101001,butnotof00111or100110.
Aprefixfreecodeofsizenisacollectionofndistinctbitstringssuchthatnostringisaprefixofanyother.
Forexample,thisisaprefixfreecodeofsize6:
0000,0001,001,01,10,11
Nowsupposethatitcostsonepennytotransmita'0'bit,butfourpencetotransmita'1'.
Thenthetotalcostoftheprefixfreecodeshownaboveis35pence,whichhappenstobethecheapest
possiblefortheskewedpricingschemeinquestion.
Inshort,wewriteCost(6)=35.
WhatisCost(109)?
Problem220:HeighwayDragon
LetD0bethetwoletterstring"Fa".Forn1,deriveDnfromDn1bythestringrewritingrules:
"a""aRbFR"
"b""LFaLb"
https://projecteuler.net/show=all
65/163
5/2/2015
Thus,D0="Fa",D1="FaRbFR",D2="FaRbFRRLFaLbFR",andsoon.
Thesestringscanbeinterpretedasinstructionstoacomputergraphicsprogram,with"F"meaning"draw
forwardoneunit","L"meaning"turnleft90degrees","R"meaning"turnright90degrees",and"a"and"b"
beingignored.Theinitialpositionofthecomputercursoris(0,0),pointinguptowards(0,1).
ThenDnisanexoticdrawingknownastheHeighwayDragonofordern.Forexample,D10isshownbelow
countingeach"F"asonestep,thehighlightedspotat(18,16)isthepositionreachedafter500steps.
Whatisthepositionofthecursorafter1012stepsinD50?
Giveyouranswerintheformx,ywithnospaces.
Problem221:AlexandrianIntegers
WeshallcallapositiveintegerAan"Alexandrianinteger",ifthereexistintegersp,q,rsuchthat:
A=pqrand
Forexample,630isanAlexandrianinteger(p=5,q=7,r=18).Infact,630isthe6thAlexandrian
integer,thefirst6Alexandrianintegersbeing:6,42,120,156,420and630.
Findthe150000thAlexandrianinteger.
Problem222:SpherePacking
Whatisthelengthoftheshortestpipe,ofinternalradius50mm,thatcanfullycontain21ballsofradii30mm,
31mm,...,50mm?
Giveyouranswerinmicrometres(106m)roundedtothenearestinteger.
Problem223:AlmostrightangledtrianglesI
Letuscallanintegersidedtrianglewithsidesabcbarelyacuteifthesidessatisfy
a2+b2=c2+1.
Howmanybarelyacutetrianglesaretherewithperimeter25,000,000?
Problem224:AlmostrightangledtrianglesII
Letuscallanintegersidedtrianglewithsidesabcbarelyobtuseifthesidessatisfy
a2+b2=c21.
Howmanybarelyobtusetrianglesaretherewithperimeter75,000,000?
Problem225:Tribonaccinondivisors
Thesequence1,1,1,3,5,9,17,31,57,105,193,355,653,1201...
isdefinedbyT1=T2=T3=1andTn=Tn1+Tn2+Tn3.
https://projecteuler.net/show=all
66/163
5/2/2015
Itcanbeshownthat27doesnotdivideanytermsofthissequence.
Infact,27isthefirstoddnumberwiththisproperty.
Findthe124thoddnumberthatdoesnotdivideanytermsoftheabovesequence.
Problem226:AScoopofBlancmange
Theblancmangecurveisthesetofpoints(x,y)suchthat0x1and
wheres(x)=thedistancefromxtothenearestinteger.
Theareaundertheblancmangecurveisequalto,showninpinkinthediagrambelow.
LetCbethecirclewithcentre(,)andradius,showninblackinthediagram.
WhatareaundertheblancmangecurveisenclosedbyC?
Giveyouranswerroundedtoeightdecimalplacesintheform0.abcdefgh
Problem227:TheChase
"TheChase"isagameplayedwithtwodiceandanevennumberofplayers.
Theplayerssitaroundatablethegamebeginswithtwooppositeplayershavingonedieeach.Oneach
turn,thetwoplayerswithadierollit.
Ifaplayerrollsa1,hepassesthedietohisneighbourontheleftifherollsa6,hepassesthedietohis
neighbourontherightotherwise,hekeepsthedieforthenextturn.
Thegameendswhenoneplayerhasbothdiceaftertheyhavebeenrolledandpassedthatplayerhasthen
lost.
Inagamewith100players,whatistheexpectednumberofturnsthegamelasts?
Giveyouranswerroundedtotensignificantdigits.
Problem228:MinkowskiSums
LetSnbetheregularnsidedpolygonorshapewhoseverticesvk(k=1,2,,n)havecoordinates:
xk=cos(2k1/n180)
yk=sin(2k1/n180)
EachSnistobeinterpretedasafilledshapeconsistingofallpointsontheperimeterandintheinterior.
TheMinkowskisum,S+T,oftwoshapesSandTistheresultofaddingeverypointinStoeverypointinT,
wherepointadditionisperformedcoordinatewise:(u,v)+(x,y)=(u+x,v+y).
Forexample,thesumofS3andS4isthesixsidedshapeshowninpinkbelow:
https://projecteuler.net/show=all
67/163
5/2/2015
HowmanysidesdoesS1864+S1865++S1909have?
Problem229:FourRepresentationsusingSquares
Considerthenumber3600.Itisveryspecial,because
3600=482+362
3600=202+2402
3600=302+3302
3600=452+7152
Similarly,wefindthat88201=992+2802=2872+2542=2832+3522=1972+7842.
In1747,Eulerprovedwhichnumbersarerepresentableasasumoftwosquares.Weareinterestedinthe
numbersnwhichadmitrepresentationsofallofthefollowingfourtypes:
n=a12+b12
n=a22+2b22
n=a32+3b32
n=a72+7b72,
wheretheakandbkarepositiveintegers.
Thereare75373suchnumbersthatdonotexceed107.
Howmanysuchnumbersaretherethatdonotexceed2109?
Problem230:FibonacciWords
Foranytwostringsofdigits,AandB,wedefineFA,Btobethesequence(A,B,AB,BAB,ABBAB,...)inwhich
eachtermistheconcatenationoftheprevioustwo.
Further,wedefineDA,B(n)tobethenthdigitinthefirsttermofFA,Bthatcontainsatleastndigits.
Example:
LetA=1415926535,B=8979323846.WewishtofindDA,B(35),say.
ThefirstfewtermsofFA,Bare:
1415926535
8979323846
14159265358979323846
897932384614159265358979323846
14159265358979323846897932384614159265358979323846
ThenDA,B(35)isthe35thdigitinthefifthterm,whichis9.
NowweuseforAthefirst100digitsofbehindthedecimalpoint:
14159265358979323846264338327950288419716939937510
58209749445923078164062862089986280348253421170679
andforBthenexthundreddigits:
https://projecteuler.net/show=all
68/163
5/2/2015
82148086513282306647093844609550582231725359408128
48111745028410270193852110555964462294895493038196.
Findn=0,1,...,1710nDA,B((127+19n)7n).
Problem231:Theprimefactorisationofbinomialcoefficients
Thebinomialcoefficient10C3=120.
120=2335=22235,and2+2+2+3+5=14.
Sothesumofthetermsintheprimefactorisationof10C3is14.
Findthesumofthetermsintheprimefactorisationof20000000C15000000.
Problem232:TheRace
Twoplayersshareanunbiasedcoinandtakeitinturnstoplay"TheRace".OnPlayer1'sturn,hetosses
thecoinonce:ifitcomesupHeads,hescoresonepointifitcomesupTails,hescoresnothing.OnPlayer
2'sturn,shechoosesapositiveintegerTandtossesthecoinTtimes:ifitcomesupallHeads,shescores
2T1pointsotherwise,shescoresnothing.Player1goesfirst.Thewinneristhefirstto100ormorepoints.
OneachturnPlayer2selectsthenumber,T,ofcointossesthatmaximisestheprobabilityofherwinning.
WhatistheprobabilitythatPlayer2wins?
Giveyouranswerroundedtoeightdecimalplacesintheform0.abcdefgh.
Problem233:Latticepointsonacircle
Letf(N)bethenumberofpointswithintegercoordinatesthatareonacirclepassingthrough(0,0),(N,0),
(0,N),and(N,N).
Itcanbeshownthatf(10000)=36.
WhatisthesumofallpositiveintegersN1011suchthatf(N)=420?
Problem234:Semidivisiblenumbers
Foranintegern4,wedefinethelowerprimesquarerootofn,denotedbylps(n),asthelargestprime
nandtheupperprimesquarerootofn,ups(n),asthesmallestprimen.
So,forexample,lps(4)=2=ups(4),lps(1000)=31,ups(1000)=37.
Letuscallanintegern4semidivisible,ifoneoflps(n)andups(n)dividesn,butnotboth.
Thesumofthesemidivisiblenumbersnotexceeding15is30,thenumbersare8,10and12.
15isnotsemidivisiblebecauseitisamultipleofbothlps(15)=3andups(15)=5.
Asafurtherexample,thesumofthe92semidivisiblenumbersupto1000is34825.
Whatisthesumofallsemidivisiblenumbersnotexceeding999966663333?
Problem235:AnArithmeticGeometricsequence
Givenisthearithmeticgeometricsequenceu(k)=(9003k)rk1.
Lets(n)=k=1...nu(k).
Findthevalueofrforwhichs(5000)=600,000,000,000.
Giveyouranswerroundedto12placesbehindthedecimalpoint.
Problem236:LuxuryHampers
https://projecteuler.net/show=all
69/163
5/2/2015
Suppliers'A'and'B'providedthefollowingnumbersofproductsfortheluxuryhampermarket:
Product
BelugaCaviar
ChristmasCake
GammonJoint
VintagePort
ChampagneTruffles
'A'
5248
1312
2624
5760
3936
'B'
640
1888
3776
3776
5664
Althoughthesupplierstryveryhardtoshiptheirgoodsinperfectcondition,thereisinevitablysomespoilage
i.e.productsgonebad.
Thesupplierscomparetheirperformanceusingtwotypesofstatistic:
Thefiveperproductspoilageratesforeachsupplierareequaltothenumberofproductsgonebad
dividedbythenumberofproductssupplied,foreachofthefiveproductsinturn.
Theoverallspoilagerateforeachsupplierisequaltothetotalnumberofproductsgonebaddivided
bythetotalnumberofproductsprovidedbythatsupplier.
Totheirsurprise,thesuppliersfoundthateachofthefiveperproductspoilagerateswasworse(higher)for
'B'thanfor'A'bythesamefactor(ratioofspoilagerates),m>1andyet,paradoxically,theoverallspoilage
ratewasworsefor'A'thanfor'B',alsobyafactorofm.
Therearethirtyfivem>1forwhichthissurprisingresultcouldhaveoccurred,thesmallestofwhichis
1476/1475.
What'sthelargestpossiblevalueofm?
Giveyouranswerasafractionreducedtoitslowestterms,intheformu/v.
Problem237:Toursona4xnplayingboard
LetT(n)bethenumberoftoursovera4nplayingboardsuchthat:
Thetourstartsinthetopleftcorner.
Thetourconsistsofmovesthatareup,down,left,orrightonesquare.
Thetourvisitseachsquareexactlyonce.
Thetourendsinthebottomleftcorner.
Thediagramshowsonetourovera410board:
T(10)is2329.WhatisT(1012)modulo108?
Problem238:Infinitestringtour
Createasequenceofnumbersusingthe"BlumBlumShub"pseudorandomnumbergenerator:
s0 = 14025256
sn+1 = sn2mod20300713
Concatenatethesenumberss0s1s2tocreateastringwofinfinitelength.
Then,w=14025256741014958470038053646
Forapositiveintegerk,ifnosubstringofwexistswithasumofdigitsequaltok,p(k)isdefinedtobezero.
Ifatleastonesubstringofwexistswithasumofdigitsequaltok,wedefinep(k)=z,wherezisthestarting
positionoftheearliestsuchsubstring.
Forinstance:
Thesubstrings1,14,1402,
withrespectivesumsofdigitsequalto1,5,7,
https://projecteuler.net/show=all
70/163
5/2/2015
startatposition1,hencep(1)=p(5)=p(7)==1.
Thesubstrings4,402,4025,
withrespectivesumsofdigitsequalto4,6,11,
startatposition2,hencep(4)=p(6)=p(11)==2.
Thesubstrings02,0252,
withrespectivesumsofdigitsequalto2,9,
startatposition3,hencep(2)=p(9)==3.
Notethatsubstring025startingatposition3,hasasumofdigitsequalto7,buttherewasanearlier
substring(startingatposition1)withasumofdigitsequalto7,sop(7)=1,not3.
Wecanverifythat,for0<k103,p(k)=4742.
Findp(k),for0<k21015.
Problem239:TwentytwoFoolishPrimes
Asetofdisksnumbered1through100areplacedinalineinrandomorder.
Whatistheprobabilitythatwehaveapartialderangementsuchthatexactly22primenumberdiscsare
foundawayfromtheirnaturalpositions?
(Anynumberofnonprimedisksmayalsobefoundinoroutoftheirnaturalpositions.)
Giveyouranswerroundedto12placesbehindthedecimalpointintheform0.abcdefghijkl.
Problem240:TopDice
Thereare1111waysinwhichfive6sideddice(sidesnumbered1to6)canberolledsothatthetopthree
sumto15.Someexamplesare:
D1,D2,D3,D4,D5=4,3,6,3,5
D1,D2,D3,D4,D5=4,3,3,5,6
D1,D2,D3,D4,D5=3,3,3,6,6
D1,D2,D3,D4,D5=6,6,3,3,3
Inhowmanywayscantwenty12sideddice(sidesnumbered1to12)berolledsothatthetoptensumto
70?
Problem241:PerfectionQuotients
Forapositiveintegern,let(n)bethesumofalldivisorsofn,soe.g.(6)=1+2+3+6=12.
Aperfectnumber,asyouprobablyknow,isanumberwith(n)=2n.
Letusdefinetheperfectionquotientofapositiveintegeras p(n) =
(n)
Findthesumofallpositiveintegersn1018forwhichp(n)hastheformk+12,wherekisaninteger.
Problem242:OddTriplets
Giventheset{1,2,...,n},wedefinef(n,k)asthenumberofitskelementsubsetswithanoddsumof
elements.Forexample,f(5,3)=4,sincetheset{1,2,3,4,5}hasfour3elementsubsetshavinganoddsumof
elements,i.e.:{1,2,4},{1,3,5},{2,3,4}and{2,4,5}.
Whenallthreevaluesn,kandf(n,k)areodd,wesaythattheymake
anoddtriplet[n,k,f(n,k)].
Thereareexactlyfiveoddtripletswithn10,namely:
[1,1,f(1,1)=1],[5,1,f(5,1)=3],[5,5,f(5,5)=1],[9,1,f(9,1)=5]and[9,9,f(9,9)=1].
Howmanyoddtripletsaretherewithn1012?
https://projecteuler.net/show=all
71/163
5/2/2015
Problem243:Resilience
Apositivefractionwhosenumeratorislessthanitsdenominatoriscalledaproperfraction.
Foranydenominator,d,therewillbed1properfractionsforexample,withd=12:
1/ ,2/ ,3/ ,4/ ,5/ ,6/ ,7/ ,8/ ,9/ ,10/ ,11/ .
12
12
12
12
12
12
12
12
12
12
12
Weshallcallafractionthatcannotbecancelleddownaresilientfraction.
Furthermoreweshalldefinetheresilienceofadenominator,R(d),tobetheratioofitsproperfractionsthat
areresilientforexample,R(12)=4/11.
Infact,d=12isthesmallestdenominatorhavingaresilienceR(d)<4/10.
Findthesmallestdenominatord,havingaresilienceR(d)<15499/94744.
Problem244:Sliders
YouprobablyknowthegameFifteenPuzzle.Here,insteadofnumberedtiles,wehavesevenredtilesand
eightbluetiles.
Amoveisdenotedbytheuppercaseinitialofthedirection(Left,Right,Up,Down)inwhichthetileisslid,
e.g.startingfromconfiguration(S),bythesequenceLULURwereachtheconfiguration(E):
(S)
,(E)
Foreachpath,itschecksumiscalculatedby(pseudocode):
checksum=0
checksum=(checksum243+m1)mod100000007
checksum=(checksum243+m2)mod100000007
checksum=(checksum243+mn)mod100000007
wheremkistheASCIIvalueofthekthletterinthemovesequenceandtheASCIIvaluesforthemovesare:
L 76
R
82
85
68
ForthesequenceLULURgivenabove,thechecksumwouldbe19761398.
Now,startingfromconfiguration(S),findallshortestwaystoreachconfiguration(T).
(S)
,(T)
Whatisthesumofallchecksumsforthepathshavingtheminimallength?
Problem245:Coresilience
Weshallcallafractionthatcannotbecancelleddownaresilientfraction.
Furthermoreweshalldefinetheresilienceofadenominator,R(d),tobetheratioofitsproperfractionsthat
areresilientforexample,R(12)=411.
(d)
,whereisEuler'stotientfunction.
d1
n(n)
.
Wefurtherdefinethecoresilienceofanumbern>1asC(n) =
n1
Theresilienceofanumberd>1isthen
1
https://projecteuler.net/show=all
72/163
5/2/2015
ThecoresilienceofaprimepisC(p) = p1 .
Findthesumofallcompositeintegers1<n21011,forwhichC(n)isaunitfraction.
Problem246:Tangentstoanellipse
Adefinitionforanellipseis:
GivenacirclecwithcentreMandradiusrandapointGsuchthatd(G,M)<r,thelocusofthepointsthatare
equidistantfromcandGformanellipse.
Theconstructionofthepointsoftheellipseisshownbelow.
GivenarethepointsM(2000,1500)andG(8000,1500).
GivenisalsothecirclecwithcentreMandradius15000.
ThelocusofthepointsthatareequidistantfromGandcformanellipsee.
FromapointPoutsideethetwotangentst1andt2totheellipsearedrawn.
Letthepointswheret1andt2touchtheellipsebeRandS.
ForhowmanylatticepointsPisangleRPSgreaterthan45degrees?
Problem247:Squaresunderahyperbola
Considertheregionconstrainedby1xand0y1/x.
LetS1bethelargestsquarethatcanfitunderthecurve.
LetS2bethelargestsquarethatfitsintheremainingarea,andsoon.
LettheindexofSnbethepair(left,below)indicatingthenumberofsquarestotheleftofSnandthenumber
ofsquaresbelowSn.
https://projecteuler.net/show=all
73/163
5/2/2015
Thediagramshowssomesuchsquareslabelledbynumber.
S2hasonesquaretoitsleftandnonebelow,sotheindexofS2is(1,0).
ItcanbeseenthattheindexofS32is(1,1)asistheindexofS50.
50isthelargestnforwhichtheindexofSnis(1,1).
WhatisthelargestnforwhichtheindexofSnis(3,3)?
Problem248:NumbersforwhichEulerstotientfunctionequals13!
Thefirstnumbernforwhich(n)=13!is6227180929.
Findthe150,000thsuchnumber.
Problem249:PrimeSubsetSums
LetS={2,3,5,...,4999}bethesetofprimenumberslessthan5000.
FindthenumberofsubsetsofS,thesumofwhoseelementsisaprimenumber.
Entertherightmost16digitsasyouranswer.
Problem250:250250
Findthenumberofnonemptysubsetsof{11,22,33,...,250250250250},thesumofwhoseelementsis
divisibleby250.Entertherightmost16digitsasyouranswer.
Problem251:CardanoTriplets
Atripletofpositiveintegers(a,b,c)iscalledaCardanoTripletifitsatisfiesthecondition:
Forexample,(2,1,5)isaCardanoTriplet.
Thereexist149CardanoTripletsforwhicha+b+c1000.
FindhowmanyCardanoTripletsexistsuchthata+b+c110,000,000.
Problem252:ConvexHoles
Givenasetofpointsonaplane,wedefineaconvexholetobeaconvexpolygonhavingasverticesanyof
thegivenpointsandnotcontaininganyofthegivenpointsinitsinterior(inadditiontothevertices,other
givenpointsmaylieontheperimeterofthepolygon).
Asanexample,theimagebelowshowsasetoftwentypointsandafewsuchconvexholes.Theconvex
holeshownasaredheptagonhasanareaequalto1049694.5squareunits,whichisthehighestpossible
https://projecteuler.net/show=all
74/163
5/2/2015
areaforaconvexholeonthegivensetofpoints.
Forourexample,weusedthefirst20points(T2k1,T2k),fork=1,2,,20,producedwiththepseudo
randomnumbergenerator:
S0 = 290797
Sn+1 = Sn2mod50515093
Tn = (Snmod2000)1000
i.e.(527,144),(488,732),(454,947),
Whatisthemaximumareaforaconvexholeonthesetcontainingthefirst500pointsinthepseudorandom
sequence?
Specifyyouranswerincludingonedigitafterthedecimalpoint.
Problem253:Tidyingup
Asmallchildhasanumbercaterpillarconsistingoffortyjigsawpieces,eachwithonenumberonit,which,
whenconnectedtogetherinaline,revealthenumbers1to40inorder.
Everynight,thechild'sfatherhastopickupthepiecesofthecaterpillarthathavebeenscatteredacrossthe
playroom.Hepicksupthepiecesatrandomandplacestheminthecorrectorder.
Asthecaterpillarisbuiltupinthisway,itformsdistinctsegmentsthatgraduallymergetogether.
Thenumberofsegmentsstartsatzero(nopiecesplaced),generallyincreasesuptoaboutelevenortwelve,
thentendstodropagainbeforefinishingatasinglesegment(allpiecesplaced).
Forexample:
Piece
Placed
Segments
SoFar
12
29
34
35
LetMbethemaximumnumberofsegmentsencounteredduringarandomtidyupofthecaterpillar.
Foracaterpillaroftenpieces,thenumberofpossibilitiesforeachMis
Possibilities
512
250912
1815264
1418112
144000
sothemostlikelyvalueofMis3andtheaveragevalueis385643113400=3.400732,roundedtosixdecimal
https://projecteuler.net/show=all
75/163
5/2/2015
places.
ThemostlikelyvalueofMforafortypiececaterpillaris11butwhatistheaveragevalueofM?
Giveyouranswerroundedtosixdecimalplaces.
Problem254:SumsofDigitFactorials
Definef(n)asthesumofthefactorialsofthedigitsofn.Forexample,f(342)=3!+4!+2!=32.
Definesf(n)asthesumofthedigitsoff(n).Sosf(342)=3+2=5.
Defineg(i)tobethesmallestpositiveintegernsuchthatsf(n)=i.Thoughsf(342)is5,sf(25)isalso5,and
itcanbeverifiedthatg(5)is25.
Definesg(i)asthesumofthedigitsofg(i).Sosg(5)=2+5=7.
Further,itcanbeverifiedthatg(20)is267andsg(i)for1i20is156.
Whatissg(i)for1i150?
Problem255:RoundedSquareRoots
Wedefinetheroundedsquarerootofapositiveintegernasthesquarerootofnroundedtothenearest
integer.
Thefollowingprocedure(essentiallyHeron'smethodadaptedtointegerarithmetic)findstherounded
squarerootofn:
Letdbethenumberofdigitsofthenumbern.
Ifdisodd,setx =210(d1)2.
0
Ifdiseven,setx0=710(d2)2.
Repeat:
untilxk+1=xk.
Asanexample,letusfindtheroundedsquarerootofn=4321.
nhas4digits,sox0=710(42)2=70.
Sincex2=x1,westophere.
So,afterjusttwoiterations,wehavefoundthattheroundedsquarerootof4321is66(theactualsquare
rootis65.7343137).
Thenumberofiterationsrequiredwhenusingthismethodissurprisinglylow.
Forexample,wecanfindtheroundedsquarerootofa5digitinteger(10,000n99,999)withanaverage
of3.2102888889iterations(theaveragevaluewasroundedto10decimalplaces).
Usingtheproceduredescribedabove,whatistheaveragenumberofiterationsrequiredtofindtherounded
squarerootofa14digitnumber(1013n<1014)?
Giveyouranswerroundedto10decimalplaces.
Note:Thesymbolsxandxrepresentthefloorfunctionandceilingfunctionrespectively.
Problem256:TatamiFreeRooms
Tatamiarerectangularmats,usedtocompletelycoverthefloorofaroom,withoutoverlap.
Assumingthattheonlytypeofavailabletatamihasdimensions12,thereareobviouslysomelimitationsfortheshapeandsize
oftheroomsthatcanbecovered.
https://projecteuler.net/show=all
76/163
5/2/2015
Forthisproblem,weconsideronlyrectangularroomswithintegerdimensionsa,bandevensizes=ab.
Weusetheterm'size'todenotethefloorsurfaceareaoftheroom,andwithoutlossofgeneralityweaddtheconditiona
b.
Thereisoneruletofollowwhenlayingouttatami:theremustbenopointswherecornersoffourdifferentmatsmeet.
Forexample,considerthetwoarrangementsbelowfora44room:
Thearrangementontheleftisacceptable,whereastheoneontherightisnot:ared"X"inthemiddle,marksthepointwhere
fourtatamimeet.
Becauseofthisrule,certainevensizedroomscannotbecoveredwithtatami:wecallthemtatamifreerooms.
Further,wedefineT(s)asthenumberoftatamifreeroomsofsizes.
Thesmallesttatamifreeroomhassizes=70anddimensions710.
Alltheotherroomsofsizes=70canbecoveredwithtatamitheyare:170,235and514.
Hence,T(70)=1.
Similarly,wecanverifythatT(1320)=5becausethereareexactly5tatamifreeroomsofsizes=1320:
2066,2260,2455,3044and3340.
Infact,s=1320isthesmallestroomsizesforwhichT(s)=5.
FindthesmallestroomsizesforwhichT(s)=200.
Problem257:AngularBisectors
GivenisanintegersidedtriangleABCwithsidesabc.(AB=c,BC=aandAC=b).
TheangularbisectorsofthetriangleintersectthesidesatpointsE,FandG(seepicturebelow).
ThesegmentsEF,EGandFGpartitionthetriangleABCintofoursmallertriangles:AEG,BFE,CGFandEFG.
Itcanbeproventhatforeachofthesefourtrianglestheratioarea(ABC)/area(subtriangle)isrational.
However,thereexisttrianglesforwhichsomeoralloftheseratiosareintegral.
HowmanytrianglesABCwithperimeter100,000,000existsothattheratioarea(ABC)/area(AEG)isintegral?
Problem258:AlaggedFibonaccisequence
Asequenceisdefinedas:
gk=1,for0k1999
gk=gk2000+gk1999,fork2000.
Findgkmod20092010fork=1018.
Problem259:ReachableNumbers
Apositiveintegerwillbecalledreachableifitcanresultfromanarithmeticexpressionobeyingthefollowing
rules:
Usesthedigits1through9,inthatorderandexactlyonceeach.
Anysuccessivedigitscanbeconcatenated(forexample,usingthedigits2,3and4weobtainthe
number234).
Onlythefourusualbinaryarithmeticoperations(addition,subtraction,multiplicationanddivision)are
https://projecteuler.net/show=all
77/163
5/2/2015
allowed.
Eachoperationcanbeusedanynumberoftimes,ornotatall.
Unaryminusisnotallowed.
Anynumberof(possiblynested)parenthesesmaybeusedtodefinetheorderofoperations.
Forexample,42isreachable,since(1/23)*((4*5)6)*(789)=42.
Whatisthesumofallpositivereachableintegers?
Problem260:StoneGame
Agameisplayedwiththreepilesofstonesandtwoplayers.
Atherturn,aplayerremovesoneormorestonesfromthepiles.However,ifshetakesstonesfrommore
thanonepile,shemustremovethesamenumberofstonesfromeachoftheselectedpiles.
Inotherwords,theplayerchoosessomeN>0andremoves:
Nstonesfromanysinglepileor
Nstonesfromeachofanytwopiles(2Ntotal)or
Nstonesfromeachofthethreepiles(3Ntotal).
Theplayertakingthelaststone(s)winsthegame.
Awinningconfigurationisonewherethefirstplayercanforceawin.
Forexample,(0,0,13),(0,11,11)and(5,5,5)arewinningconfigurationsbecausethefirstplayercan
immediatelyremoveallstones.
Alosingconfigurationisonewherethesecondplayercanforceawin,nomatterwhatthefirstplayerdoes.
Forexample,(0,1,2)and(1,3,3)arelosingconfigurations:anylegalmoveleavesawinningconfigurationfor
thesecondplayer.
Consideralllosingconfigurations(xi,yi,zi)wherexiyizi100.
Wecanverifythat(xi+yi+zi)=173895forthese.
Find(xi+yi+zi)where(xi,yi,zi)rangesoverthelosingconfigurations
withxiyizi1000.
Problem261:PivotalSquareSums
Letuscallapositiveintegerkasquarepivot,ifthereisapairofintegersm>0andnk,suchthatthe
sumofthe(m+1)consecutivesquaresuptokequalsthesumofthemconsecutivesquaresfrom(n+1)on:
(km)2+...+k2=(n+1)2+...+(n+m)2.
Somesmallsquarepivotsare
4:32+42=52
21:202+212=292
24:212+222+232+242=252+262+272
110:1082+1092+1102=1332+1342
Findthesumofalldistinctsquarepivots1010.
Problem262:MountainRange
Thefollowingequationrepresentsthecontinuoustopographyofamountainousregion,givingtheelevation
hatanypoint(x,y):
AmosquitointendstoflyfromA(200,200)toB(1400,1400),withoutleavingtheareagivenby
0x,y1600.
Becauseoftheinterveningmountains,itfirstrisesstraightuptoapointA',havingelevationf.Then,while
remainingatthesameelevationf,itfliesaroundanyobstaclesuntilitarrivesatapointB'directlyaboveB.
https://projecteuler.net/show=all
78/163
5/2/2015
First,determinefminwhichistheminimumconstantelevationallowingsuchatripfromAtoB,while
remaininginthespecifiedarea.
Then,findthelengthoftheshortestpathbetweenA'andB',whileflyingatthatconstantelevationfmin.
Givethatlengthasyouranswer,roundedtothreedecimalplaces.
Note:Forconvenience,theelevationfunctionshownaboveisrepeatedbelow,inaformsuitableformost
programminglanguages:
h=(50000.005*(x*x+y*y+x*y)+12.5*(x+y))*exp(abs(0.000001*(x*x+y*y)0.0015*(x+y)+0.7))
Problem263:Anengineers'dreamcometrue
Considerthenumber6.Thedivisorsof6are:1,2,3and6.
Everynumberfrom1uptoandincluding6canbewrittenasasumofdistinctdivisorsof6:
1=1,2=2,3=1+2,4=1+3,5=2+3,6=6.
Anumberniscalledapracticalnumberifeverynumberfrom1uptoandincludingncanbeexpressedasa
sumofdistinctdivisorsofn.
Apairofconsecutiveprimenumberswithadifferenceofsixiscalledasexypair(since"sex"istheLatin
wordfor"six").Thefirstsexypairis(23,29).
Wemayoccasionallyfindatriplepair,whichmeansthreeconsecutivesexyprimepairs,suchthatthe
secondmemberofeachpairisthefirstmemberofthenextpair.
Weshallcallanumbernsuchthat:
(n9,n3),(n3,n+3),(n+3,n+9)formatriplepair,and
thenumbersn8,n4,n,n+4andn+8areallpractical,
anengineersparadise.
Findthesumofthefirstfourengineersparadises.
Problem264:TriangleCentres
Considerallthetriangleshaving:
Alltheirverticesonlatticepoints.
CircumcentreattheoriginO.
OrthocentreatthepointH(5,0).
Thereareninesuchtriangleshavingaperimeter50.
Listedandshowninascendingorderoftheirperimeter,theyare:
A(4,3),B(5,0),C(4,3)
A(4,3),B(5,0),C(4,3)
A(3,4),B(5,0),C(3,4)
A(3,4),B(5,0),C(3,4)
A(0,5),B(5,0),C(0,5)
A(1,8),B(8,1),C(4,7)
A(8,1),B(1,8),C(4,7)
A(2,9),B(9,2),C(6,7)
A(9,2),B(2,9),C(6,7)
Thesumoftheirperimeters,roundedtofourdecimalplaces,is291.0089.
Findallsuchtriangleswithaperimeter105.
Enterasyouranswerthesumoftheirperimetersroundedtofourdecimalplaces.
Problem265:BinaryCircles
https://projecteuler.net/show=all
79/163
5/2/2015
2NbinarydigitscanbeplacedinacirclesothatalltheNdigitclockwisesubsequencesaredistinct.
ForN=3,twosuchcirculararrangementsarepossible,ignoringrotations:
Forthefirstarrangement,the3digitsubsequences,inclockwiseorder,are:
000,001,010,101,011,111,110and100.
Eachcirculararrangementcanbeencodedasanumberbyconcatenatingthebinarydigitsstartingwiththe
subsequenceofallzerosasthemostsignificantbitsandproceedingclockwise.Thetwoarrangementsfor
N=3arethusrepresentedas23and29:
000101112=23
000111012=29
CallingS(N)thesumoftheuniquenumericrepresentations,wecanseethatS(3)=23+29=52.
FindS(5).
Problem266:PseudoSquareRoot
Thedivisorsof12are:1,2,3,4,6and12.
Thelargestdivisorof12thatdoesnotexceedthesquarerootof12is3.
Weshallcallthelargestdivisorofanintegernthatdoesnotexceedthesquarerootofnthepseudosquare
root(PSR)ofn.
ItcanbeseenthatPSR(3102)=47.
Letpbetheproductoftheprimesbelow190.
FindPSR(p)mod1016.
Problem267:Billionaire
Youaregivenauniqueinvestmentopportunity.
Startingwith1ofcapital,youcanchooseafixedproportion,f,ofyourcapitaltobetonafaircointoss
repeatedlyfor1000tosses.
Yourreturnisdoubleyourbetforheadsandyouloseyourbetfortails.
Forexample,iff=1/4,forthefirsttossyoubet0.25,andifheadscomesupyouwin0.5andsothenhave
1.5.Youthenbet0.375andifthesecondtossistails,youhave1.125.
Choosingftomaximizeyourchancesofhavingatleast1,000,000,000after1,000flips,whatisthechance
thatyoubecomeabillionaire?
Allcomputationsareassumedtobeexact(norounding),butgiveyouranswerroundedto12digitsbehind
thedecimalpointintheform0.abcdefghijkl.
Problem268:Countingnumberswithatleastfourdistinctprimefactorsless
than100
Itcanbeverifiedthatthereare23positiveintegerslessthan1000thataredivisiblebyatleastfourdistinct
primeslessthan100.
Findhowmanypositiveintegerslessthan1016aredivisiblebyatleastfourdistinctprimeslessthan100.
Problem269:Polynomialswithatleastoneintegerroot
ArootorzeroofapolynomialP(x)isasolutiontotheequationP(x)=0.
DefinePnasthepolynomialwhosecoefficientsarethedigitsofn.
https://projecteuler.net/show=all
80/163
5/2/2015
Forexample,P5703(x)=5x3+7x2+3.
Wecanseethat:
Pn(0)isthelastdigitofn,
Pn(1)isthesumofthedigitsofn,
Pn(10)isnitself.
DefineZ(k)asthenumberofpositiveintegers,n,notexceedingkforwhichthepolynomialPnhasatleast
oneintegerroot.
ItcanbeverifiedthatZ(100000)is14696.
WhatisZ(1016)?
Problem270:CuttingSquares
AsquarepieceofpaperwithintegerdimensionsNNisplacedwithacornerattheoriginandtwoofits
sidesalongthexandyaxes.Then,wecutituprespectingthefollowingrules:
Weonlymakestraightcutsbetweentwopointslyingondifferentsidesofthesquare,andhaving
integercoordinates.
Twocutscannotcross,butseveralcutscanmeetatthesameborderpoint.
Proceeduntilnomorelegalcutscanbemade.
Countinganyreflectionsorrotationsasdistinct,wecallC(N)thenumberofwaystocutanNNsquare.For
example,C(1)=2andC(2)=30(shownbelow).
WhatisC(30)mod108?
Problem271:ModularCubes,part1
Forapositivenumbern,defineS(n)asthesumoftheintegersx,forwhich1<x<nand
x31modn.
Whenn=91,thereare8possiblevaluesforx,namely:9,16,22,29,53,74,79,81.
Thus,S(91)=9+16+22+29+53+74+79+81=363.
FindS(13082761331670030).
Problem272:ModularCubes,part2
Forapositivenumbern,defineC(n)asthenumberoftheintegersx,forwhich1<x<nand
x31modn.
Whenn=91,thereare8possiblevaluesforx,namely:9,16,22,29,53,74,79,81.
Thus,C(91)=8.
https://projecteuler.net/show=all
81/163
5/2/2015
Findthesumofthepositivenumbersn1011forwhichC(n)=242.
Problem273:SumofSquares
Considerequationsoftheform:a2+b2=N,0ab,a,bandNinteger.
ForN=65therearetwosolutions:
a=1,b=8anda=4,b=7.
WecallS(N)thesumofthevaluesofaofallsolutionsofa2+b2=N,0ab,a,bandNinteger.
ThusS(65)=1+4=5.
FindS(N),forallsquarefreeNonlydivisiblebyprimesoftheform4k+1with4k+1<150.
Problem274:DivisibilityMultipliers
Foreachintegerp>1coprimeto10thereisapositivedivisibilitymultiplierm<pwhichpreserves
divisibilitybypforthefollowingfunctiononanypositiveinteger,n:
f(n)=(allbutthelastdigitofn)+(thelastdigitofn)*m
Thatis,ifmisthedivisibilitymultiplierforp,thenf(n)isdivisiblebypifandonlyifnisdivisiblebyp.
(Whennismuchlargerthanp,f(n)willbelessthannandrepeatedapplicationoffprovidesamultiplicative
divisibilitytestforp.)
Forexample,thedivisibilitymultiplierfor113is34.
f(76275)=7627+5*34=7797:76275and7797arebothdivisibleby113
f(12345)=1234+5*34=1404:12345and1404arebothnotdivisibleby113
Thesumofthedivisibilitymultipliersfortheprimesthatarecoprimeto10andlessthan1000is39517.
Whatisthesumofthedivisibilitymultipliersfortheprimesthatarecoprimeto10andlessthan107?
Problem275:BalancedSculptures
Letusdefineabalancedsculptureofordernasfollows:
Apolyominomadeupofn+1tilesknownastheblocks(ntiles)
andtheplinth(remainingtile)
theplinthhasitscentreatposition(x=0,y=0)
theblockshaveycoordinatesgreaterthanzero(sotheplinthistheuniquelowesttile)
thecentreofmassofalltheblocks,combined,hasxcoordinateequaltozero.
Whencountingthesculptures,anyarrangementswhicharesimplyreflectionsabouttheyaxis,arenot
countedasdistinct.Forexample,the18balancedsculpturesoforder6areshownbelownotethateach
pairofmirrorimages(abouttheyaxis)iscountedasonesculpture:
https://projecteuler.net/show=all
82/163
5/2/2015
Thereare964balancedsculpturesoforder10and360505oforder15.
Howmanybalancedsculpturesarethereoforder18?
Problem276:PrimitiveTriangles
Considerthetriangleswithintegersidesa,bandcwithabc.
Anintegersidedtriangle(a,b,c)iscalledprimitiveifgcd(a,b,c)=1.
Howmanyprimitiveintegersidedtrianglesexistwithaperimeternotexceeding10000000?
Problem277:AModifiedCollatzsequence
AmodifiedCollatzsequenceofintegersisobtainedfromastartingvaluea1inthefollowingway:
an+1=an/3ifanisdivisibleby3.Weshalldenotethisasalargedownwardstep,"D".
an+1=(4an+2)/3ifandividedby3givesaremainderof1.Weshalldenotethisasanupwardstep,"U".
an+1=(2an1)/3ifandividedby3givesaremainderof2.Weshalldenotethisasasmalldownwardstep,
"d".
Thesequenceterminateswhensomean=1.
Givenanyinteger,wecanlistoutthesequenceofsteps.
Forinstanceifa1=231,thenthesequence{an}={231,77,51,17,11,7,10,14,9,3,1}correspondstothesteps
"DdDddUUdDD".
Ofcourse,thereareothersequencesthatbeginwiththatsamesequence"DdDddUUdDD....".
Forinstance,ifa1=1004064,thenthesequenceisDdDddUUdDDDdUDUUUdDdUUDDDUdDD.
Infact,1004064isthesmallestpossiblea1>106thatbeginswiththesequenceDdDddUUdDD.
Whatisthesmallesta1>1015thatbeginswiththesequence
"UDDDUdddDDUDDddDdDddDDUDDdUUDd"?
Problem278:LinearCombinationsofSemiprimes
Giventhevaluesofintegers1<a1<a2<...<an,considerthelinearcombination
q1a1+q2a2+...+qnan=b,usingonlyintegervaluesqk0.
Notethatforagivensetofak,itmaybethatnotallvaluesofbarepossible.
Forinstance,ifa1=5anda2=7,therearenoq10andq20suchthatbcouldbe
1,2,3,4,6,8,9,11,13,16,18or23.
Infact,23isthelargestimpossiblevalueofbfora1=5anda2=7.
Wethereforecallf(5,7)=23.
Similarly,itcanbeshownthatf(6,10,15)=29andf(14,22,77)=195.
Findf(p*q,p*r,q*r),wherep,qandrareprimenumbersandp<q<r<5000.
Problem279:Triangleswithintegralsidesandanintegralangle
Howmanytrianglesaretherewithintegralsides,atleastoneintegralangle(measuredindegrees),anda
perimeterthatdoesnotexceed108?
Problem280:Antandseeds
Alaboriousantwalksrandomlyona5x5grid.Thewalkstartsfromthecentralsquare.Ateachstep,theant
movestoanadjacentsquareatrandom,withoutleavingthegridthusthereare2,3or4possiblemovesat
eachstepdependingontheant'sposition.
Atthestartofthewalk,aseedisplacedoneachsquareofthelowerrow.Whentheantisn'tcarryingaseed
andreachesasquareofthelowerrowcontainingaseed,itwillstarttocarrytheseed.Theantwilldropthe
https://projecteuler.net/show=all
83/163
5/2/2015
seedonthefirstemptysquareoftheupperrowiteventuallyreaches.
What'stheexpectednumberofstepsuntilallseedshavebeendroppedinthetoprow?
Giveyouranswerroundedto6decimalplaces.
Problem281:PizzaToppings
Youaregivenapizza(perfectcircle)thathasbeencutintomnequalpiecesandyouwanttohaveexactly
onetoppingoneachslice.
Letf(m,n)denotethenumberofwaysyoucanhavetoppingsonthepizzawithmdifferenttoppings(m2),
usingeachtoppingonexactlynslices(n1).
Reflectionsareconsidereddistinct,rotationsarenot.
Thus,forinstance,f(2,1)=1,f(2,2)=f(3,1)=2andf(3,2)=16.
f(3,2)isshownbelow:
Findthesumofallf(m,n)suchthatf(m,n)1015.
Problem282:TheAckermannfunction
Fornonnegativeintegersm,n,theAckermannfunctionA(m,n)isdefinedasfollows:
ForexampleA(1,0)=2,A(2,2)=7andA(3,4)=125.
Find
A(n,n)andgiveyouranswermod148.
Problem283:Integersidedtrianglesforwhichthearea/perimeterratiois
integral
Considerthetrianglewithsides6,8and10.Itcanbeseenthattheperimeterandtheareaarebothequalto
24.Sothearea/perimeterratioisequalto1.
Consideralsothetrianglewithsides13,14and15.Theperimeterequals42whiletheareaisequalto84.
Soforthistrianglethearea/perimeterratioisequalto2.
Findthesumoftheperimetersofallintegersidedtrianglesforwhichthearea/perimeterratiosareequalto
positiveintegersnotexceeding1000.
Problem284:SteadySquares
The3digitnumber376inthedecimalnumberingsystemisanexampleofnumberswiththespecial
propertythatitssquareendswiththesamedigits:3762=141376.Let'scallanumberwiththispropertya
steadysquare.
Steadysquarescanalsobeobservedinothernumberingsystems.Inthebase14numberingsystem,the3
digitnumberc37isalsoasteadysquare:c372=aa0c37,andthesumofitsdigitsisc+3+7=18inthesame
numberingsystem.Thelettersa,b,canddareusedforthe10,11,12and13digitsrespectively,ina
mannersimilartothehexadecimalnumberingsystem.
For1n9,thesumofthedigitsofallthendigitsteadysquaresinthebase14numberingsystemis2d8
(582decimal).Steadysquareswithleading0'sarenotallowed.
Findthesumofthedigitsofallthendigitsteadysquaresinthebase14numberingsystemfor
1n10000(decimal)andgiveyouranswerinthebase14systemusinglowercaseletterswhere
necessary.
https://projecteuler.net/show=all
84/163
5/2/2015
Problem285:Pythagoreanodds
Albertchoosesapositiveintegerk,thentworealnumbersa,barerandomlychosenintheinterval[0,1]with
uniformdistribution.
Thesquarerootofthesum(ka+1)2+(kb+1)2isthencomputedandroundedtothenearestinteger.Ifthe
resultisequaltok,hescoreskpointsotherwisehescoresnothing.
Forexample,ifk=6,a=0.2andb=0.85,then(ka+1)2+(kb+1)2=42.05.
Thesquarerootof42.05is6.484...andwhenroundedtothenearestinteger,itbecomes6.
Thisisequaltok,sohescores6points.
Itcanbeshownthatifheplays10turnswithk=1,k=2,...,k=10,theexpectedvalueofhistotalscore,
roundedtofivedecimalplaces,is10.20914.
Ifheplays105turnswithk=1,k=2,k=3,...,k=105,whatistheexpectedvalueofhistotalscore,rounded
tofivedecimalplaces?
Problem286:Scoringprobabilities
Barbaraisamathematicianandabasketballplayer.Shehasfoundthattheprobabilityofscoringapoint
whenshootingfromadistancexisexactly(1x/q),whereqisarealconstantgreaterthan50.
Duringeachpracticerun,shetakesshotsfromdistancesx=1,x=2,...,x=50and,accordingtoher
records,shehaspreciselya2%chancetoscoreatotalofexactly20points.
Findqandgiveyouranswerroundedto10decimalplaces.
Problem287:Quadtreeencoding(asimplecompressionalgorithm)
Thequadtreeencodingallowsustodescribea2N2Nblackandwhiteimageasasequenceofbits(0and
1).Thosesequencesaretobereadfromlefttorightlikethis:
thefirstbitdealswiththecomplete2N2Nregion
"0"denotesasplit:
thecurrent2n2nregionisdividedinto4subregionsofdimension2n12n1,
thenextbitscontainsthedescriptionofthetopleft,topright,bottomleftandbottomrightsubregions
inthatorder
"10"indicatesthatthecurrentregioncontainsonlyblackpixels
"11"indicatesthatthecurrentregioncontainsonlywhitepixels.
Considerthefollowing44image(coloredmarksdenoteplaceswhereasplitcanoccur):
Thisimagecanbedescribedbyseveralsequences,forexample:"001010101001011111011010101010",
oflength30,or
"0100101111101110",oflength16,whichistheminimalsequenceforthisimage.
ForapositiveintegerN,defineDNasthe2N2Nimagewiththefollowingcoloringscheme:
thepixelwithcoordinatesx=0,y=0correspondstothebottomleftpixel,
if(x2N1)2+(y2N1)222N2thenthepixelisblack,
otherwisethepixeliswhite.
WhatisthelengthoftheminimalsequencedescribingD24?
https://projecteuler.net/show=all
85/163
5/2/2015
Problem288:Anenormousfactorial
ForanyprimepthenumberN(p,q)isdefinedbyN(p,q)=n=0toqTn*pn
withTngeneratedbythefollowingrandomnumbergenerator:
S0=290797
Sn+1=Sn2mod50515093
Tn=Snmodp
LetNfac(p,q)bethefactorialofN(p,q).
LetNF(p,q)bethenumberoffactorspinNfac(p,q).
YouaregiventhatNF(3,10000)mod320=624955285.
FindNF(61,107)mod6110
Problem289:EulerianCycles
LetC(x,y)beacirclepassingthroughthepoints(x,y),(x,y+1),(x+1,y)and(x+1,y+1).
Forpositiveintegersmandn,letE(m,n)beaconfigurationwhichconsistsofthemncircles:
{C(x,y):0x<m,0y<n,xandyareintegers}
AnEuleriancycleonE(m,n)isaclosedpaththatpassesthrougheacharcexactlyonce.
ManysuchpathsarepossibleonE(m,n),butweareonlyinterestedinthosewhicharenotselfcrossing:A
noncrossingpathjusttouchesitselfatlatticepoints,butitnevercrossesitself.
TheimagebelowshowsE(3,3)andanexampleofanEuleriannoncrossingpath.
LetL(m,n)bethenumberofEuleriannoncrossingpathsonE(m,n).
Forexample,L(1,2)=2,L(2,2)=37andL(3,3)=104290.
FindL(6,10)mod1010.
Problem290:DigitalSignature
Howmanyintegers0n<1018havethepropertythatthesumofthedigitsofnequalsthesumofdigitsof
137n?
Problem291:PanaitopolPrimes
AprimenumberpiscalledaPanaitopolprimeif
forsomepositiveintegers
xandy.
FindhowmanyPanaitopolprimesarelessthan51015.
https://projecteuler.net/show=all
86/163
5/2/2015
Problem292:PythagoreanPolygons
Weshalldefineapythagoreanpolygontobeaconvexpolygonwiththefollowingproperties:
thereareatleastthreevertices,
nothreeverticesarealigned,
eachvertexhasintegercoordinates,
eachedgehasintegerlength.
Foragivenintegern,defineP(n)asthenumberofdistinctpythagoreanpolygonsforwhichtheperimeteris
n.
Pythagoreanpolygonsshouldbeconsidereddistinctaslongasnoneisatranslationofanother.
YouaregiventhatP(4)=1,P(30)=3655andP(60)=891045.
FindP(120).
Problem293:PseudoFortunateNumbers
AnevenpositiveintegerNwillbecalledadmissible,ifitisapowerof2oritsdistinctprimefactorsare
consecutiveprimes.
Thefirsttwelveadmissiblenumbersare2,4,6,8,12,16,18,24,30,32,36,48.
IfNisadmissible,thesmallestintegerM>1suchthatN+Misprime,willbecalledthepseudoFortunate
numberforN.
Forexample,N=630isadmissiblesinceitisevenanditsdistinctprimefactorsaretheconsecutiveprimes
2,3,5and7.
Thenextprimenumberafter631is641hence,thepseudoFortunatenumberfor630isM=11.
ItcanalsobeseenthatthepseudoFortunatenumberfor16is3.
FindthesumofalldistinctpseudoFortunatenumbersforadmissiblenumbersNlessthan109.
Problem294:Sumofdigitsexperience#23
Forapositiveintegerk,defined(k)asthesumofthedigitsofkinitsusualdecimalrepresentation.Thus
d(42)=4+2=6.
Forapositiveintegern,defineS(n)asthenumberofpositiveintegersk<10nwiththefollowingproperties:
kisdivisibleby23and
d(k)=23.
YouaregiventhatS(9)=263626andS(42)=6377168878570056.
FindS(1112)andgiveyouranswermod109.
Problem295:Lenticularholes
Wecalltheconvexareaenclosedbytwocirclesalenticularholeif:
Thecentresofbothcirclesareonlatticepoints.
Thetwocirclesintersectattwodistinctlatticepoints.
Theinterioroftheconvexareaenclosedbybothcirclesdoesnotcontainanylatticepoints.
Considerthecircles:
C0:x2+y2=25
C1:(x+4)2+(y4)2=1
C2:(x12)2+(y4)2=65
ThecirclesC0,C1andC2aredrawninthepicturebelow.
https://projecteuler.net/show=all
87/163
5/2/2015
C0andC1formalenticularhole,aswellasC0andC2.
Wecallanorderedpairofpositiverealnumbers(r1,r2)alenticularpairifthereexisttwocircleswithradiir1
andr2thatformalenticularhole.Wecanverifythat(1,5)and(5,65)arethelenticularpairsofthe
exampleabove.
LetL(N)bethenumberofdistinctlenticularpairs(r1,r2)forwhich0<r1r2N.
WecanverifythatL(10)=30andL(100)=3442.
FindL(100000).
Problem296:AngularBisectorandTangent
GivenisanintegersidedtriangleABCwithBCACAB.
kistheangularbisectorofangleACB.
misthetangentatCtothecircumscribedcircleofABC.
nisalineparalleltomthroughB.
TheintersectionofnandkiscalledE.
HowmanytrianglesABCwithaperimeternotexceeding100000existsuchthatBEhasintegrallength?
Problem297:ZeckendorfRepresentation
EachnewtermintheFibonaccisequenceisgeneratedbyaddingtheprevioustwoterms.
Startingwith1and2,thefirst10termswillbe:1,2,3,5,8,13,21,34,55,89.
EverypositiveintegercanbeuniquelywrittenasasumofnonconsecutivetermsoftheFibonaccisequence.
https://projecteuler.net/show=all
88/163
5/2/2015
Forexample,100=3+8+89.
SuchasumiscalledtheZeckendorfrepresentationofthenumber.
Foranyintegern>0,letz(n)bethenumberoftermsintheZeckendorfrepresentationofn.
Thus,z(5)=1,z(14)=2,z(100)=3etc.
Also,for0<n<106,z(n)=7894453.
Findz(n)for0<n<1017.
Problem298:SelectiveAmnesia
LarryandRobinplayamemorygameinvolvingofasequenceofrandomnumbersbetween1and10,
inclusive,thatarecalledoutoneatatime.Eachplayercanrememberupto5previousnumbers.Whenthe
callednumberisinaplayer'smemory,thatplayerisawardedapoint.Ifit'snot,theplayeraddsthecalled
numbertohismemory,removinganothernumberifhismemoryisfull.
Bothplayersstartwithemptymemories.Bothplayersalwaysaddnewmissednumberstotheirmemorybut
useadifferentstrategyindecidingwhichnumbertoremove:
Larry'sstrategyistoremovethenumberthathasn'tbeencalledinthelongesttime.
Robin'sstrategyistoremovethenumberthat'sbeeninthememorythelongesttime.
Examplegame:
Turn
1
2
3
4
5
6
7
8
9
10
Called
number
1
2
4
6
1
8
10
2
4
1
Larry's Larry's
memory score
1
0
1,2
0
1,2,4
0
1,2,4,6
0
1,2,4,6
1
1,2,4,6,8
1
1,4,6,8,10
1
1,2,6,8,10
1
1,2,4,8,10
1
1,2,4,8,10
2
Robin's Robin's
memory score
1
0
1,2
0
1,2,4
0
1,2,4,6
0
1,2,4,6
1
1,2,4,6,8
1
2,4,6,8,10
1
2,4,6,8,10
2
2,4,6,8,10
3
1,4,6,8,10
3
DenotingLarry'sscorebyLandRobin'sscorebyR,whatistheexpectedvalueof|LR|after50turns?
Giveyouranswerroundedtoeightdecimalplacesusingtheformatx.xxxxxxxx.
Problem299:Threesimilartriangles
Fourpointswithintegercoordinatesareselected:
A(a,0),B(b,0),C(0,c)andD(0,d),with0<a<band0<c<d.
PointP,alsowithintegercoordinates,ischosenonthelineACsothatthethreetrianglesABP,CDPand
BDPareallsimilar.
Itiseasytoprovethatthethreetrianglescanbesimilar,onlyifa=c.
So,giventhata=c,wearelookingfortriplets(a,b,d)suchthatatleastonepointP(withintegercoordinates)
https://projecteuler.net/show=all
89/163
5/2/2015
existsonAC,makingthethreetrianglesABP,CDPandBDPallsimilar.
Forexample,if(a,b,d)=(2,3,4),itcanbeeasilyverifiedthatpointP(1,1)satisfiestheabovecondition.Note
thatthetriplets(2,3,4)and(2,4,3)areconsideredasdistinct,althoughpointP(1,1)iscommonforboth.
Ifb+d<100,thereare92distincttriplets(a,b,d)suchthatpointPexists.
Ifb+d<100000,thereare320471distincttriplets(a,b,d)suchthatpointPexists.
Ifb+d<100000000,howmanydistincttriplets(a,b,d)aretheresuchthatpointPexists?
Problem300:Proteinfolding
Inaverysimplifiedform,wecanconsiderproteinsasstringsconsistingofhydrophobic(H)andpolar(P)
elements,e.g.HHPPHHHPHHPH.
Forthisproblem,theorientationofaproteinisimportante.g.HPPisconsidereddistinctfromPPH.Thus,
thereare2ndistinctproteinsconsistingofnelements.
Whenoneencountersthesestringsinnature,theyarealwaysfoldedinsuchawaythatthenumberofHH
contactpointsisaslargeaspossible,sincethisisenergeticallyadvantageous.
Asaresult,theHelementstendtoaccumulateintheinnerpart,withthePelementsontheoutside.
Naturalproteinsarefoldedinthreedimensionsofcourse,butwewillonlyconsiderproteinfoldingintwo
dimensions.
Thefigurebelowshowstwopossiblewaysthatourexampleproteincouldbefolded(HHcontactpointsare
shownwithreddots).
ThefoldingonthelefthasonlysixHHcontactpoints,thusitwouldneveroccurnaturally.
Ontheotherhand,thefoldingontherighthasnineHHcontactpoints,whichisoptimalforthisstring.
AssumingthatHandPelementsareequallylikelytooccurinanypositionalongthestring,theaverage
numberofHHcontactpointsinanoptimalfoldingofarandomproteinstringoflength8turnsouttobe
850/28=3.3203125.
WhatistheaveragenumberofHHcontactpointsinanoptimalfoldingofarandomproteinstringoflength
15?
Giveyouranswerusingasmanydecimalplacesasnecessaryforanexactresult.
Problem301:Nim
Nimisagameplayedwithheapsofstones,wheretwoplayerstakeitinturntoremoveanynumberof
stonesfromanyheapuntilnostonesremain.
We'llconsiderthethreeheapnormalplayversionofNim,whichworksasfollows:
Atthestartofthegametherearethreeheapsofstones.
Onhisturntheplayerremovesanypositivenumberofstonesfromanysingleheap.
Thefirstplayerunabletomove(becausenostonesremain)loses.
If(n1,n2,n3)indicatesaNimpositionconsistingofheapsofsizen1,n2andn3thenthereisasimple
functionX(n1,n2,n3)thatyoumaylookuporattempttodeduceforyourselfthatreturns:
zeroif,withperfectstrategy,theplayerabouttomovewilleventuallyloseor
nonzeroif,withperfectstrategy,theplayerabouttomovewilleventuallywin.
ForexampleX(1,2,3)=0because,nomatterwhatthecurrentplayerdoes,hisopponentcanrespondwitha
movethatleavestwoheapsofequalsize,atwhichpointeverymovebythecurrentplayercanbemirrored
byhisopponentuntilnostonesremainsothecurrentplayerloses.Toillustrate:
currentplayermovesto(1,2,1)
opponentmovesto(1,0,1)
currentplayermovesto(0,0,1)
opponentmovesto(0,0,0),andsowins.
Forhowmanypositiveintegersn230doesX(n,2n,3n)=0?
https://projecteuler.net/show=all
90/163
5/2/2015
Problem302:StrongAchillesNumbers
Apositiveintegernispowerfulifp2isadivisorofnforeveryprimefactorpinn.
Apositiveintegernisaperfectpowerifncanbeexpressedasapowerofanotherpositiveinteger.
ApositiveintegernisanAchillesnumberifnispowerfulbutnotaperfectpower.Forexample,864and
1800areAchillesnumbers:864=2533and1800=233252.
WeshallcallapositiveintegerSaStrongAchillesnumberifbothSand(S)areAchillesnumbers.1
Forexample,864isaStrongAchillesnumber:(864)=288=2532.However,1800isn'taStrongAchilles
numberbecause:(1800)=480=253151.
Thereare7StrongAchillesnumbersbelow104and656below108.
HowmanyStrongAchillesnumbersaretherebelow1018?
1denotesEuler'stotientfunction.
Problem303:Multipleswithsmalldigits
Forapositiveintegern,definef(n)astheleastpositivemultipleofnthat,writteninbase10,usesonlydigits
2.
Thusf(2)=2,f(3)=12,f(7)=21,f(42)=210,f(89)=1121222.
Also,
Find
Problem304:Primonacci
Foranypositiveintegernthefunctionnext_prime(n)returnsthesmallestprimep
suchthatp>n.
Thesequencea(n)isdefinedby:
a(1)=next_prime(1014)anda(n)=next_prime(a(n1))forn>1.
Thefibonaccisequencef(n)isdefinedby:f(0)=0,f(1)=1andf(n)=f(n1)+f(n2)forn>1.
Thesequenceb(n)isdefinedasf(a(n)).
Findb(n)for1n100000.Giveyouranswermod1234567891011.
Problem305:ReflexivePosition
Let'scallSthe(infinite)stringthatismadebyconcatenatingtheconsecutivepositiveintegers(startingfrom
1)writtendowninbase10.
Thus,S=1234567891011121314151617181920212223242...
It'seasytoseethatanynumberwillshowupaninfinitenumberoftimesinS.
Let'scallf(n)thestartingpositionofthenthoccurrenceofninS.
Forexample,f(1)=1,f(5)=81,f(12)=271andf(7780)=111111365.
Findf(3k)for1k13.
Problem306:PaperstripGame
https://projecteuler.net/show=all
91/163
5/2/2015
ThefollowinggameisaclassicexampleofCombinatorialGameTheory:
Twoplayersstartwithastripofnwhitesquaresandtheytakealternateturns.
Oneachturn,aplayerpickstwocontiguouswhitesquaresandpaintsthemblack.
Thefirstplayerwhocannotmakeamoveloses.
Ifn=1,therearenovalidmoves,sothefirstplayerlosesautomatically.
Ifn=2,thereisonlyonevalidmove,afterwhichthesecondplayerloses.
Ifn=3,therearetwovalidmoves,butbothleaveasituationwherethesecondplayerloses.
Ifn=4,therearethreevalidmovesforthefirstplayershecanwinthegamebypaintingthetwo
middlesquares.
Ifn=5,therearefourvalidmovesforthefirstplayer(shownbelowinred)butnomatterwhatshe
does,thesecondplayer(blue)wins.
So,for1n5,thereare3valuesofnforwhichthefirstplayercanforceawin.
Similarly,for1n50,thereare40valuesofnforwhichthefirstplayercanforceawin.
For1n1000000,howmanyvaluesofnarethereforwhichthefirstplayercanforceawin?
Problem307:ChipDefects
kdefectsarerandomlydistributedamongstnintegratedcircuitchipsproducedbyafactory(anynumberof
defectsmaybefoundonachipandeachdefectisindependentoftheotherdefects).
Letp(k,n)representtheprobabilitythatthereisachipwithatleast3defects.
Forinstancep(3,7)0.0204081633.
Findp(20000,1000000)andgiveyouranswerroundedto10decimalplacesintheform0.abcdefghij
Problem308:AnamazingPrimegeneratingAutomaton
AprogramwrittenintheprogramminglanguageFractranconsistsofalistoffractions.
TheinternalstateoftheFractranVirtualMachineisapositiveinteger,whichisinitiallysettoaseedvalue.
EachiterationofaFractranprogrammultipliesthestateintegerbythefirstfractioninthelistwhichwillleave
itaninteger.
Forexample,oneoftheFractranprogramsthatJohnHortonConwaywroteforprimegenerationconsistsof
thefollowing14fractions:
17
78
19
23
29
77
95
77
1
11
13
15
1
55
,
,
,
,
,
,
,
,
,
,
,
,
,
.
91
85
51
38
33
29
23
19
17
13
11
2
7
1
Startingwiththeseedinteger2,successiveiterationsoftheprogramproducethesequence:
15,825,725,1925,2275,425,...,68,4,30,...,136,8,60,...,544,32,240,...
Thepowersof2thatappearinthissequenceare22,23,25,...
Itcanbeshownthatallthepowersof2inthissequencehaveprimeexponentsandthatalltheprimes
appearasexponentsofpowersof2,inproperorder!
IfsomeoneusestheaboveFractranprogramtosolveProjectEulerProblem7(findthe10001stprime),how
manyiterationswouldbeneededuntiltheprogramproduces210001stprime?
Problem309:IntegerLadders
Intheclassic"CrossingLadders"problem,wearegiventhelengthsxandyoftwoladdersrestingonthe
oppositewallsofanarrow,levelstreet.Wearealsogiventheheighthabovethestreetwherethetwo
ladderscrossandweareaskedtofindthewidthofthestreet(w).
https://projecteuler.net/show=all
92/163
5/2/2015
Here,weareonlyconcernedwithinstanceswhereallfourvariablesarepositiveintegers.
Forexample,ifx=70,y=119andh=30,wecancalculatethatw=56.
Infact,forintegervaluesx,y,hand0<x<y<200,thereareonlyfivetriplets(x,y,h)producinginteger
solutionsforw:
(70,119,30),(74,182,21),(87,105,35),(100,116,35)and(119,175,40).
Forintegervaluesx,y,hand0<x<y<1000000,howmanytriplets(x,y,h)produceintegersolutionsfor
w?
Problem310:NimSquare
AliceandBobplaythegameNimSquare.
NimSquareisjustlikeordinarythreeheapnormalplayNim,buttheplayersmayonlyremoveasquare
numberofstonesfromaheap.
Thenumberofstonesinthethreeheapsisrepresentedbytheorderedtriple(a,b,c).
If0abc29thenthenumberoflosingpositionsforthenextplayeris1160.
Findthenumberoflosingpositionsforthenextplayerif0abc100000.
Problem311:BiclinicIntegralQuadrilaterals
ABCDisaconvex,integersidedquadrilateralwith1AB<BC<CD<AD.
BDhasintegerlength.OisthemidpointofBD.AOhasintegerlength.
We'llcallABCDabiclinicintegralquadrilateralifAO=COBO=DO.
Forexample,thefollowingquadrilateralisabiclinicintegralquadrilateral:
AB=19,BC=29,CD=37,AD=43,BD=48andAO=CO=23.
LetB(N)bethenumberofdistinctbiclinicintegralquadrilateralsABCDthatsatisfyAB2+BC2+CD2+AD2N.
WecanverifythatB(10000)=49andB(1000000)=38239.
FindB(10000000000).
Problem312:CyclicpathsonSierpiskigraphs
https://projecteuler.net/show=all
93/163
5/2/2015
ASierpiskigraphoforder1(S1)isanequilateraltriangle.
Sn+1isobtainedfromSnbypositioningthreecopiesofSnsothateverypairofcopieshasonecommon
corner.
LetC(n)bethenumberofcyclesthatpassexactlyoncethroughalltheverticesofSn.
Forexample,C(3)=8becauseeightsuchcyclescanbedrawnonS3,asshownbelow:
Itcanalsobeverifiedthat:
C(1)=C(2)=1
C(5)=71328803586048
C(10000)mod108=37652224
C(10000)mod138=617720485
FindC(C(C(10000)))mod138.
Problem313:Slidinggame
Inaslidinggameacountermayslidehorizontallyorverticallyintoanemptyspace.Theobjectiveofthe
gameistomovetheredcounterfromthetopleftcornerofagridtothebottomrightcornerthespace
alwaysstartsinthebottomrightcorner.Forexample,thefollowingsequenceofpicturesshowhowthe
gamecanbecompletedinfivemovesona2by2grid.
LetS(m,n)representtheminimumnumberofmovestocompletethegameonanmbyngrid.Forexample,
itcanbeverifiedthatS(5,4)=25.
https://projecteuler.net/show=all
94/163
5/2/2015
Thereareexactly5482gridsforwhichS(m,n)=p2,wherep<100isprime.
HowmanygridsdoesS(m,n)=p2,wherep<106isprime?
Problem314:TheMouseontheMoon
Themoonhasbeenopenedup,andlandcanbeobtainedforfree,butthereisacatch.Youhavetobuilda
wallaroundthelandthatyoustakeout,andbuildingawallonthemoonisexpensive.Everycountryhas
beenallotteda500mby500msquarearea,buttheywillpossessonlythatareawhichtheywallin.251001
postshavebeenplacedinarectangulargridwith1meterspacing.Thewallmustbeaclosedseriesof
straightlines,eachlinerunningfromposttopost.
Thebiggercountriesofcoursehavebuilta2000mwallenclosingtheentire250000m2area.TheDuchyof
GrandFenwick,hasatighterbudget,andhasaskedyou(theirRoyalProgrammer)tocomputewhatshape
wouldgetbestmaximumenclosedarea/walllengthratio.
Youhavedonesomepreliminarycalculationsonasheetofpaper.Fora2000meterwallenclosingthe250
000m2areatheenclosedarea/walllengthratiois125.
Althoughnotallowed,buttogetanideaifthisisanythingbetter:ifyouplaceacircleinsidethesquarearea
touchingthefoursidestheareawillbeequalto*2502m2andtheperimeterwillbe*500m,sothe
enclosedarea/walllengthratiowillalsobe125.
However,ifyoucutofffromthesquarefourtriangleswithsides75m,75mand752mthetotalarea
becomes238750m2andtheperimeterbecomes1400+3002m.Sothisgivesanenclosedarea/wall
lengthratioof130.87,whichissignificantlybetter.
https://projecteuler.net/show=all
95/163
5/2/2015
Findthemaximumenclosedarea/walllengthratio.
Giveyouranswerroundedto8placesbehindthedecimalpointintheformabc.defghijk.
Problem315:Digitalrootclocks
SamandMaxareaskedtotransformtwodigitalclocksintotwo"digitalroot"clocks.
Adigitalrootclockisadigitalclockthatcalculatesdigitalrootsstepbystep.
Whenaclockisfedanumber,itwillshowitandthenitwillstartthecalculation,showingalltheintermediate
valuesuntilitgetstotheresult.
Forexample,iftheclockisfedthenumber137,itwillshow:"137""11""2"andthenitwillgoblack,
waitingforthenextnumber.
Everydigitalnumberconsistsofsomelightsegments:threehorizontal(top,middle,bottom)andfourvertical
(topleft,topright,bottomleft,bottomright).
Number"1"ismadeofverticaltoprightandbottomright,number"4"ismadebymiddlehorizontaland
verticaltopleft,toprightandbottomright.Number"8"lightsthemall.
Theclocksconsumeenergyonlywhensegmentsareturnedon/off.
Toturnona"2"willcost5transitions,whilea"7"willcostonly4transitions.
SamandMaxbuilttwodifferentclocks.
Sam'sclockisfede.g.number137:theclockshows"137",thenthepanelisturnedoff,thenthenext
number("11")isturnedon,thenthepanelisturnedoffagainandfinallythelastnumber("2")isturnedon
and,aftersometime,off.
Fortheexample,withnumber137,Sam'sclockrequires:
"137" : (2+5+4)2=22transitions("137"on/off).
"11" : (2+2)2=8transitions("11"on/off).
"2" : (5)2=10transitions("2"on/off).
Foragrandtotalof40transitions.
Max'sclockworksdifferently.Insteadofturningoffthewholepanel,itissmartenoughtoturnoffonlythose
segmentsthatwon'tbeneededforthenextnumber.
Fornumber137,Max'sclockrequires:
"137" : 2+5+4=11transitions("137"on)
7transitions(toturnoffthesegmentsthatarenotneededfornumber"11").
"11" : 0transitions(number"11"isalreadyturnedoncorrectly)
3transitions(toturnoffthefirst"1"andthebottompartofthesecond"1"
thetoppartiscommonwithnumber"2").
"2" : 4transitions(toturnontheremainingsegmentsinordertogeta"2")
5transitions(toturnoffnumber"2").
Foragrandtotalof30transitions.
Ofcourse,Max'sclockconsumeslesspowerthanSam'sone.
ThetwoclocksarefedalltheprimenumbersbetweenA=107andB=2107.
FindthedifferencebetweenthetotalnumberoftransitionsneededbySam'sclockandthatneededby
Max'sone.
Problem316:Numbersindecimalexpansions
Letp=p1p2p3...beaninfinitesequenceofrandomdigits,selectedfrom{0,1,2,3,4,5,6,7,8,9}withequal
probability.
Itcanbeseenthatpcorrespondstotherealnumber0.p1p2p3....
Itcanalsobeseenthatchoosingarandomrealnumberfromtheinterval[0,1)isequivalenttochoosingan
infinitesequenceofrandomdigitsselectedfrom{0,1,2,3,4,5,6,7,8,9}withequalprobability.
https://projecteuler.net/show=all
96/163
5/2/2015
Foranypositiveintegernwithddecimaldigits,letkbethesmallestindexsuchthat
pk,pk+1,...pk+d1arethedecimaldigitsofn,inthesameorder.
Also,letg(n)betheexpectedvalueofkitcanbeproventhatg(n)isalwaysfiniteand,interestingly,always
anintegernumber.
Forexample,ifn=535,then
forp=31415926535897....,wegetk=9
forp=355287143650049560000490848764084685354...,wegetk=36
etcandwefindthatg(535)=1008.
Giventhat
Note:
,find
representsthefloorfunction.
Problem317:Firecracker
Afirecrackerexplodesataheightof100mabovelevelground.Itbreaksintoalargenumberofverysmall
fragments,whichmoveineverydirectionallofthemhavethesameinitialvelocityof20m/s.
Weassumethatthefragmentsmovewithoutairresistance,inauniformgravitationalfieldwithg=9.81m/s2.
Findthevolume(inm3)oftheregionthroughwhichthefragmentsmovebeforereachingtheground.Give
youranswerroundedtofourdecimalplaces.
Problem318:2011nines
Considertherealnumber2+3.
Whenwecalculatetheevenpowersof2+3weget:
(2+3)2=9.898979485566356...
(2+3)4=97.98979485566356...
(2+3)6=969.998969071069263...
(2+3)8=9601.99989585502907...
(2+3)10=95049.999989479221...
(2+3)12=940897.9999989371855...
(2+3)14=9313929.99999989263...
(2+3)16=92198401.99999998915...
Itlookslikethatthenumberofconsecutiveninesatthebeginningofthefractionalpartofthesepowersis
nondecreasing.
Infactitcanbeproventhatthefractionalpartof(2+3)2napproaches1forlargen.
Considerallrealnumbersoftheformp+qwithpandqpositiveintegersandp<q,suchthatthefractional
partof(p+q)2napproaches1forlargen.
LetC(p,q,n)bethenumberofconsecutiveninesatthebeginningofthefractionalpartof
(p+q)2n.
LetN(p,q)betheminimalvalueofnsuchthatC(p,q,n)2011.
FindN(p,q)forp+q2011.
Problem319:BoundedSequences
Letx1,x2,...,xnbeasequenceoflengthnsuchthat:
x1=2
forall1<in:xi1<xi
foralliandjwith1i,jn:(xi)j<(xj+1)i
Thereareonlyfivesuchsequencesoflength2,namely:{2,4},{2,5},{2,6},{2,7}and{2,8}.
Thereare293suchsequencesoflength5threeexamplesaregivenbelow:
{2,5,11,25,55},{2,6,14,36,88},{2,8,22,64,181}.
Lett(n)denotethenumberofsuchsequencesoflengthn.
https://projecteuler.net/show=all
97/163
5/2/2015
Youaregiventhatt(10)=86195andt(20)=5227991891.
Findt(1010)andgiveyouranswermodulo109.
Problem320:Factorialsdivisiblebyahugeinteger
LetN(i)bethesmallestintegernsuchthatn!isdivisibleby(i!)1234567890
LetS(u)=N(i)for10iu.
S(1000)=614538266565663.
FindS(1000000)mod1018.
Problem321:SwappingCounters
Ahorizontalrowcomprisingof2n+1squareshasnredcountersplacedatoneendandnbluecountersat
theotherend,beingseparatedbyasingleemptysquareinthecentre.Forexample,whenn=3.
Acountercanmovefromonesquaretothenext(slide)orcanjumpoveranothercounter(hop)aslongas
thesquarenexttothatcounterisunoccupied.
LetM(n)representtheminimumnumberofmoves/actionstocompletelyreversethepositionsofthe
colouredcountersthatis,movealltheredcounterstotherightandallthebluecounterstotheleft.
ItcanbeverifiedM(3)=15,whichalsohappenstobeatrianglenumber.
IfwecreateasequencebasedonthevaluesofnforwhichM(n)isatrianglenumberthenthefirstfive
termswouldbe:
1,3,10,22,and63,andtheirsumwouldbe99.
Findthesumofthefirstfortytermsofthissequence.
Problem322:Binomialcoefficientsdivisibleby10
LetT(m,n)bethenumberofthebinomialcoefficientsiCnthataredivisibleby10forni<m(i,mandn
arepositiveintegers).
YouaregiventhatT(109,10710)=989697000.
FindT(1018,101210).
Problem323:BitwiseORoperationsonrandomintegers
Lety0,y1,y2,...beasequenceofrandomunsigned32bitintegers
(i.e.0yi<232,everyvalueequallylikely).
Forthesequencexithefollowingrecursionisgiven:
x0=0and
xi=xi1|yi1,fori>0.(|isthebitwiseORoperator)
ItcanbeseenthateventuallytherewillbeanindexNsuchthatxi=2321(abitpatternofallones)foralli
N.
FindtheexpectedvalueofN.
https://projecteuler.net/show=all
98/163
5/2/2015
Giveyouranswerroundedto10digitsafterthedecimalpoint.
Problem324:Buildingatower
Letf(n)representthenumberofwaysonecanfilla33ntowerwithblocksof211.
You'reallowedtorotatetheblocksinanywayyoulikehowever,rotations,reflectionsetcofthetoweritself
arecountedasdistinct.
Forexample(withq=100000007):
f(2)=229,
f(4)=117805,
f(10)modq=96149360,
f(103)modq=24806056,
f(106)modq=30808124.
Findf(1010000)mod100000007.
Problem325:StoneGameII
Agameisplayedwithtwopilesofstonesandtwoplayers.Atherturn,aplayerremovesanumberofstones
fromthelargerpile.Thenumberofstonessheremovesmustbeapositivemultipleofthenumberofstones
inthesmallerpile.
E.g.,lettheorderedpair(6,14)describeaconfigurationwith6stonesinthesmallerpileand14stonesinthe
largerpile,thenthefirstplayercanremove6or12stonesfromthelargerpile.
Theplayertakingallthestonesfromapilewinsthegame.
Awinningconfigurationisonewherethefirstplayercanforceawin.Forexample,(1,5),(2,6)and(3,12)are
winningconfigurationsbecausethefirstplayercanimmediatelyremoveallstonesinthesecondpile.
Alosingconfigurationisonewherethesecondplayercanforceawin,nomatterwhatthefirstplayerdoes.
Forexample,(2,3)and(3,4)arelosingconfigurations:anylegalmoveleavesawinningconfigurationforthe
secondplayer.
DefineS(N)asthesumof(xi+yi)foralllosingconfigurations(xi,yi),0<xi<yiN.Wecanverifythat
S(10)=211andS(104)=230312207313.
FindS(1016)mod710.
Problem326:ModuloSummations
Letanbeasequencerecursivelydefinedby:
Sothefirst10elementsofanare:1,1,0,3,0,3,5,4,1,9.
Letf(N,M)representthenumberofpairs(p,q)suchthat:
Itcanbeseenthatf(10,10)=4withthepairs(3,3),(5,5),(7,9)and(9,10).
Youarealsogiventhatf(104,103)=97158.
Findf(1012,106).
Problem327:RoomsofDoom
Aseriesofthreeroomsareconnectedtoeachotherbyautomaticdoors.
https://projecteuler.net/show=all
99/163
5/2/2015
Eachdoorisoperatedbyasecuritycard.Onceyouenteraroomthedoorautomaticallyclosesandthat
securitycardcannotbeusedagain.Amachineatthestartwilldispenseanunlimitednumberofcards,but
eachroom(includingthestartingroom)containsscannersandiftheydetectthatyouareholdingmorethan
threesecuritycardsoriftheydetectanunattendedsecuritycardonthefloor,thenallthedoorswillbecome
permanentlylocked.However,eachroomcontainsaboxwhereyoumaysafelystoreanynumberof
securitycardsforuseatalaterstage.
Ifyousimplytriedtotravelthroughtheroomsoneatatimethenasyouenteredroom3youwouldhave
usedallthreecardsandwouldbetrappedinthatroomforever!
However,ifyoumakeuseofthestorageboxes,thenescapeispossible.Forexample,youcouldenterroom
1usingyourfirstcard,placeonecardinthestoragebox,anduseyourthirdcardtoexittheroombackto
thestart.Thenaftercollectingthreemorecardsfromthedispensingmachineyoucoulduseonetoenter
room1andcollectthecardyouplacedintheboxamomentago.Younowhavethreecardsagainandwill
beabletotravelthroughtheremainingthreedoors.Thismethodallowsyoutotravelthroughallthreerooms
usingsixsecuritycardsintotal.
Itispossibletotravelthroughsixroomsusingatotalof123securitycardswhilecarryingamaximumof3
cards.
LetCbethemaximumnumberofcardswhichcanbecarriedatanytime.
LetRbethenumberofroomstotravelthrough.
LetM(C,R)betheminimumnumberofcardsrequiredfromthedispensingmachinetotravelthroughR
roomscarryinguptoamaximumofCcardsatanytime.
Forexample,M(3,6)=123andM(4,6)=23.
And,M(C,6)=146for3C4.
YouaregiventhatM(C,10)=10382for3C10.
FindM(C,30)for3C40.
Problem328:LowestcostSearch
Wearetryingtofindahiddennumberselectedfromthesetofintegers{1,2,...,n}byaskingquestions.
Eachnumber(question)weask,hasacostequaltothenumberaskedandwegetoneofthreepossible
answers:
"Yourguessislowerthanthehiddennumber",or
"Yes,that'sit!",or
"Yourguessishigherthanthehiddennumber".
Giventhevalueofn,anoptimalstrategyminimizesthetotalcost(i.e.thesumofallthequestionsasked)for
theworstpossiblecase.E.g.
Ifn=3,thebestwecandoisobviouslytoaskthenumber"2".Theanswerwillimmediatelyleadustofind
thehiddennumber(atatotalcost=2).
Ifn=8,wemightdecidetousea"binarysearch"typeofstrategy:Ourfirstquestionwouldbe"4"andifthe
hiddennumberishigherthan4wewillneedoneortwoadditionalquestions.
Letoursecondquestionbe"6".Ifthehiddennumberisstillhigherthan6,wewillneedathirdquestionin
ordertodiscriminatebetween7and8.
Thus,ourthirdquestionwillbe"7"andthetotalcostforthisworstcasescenariowillbe4+6+7=17.
Wecanimproveconsiderablytheworstcasecostforn=8,byasking"5"asourfirstquestion.
Ifwearetoldthatthehiddennumberishigherthan5,oursecondquestionwillbe"7",thenwe'llknowfor
certainwhatthehiddennumberis(foratotalcostof5+7=12).
Ifwearetoldthatthehiddennumberislowerthan5,oursecondquestionwillbe"3"andifthehidden
numberislowerthan3ourthirdquestionwillbe"1",givingatotalcostof5+3+1=9.
Since12>9,theworstcasecostforthisstrategyis12.That'sbetterthanwhatweachievedpreviouslywith
the"binarysearch"strategyitisalsobetterthanorequaltoanyotherstrategy.
So,infact,wehavejustdescribedanoptimalstrategyforn=8.
LetC(n)betheworstcasecostachievedbyanoptimalstrategyforn,asdescribedabove.
ThusC(1)=0,C(2)=1,C(3)=2andC(8)=12.
https://projecteuler.net/show=all
100/163
5/2/2015
Similarly,C(100)=400and
Find
C(n)=17575.
C(n).
Problem329:PrimeFrog
Susanhasaprimefrog.
Herfrogisjumpingaroundover500squaresnumbered1to500.Hecanonlyjumponesquaretotheleftor
totheright,withequalprobability,andhecannotjumpoutsidetherange[1500].
(ifitlandsateitherend,itautomaticallyjumpstotheonlyavailablesquareonthenextmove.)
Whenheisonasquarewithaprimenumberonit,hecroaks'P'(PRIME)withprobability2/3or'N'(NOT
PRIME)withprobability1/3justbeforejumpingtothenextsquare.
Whenheisonasquarewithanumberonitthatisnotaprimehecroaks'P'withprobability1/3or'N'with
probability2/3justbeforejumpingtothenextsquare.
Giventhatthefrog'sstartingpositionisrandomwiththesameprobabilityforeverysquare,andgiventhat
shelistenstohisfirst15croaks,whatistheprobabilitythatshehearsthesequence
PPPPNNPPPNPPNPN?
Giveyouranswerasafractionp/qinreducedform.
Problem330:Euler'sNumber
Aninfinitesequenceofrealnumbersa(n)isdefinedforallintegersnasfollows:
Forexample,
1
1
1
a(0)= 1! + 2! + 3! +...=e1
a(1)=
e1
1
1
+
+
+...=2e3
1!
2!
3!
2e3
e1
1
7
+
+
+...=
e6
1!
2!
3!
2
withe=2.7182818...beingEuler'sconstant.
a(2)=
Itcanbeshownthata(n)isoftheform
Forexamplea(10)=
A(n)e+B(n)
forintegersA(n)andB(n).
n!
328161643e652694486
.
10!
FindA(109)+B(109)andgiveyouranswermod77777777.
Problem331:Crossflips
NNdisksareplacedonasquaregameboard.Eachdiskhasablacksideandwhiteside.
Ateachturn,youmaychooseadiskandflipallthedisksinthesamerowandthesamecolumnasthisdisk:
thus2N1disksareflipped.Thegameendswhenalldisksshowtheirwhiteside.Thefollowingexample
showsagameona55board.
https://projecteuler.net/show=all
101/163
5/2/2015
Itcanbeproventhat3istheminimalnumberofturnstofinishthisgame.
ThebottomleftdiskontheNNboardhascoordinates(0,0)
thebottomrightdiskhascoordinates(N1,0)andthetopleftdiskhascoordinates(0,N1).
LetCNbethefollowingconfigurationofaboardwithNNdisks:
Adiskat(x,y)satisfying
,showsitsblacksideotherwise,itshowsitswhiteside.C5is
shownabove.
LetT(N)betheminimalnumberofturnstofinishagamestartingfromconfigurationCNor0ifconfiguration
CNisunsolvable.
WehaveshownthatT(5)=3.YouarealsogiventhatT(10)=29andT(1000)=395253.
Find
Problem332:Sphericaltriangles
Asphericaltriangleisafigureformedonthesurfaceofaspherebythreegreatcirculararcsintersecting
pairwiseinthreevertices.
LetC(r)bethespherewiththecentre(0,0,0)andradiusr.
LetZ(r)bethesetofpointsonthesurfaceofC(r)withintegercoordinates.
LetT(r)bethesetofsphericaltriangleswithverticesinZ(r).Degeneratesphericaltriangles,formedby
threepointsonthesamegreatarc,arenotincludedinT(r).
LetA(r)betheareaofthesmallestsphericaltriangleinT(r).
ForexampleA(14)is3.294040roundedtosixdecimalplaces.
Find
A(r).Giveyouranswerroundedtosixdecimalplaces.
Problem333:Specialpartitions
Allpositiveintegerscanbepartitionedinsuchawaythateachandeverytermofthepartitioncanbe
expressedas2ix3j,wherei,j0.
Let'sconsideronlythosesuchpartitionswherenoneofthetermscandivideanyoftheotherterms.
https://projecteuler.net/show=all
102/163
5/2/2015
Forexample,thepartitionof17=2+6+9=(21x30+21x31+20x32)wouldnotbevalidsince2candivide
6.Neitherwouldthepartition17=16+1=(24x30+20x30)since1candivide16.Theonlyvalidpartitionof
17wouldbe8+9=(23x30+20x32).
Manyintegershavemorethanonevalidpartition,thefirstbeing11havingthefollowingtwopartitions.
11=2+9=(21x30+20x32)
11=8+3=(23x30+20x31)
Let'sdefineP(n)asthenumberofvalidpartitionsofn.Forexample,P(11)=2.
Let'sconsideronlytheprimeintegersqwhichwouldhaveasinglevalidpartitionsuchasP(17).
Thesumoftheprimesq<100suchthatP(q)=1equals233.
Findthesumoftheprimesq<1000000suchthatP(q)=1.
Problem334:Spillingthebeans
InPlato'sheaven,thereexistaninfinitenumberofbowlsinastraightline.
Eachbowleithercontainssomeornoneofafinitenumberofbeans.
Achildplaysagame,whichallowsonlyonekindofmove:removingtwobeansfromanybowl,andputting
oneineachofthetwoadjacentbowls.
Thegameendswheneachbowlcontainseitheroneornobeans.
Forexample,considertwoadjacentbowlscontaining2and3beansrespectively,allotherbowlsbeing
empty.Thefollowingeightmoveswillfinishthegame:
Youaregiventhefollowingsequences:
t0=123456.
ti1 ,
ti=
ifti1iseven
ti1
2
926252, ifti1isodd
wherexisthefloorfunction
and isthebitwiseXORoperator.
bi=(timod211)+1.
Thefirsttwotermsofthelastsequenceareb1=289andb2=145.
Ifwestartwithb1andb2beansintwoadjacentbowls,3419100moveswouldberequiredtofinishthe
game.
Considernow1500adjacentbowlscontainingb1,b2,...,b1500beansrespectively,allotherbowlsbeing
empty.Findhowmanymovesittakesbeforethegameends.
Problem335:Gatheringthebeans
WheneverPeterfeelsbored,heplacessomebowls,containingonebeaneach,inacircle.Afterthis,he
takesallthebeansoutofacertainbowlanddropsthemonebyoneinthebowlsgoingclockwise.He
repeatsthis,startingfromthebowlhedroppedthelastbeanin,untiltheinitialsituationappearsagain.For
examplewith5bowlsheactsasfollows:
https://projecteuler.net/show=all
103/163
5/2/2015
Sowith5bowlsittakesPeter15movestoreturntotheinitialsituation.
LetM(x)representthenumberofmovesrequiredtoreturntotheinitialsituation,startingwithxbowls.
Thus,M(5)=15.ItcanalsobeverifiedthatM(100)=10920.
Find
M(2k+1).Giveyouranswermodulo79.
Problem336:MaximixArrangements
Atrainisusedtotransportfourcarriagesintheorder:ABCD.However,sometimeswhenthetrainarrivesto
collectthecarriagestheyarenotinthecorrectorder.
Torearrangethecarriagestheyareallshuntedontoalargerotatingturntable.Afterthecarriagesare
uncoupledataspecificpointthetrainmovesofftheturntablepullingthecarriagesstillattachedwithit.The
remainingcarriagesarerotated180degrees.Allofthecarriagesarethenrejoinedandthisprocessis
repeatedasoftenasnecessaryinordertoobtaintheleastnumberofusesoftheturntable.
Somearrangements,suchasADCB,canbesolvedeasily:thecarriagesareseparatedbetweenAandD,
andafterDCBarerotatedthecorrectorderhasbeenachieved.
However,SimpleSimon,thetraindriver,isnotknownforhisefficiency,sohealwayssolvestheproblemby
initiallygettingcarriageAinthecorrectplace,thencarriageB,andsoon.
Usingfourcarriages,theworstpossiblearrangementsforSimon,whichweshallcallmaximix
arrangements,areDACBandDBACeachrequiringhimfiverotations(although,usingthemostefficient
approach,theycouldbesolvedusingjustthreerotations).TheprocessheusesforDACBisshownbelow.
https://projecteuler.net/show=all
104/163
5/2/2015
Itcanbeverifiedthatthereare24maximixarrangementsforsixcarriages,ofwhichthetenthlexicographic
maximixarrangementisDFAECB.
Findthe2011thlexicographicmaximixarrangementforelevencarriages.
Problem337:TotientStairstepSequences
Let{a1,a2,...,an}beanintegersequenceoflengthnsuchthat:
a1=6
forall1i<n:(ai)<(ai+1)<ai<ai+11
LetS(N)bethenumberofsuchsequenceswithanN.
Forexample,S(10)=4:{6},{6,8},{6,8,9}and{6,10}.
WecanverifythatS(100)=482073668andS(10000)mod108=73808307.
FindS(20000000)mod108.
1denotesEuler'stotientfunction.
Problem338:CuttingRectangularGridPaper
Arectangularsheetofgridpaperwithintegerdimensionswhisgiven.Itsgridspacingis1.
Whenwecutthesheetalongthegridlinesintotwopiecesandrearrangethosepieceswithoutoverlap,we
canmakenewrectangleswithdifferentdimensions.
Forexample,fromasheetwithdimensions94,wecanmakerectangleswithdimensions182,123
and66bycuttingandrearrangingasbelow:
Similarly,fromasheetwithdimensions98,wecanmakerectangleswithdimensions184and126.
Forapairwandh,letF(w,h)bethenumberofdistinctrectanglesthatcanbemadefromasheetwith
dimensionswh.
Forexample,F(2,1)=0,F(2,2)=1,F(9,4)=3andF(9,8)=2.
NotethatrectanglescongruenttotheinitialonearenotcountedinF(w,h).
Notealsothatrectangleswithdimensionswhanddimensionshwarenotconsidereddistinct.
ForanintegerN,letG(N)bethesumofF(w,h)forallpairswandhwhichsatisfy0<hwN.
WecanverifythatG(10)=55,G(103)=971745andG(105)=9992617687.
FindG(1012).Giveyouranswermodulo108.
Problem339:PeredurfabEfrawg
"Andhecametowardsavalley,throughwhichranariverandthebordersofthevalleywerewooded,and
oneachsideoftheriverwerelevelmeadows.Andononesideoftheriverhesawaflockofwhitesheep,
andontheotheraflockofblacksheep.Andwheneveroneofthewhitesheepbleated,oneoftheblack
sheepwouldcrossoverandbecomewhiteandwhenoneoftheblacksheepbleated,oneofthewhite
sheepwouldcrossoverandbecomeblack."
en.wikisource.org
https://projecteuler.net/show=all
105/163
5/2/2015
Initiallyeachflockconsistsofnsheep.Eachsheep(regardlessofcolour)isequallylikelytobethenext
sheeptobleat.Afterasheephasbleatedandasheepfromtheotherflockhascrossedover,Peredurmay
removeanumberofwhitesheepinordertomaximizetheexpectedfinalnumberofblacksheep.LetE(n)
betheexpectedfinalnumberofblacksheepifPeredurusesanoptimalstrategy.
YouaregiventhatE(5)=6.871346roundedto6placesbehindthedecimalpoint.
FindE(10000)andgiveyouranswerroundedto6placesbehindthedecimalpoint.
Problem340:CrazyFunction
Forfixedintegersa,b,c,definethecrazyfunctionF(n)asfollows:
F(n)=ncforalln>b
F(n)=F(a+F(a+F(a+F(a+n))))forallnb.
Also,defineS(a,b,c)=
Forexample,ifa=50,b=2000andc=40,thenF(0)=3240andF(2000)=2040.
Also,S(50,2000,40)=5204240.
Findthelast9digitsofS(217,721,127).
Problem341:Golomb'sselfdescribingsequence
TheGolomb'sselfdescribingsequence{G(n)}istheonlynondecreasingsequenceofnaturalnumbers
suchthatnappearsexactlyG(n)timesinthesequence.ThevaluesofG(n)forthefirstfewnare
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
G(n) 1 2 2 3 3 4 4 4 5 5
YouaregiventhatG(103)=86,G(106)=6137.
YouarealsogiventhatG(n3)=153506976for1n<103.
FindG(n3)for1n<106.
Problem342:Thetotientofasquareisacube
Considerthenumber50.
502=2500=2254,so(2500)=2453=853=2353.1
So2500isasquareand(2500)isacube.
Findthesumofallnumbersn,1<n<1010suchthat(n2)isacube.
1denotesEuler'stotientfunction.
Problem343:FractionalSequences
Foranypositiveintegerk,afinitesequenceaioffractionsxi/yiisdefinedby:
a1=1/kand
ai=(xi1+1)/(yi11)reducedtolowesttermsfori>1.
Whenaireachessomeintegern,thesequencestops.(Thatis,whenyi=1.)
Definef(k)=n.
Forexample,fork=20:
1/202/193/18=1/62/53/44/35/26/1=6
Sof(20)=6.
Alsof(1)=1,f(2)=2,f(3)=1andf(k3)=118937for1k100.
Findf(k3)for1k2106.
https://projecteuler.net/show=all
106/163
5/2/2015
Problem344:Silverdollargame
OnevariantofN.G.deBruijn'ssilverdollargamecanbedescribedasfollows:
Onastripofsquaresanumberofcoinsareplaced,atmostonecoinpersquare.Onlyonecoin,calledthe
silverdollar,hasanyvalue.Twoplayerstaketurnsmakingmoves.Ateachturnaplayermustmakeeither
aregularoraspecialmove.
Aregularmoveconsistsofselectingonecoinandmovingitoneormoresquarestotheleft.Thecoincannot
moveoutofthestriporjumponoroveranothercoin.
Alternatively,theplayercanchoosetomakethespecialmoveofpocketingtheleftmostcoinratherthan
makingaregularmove.Ifnoregularmovesarepossible,theplayerisforcedtopockettheleftmostcoin.
Thewinneristheplayerwhopocketsthesilverdollar.
Awinningconfigurationisanarrangementofcoinsonthestripwherethefirstplayercanforceawinno
matterwhatthesecondplayerdoes.
LetW(n,c)bethenumberofwinningconfigurationsforastripofnsquares,cworthlesscoinsandonesilver
dollar.
YouaregiventhatW(10,2)=324andW(100,10)=1514704946113500.
FindW(1000000,100)modulothesemiprime1000036000099(=10000031000033).
Problem345:MatrixSum
WedefinetheMatrixSumofamatrixasthemaximumsumofmatrixelementswitheachelementbeingthe
onlyoneinhisrowandcolumn.Forexample,theMatrixSumofthematrixbelowequals3315(=863+383
+343+959+767):
753183439863
49738356379973
28763343169583
627343773959943
767473103699303
FindtheMatrixSumof:
7531834398634973835637997328763343169583
627343773959943767473103699303957703583639913
4472834632923487463993119883327493423159743
217623339985340710398389463290516212462350
960376682962300780486502912800250346172812350
87045619216259347391545989873823965425329803
973965905919133673665235509613673815165992326
32214897296228625594154126532392528160195973
445721115254736551116413867218428154448848
414456310312798104566520302248694976430392198
184829373181631101969613840740778458284760390
8214618435131790171199329315727494192156574
341244878450476712914838669875299823329699
815559813459522788168586966232308833251631107
8138834515096157728161345920538027430235805
Problem346:StrongRepunits
Thenumber7isspecial,because7is111writteninbase2,and11writteninbase6
(i.e.710=116=1112).Inotherwords,7isarepunitinatleasttwobasesb>1.
Weshallcallapositiveintegerwiththispropertyastrongrepunit.Itcanbeverifiedthatthereare8strong
repunitsbelow50:{1,7,13,15,21,31,40,43}.
Furthermore,thesumofallstrongrepunitsbelow1000equals15864.
https://projecteuler.net/show=all
107/163
5/2/2015
Findthesumofallstrongrepunitsbelow1012.
Problem347:Largestintegerdivisiblebytwoprimes
Thelargestinteger100thatisonlydivisiblebyboththeprimes2and3is96,as96=32*3=25*3.Fortwo
distinctprimespandqletM(p,q,N)bethelargestpositiveintegerNonlydivisiblebybothpandqand
M(p,q,N)=0ifsuchapositiveintegerdoesnotexist.
E.g.M(2,3,100)=96.
M(3,5,100)=75andnot90because90isdivisibleby2,3and5.
AlsoM(2,73,100)=0becausetheredoesnotexistapositiveinteger100thatisdivisiblebyboth2and73.
LetS(N)bethesumofalldistinctM(p,q,N).S(100)=2262.
FindS(10000000).
Problem348:Sumofasquareandacube
Manynumberscanbeexpressedasthesumofasquareandacube.Someoftheminmorethanoneway.
Considerthepalindromicnumbersthatcanbeexpressedasthesumofasquareandacube,bothgreater
than1,inexactly4differentways.
Forexample,5229225isapalindromicnumberanditcanbeexpressedinexactly4differentways:
22852+203
22232+663
18102+1253
11972+1563
Findthesumofthefivesmallestsuchpalindromicnumbers.
Problem349:Langton'sant
Anantmovesonaregulargridofsquaresthatarecolouredeitherblackorwhite.
Theantisalwaysorientedinoneofthecardinaldirections(left,right,upordown)andmovesfromsquare
toadjacentsquareaccordingtothefollowingrules:
ifitisonablacksquare,itflipsthecolorofthesquaretowhite,rotates90degreescounterclockwiseand
movesforwardonesquare.
ifitisonawhitesquare,itflipsthecolorofthesquaretoblack,rotates90degreesclockwiseandmoves
forwardonesquare.
Startingwithagridthatisentirelywhite,howmanysquaresareblackafter1018movesoftheant?
Problem350:Constrainingtheleastgreatestandthegreatestleast
Alistofsizenisasequenceofnnaturalnumbers.
Examplesare(2,4,6),(2,6,4),(10,6,15,6),and(11).
Thegreatestcommondivisor,orgcd,ofalististhelargestnaturalnumberthatdividesallentriesofthe
list.
Examples:gcd(2,6,4)=2,gcd(10,6,15,6)=1andgcd(11)=11.
Theleastcommonmultiple,orlcm,ofalististhesmallestnaturalnumberdivisiblebyeachentryofthe
list.
Examples:lcm(2,6,4)=12,lcm(10,6,15,6)=30andlcm(11)=11.
Letf(G,L,N)bethenumberoflistsofsizeNwithgcdGandlcmL.Forexample:
f(10,100,1)=91.
f(10,100,2)=327.
f(10,100,3)=1135.
f(10,100,1000)mod1014=3286053.
Findf(106,1012,1018)mod1014.
Problem351:Hexagonalorchards
https://projecteuler.net/show=all
108/163
5/2/2015
Ahexagonalorchardofordernisatriangularlatticemadeupofpointswithinaregularhexagonwithsiden.
Thefollowingisanexampleofahexagonalorchardoforder5:
Highlightedingreenarethepointswhicharehiddenfromthecenterbyapointclosertoit.Itcanbeseen
thatforahexagonalorchardoforder5,30pointsarehiddenfromthecenter.
LetH(n)bethenumberofpointshiddenfromthecenterinahexagonalorchardofordern.
H(5)=30.H(10)=138.H(1000)=1177848.
FindH(100000000).
Problem352:Bloodtests
Eachoneofthe25sheepinaflockmustbetestedforararevirus,knowntoaffect2%ofthesheep
population.AnaccurateandextremelysensitivePCRtestexistsforbloodsamples,producingaclear
positive/negativeresult,butitisverytimeconsumingandexpensive.
Becauseofthehighcost,thevetinchargesuggeststhatinsteadofperforming25separatetests,the
followingprocedurecanbeusedinstead:
Thesheeparesplitinto5groupsof5sheepineachgroup.Foreachgroup,the5samplesaremixed
togetherandasingletestisperformed.Then,
Iftheresultisnegative,allthesheepinthatgrouparedeemedtobevirusfree.
Iftheresultispositive,5additionaltestswillbeperformed(aseparatetestforeachanimal)to
determinetheaffectedindividual(s).
Sincetheprobabilityofinfectionforanyspecificanimalisonly0.02,thefirsttest(onthepooledsamples)for
eachgroupwillbe:
Negative(andnomoretestsneeded)withprobability0.985=0.9039207968.
Positive(5additionaltestsneeded)withprobability10.9039207968=0.0960792032.
Thus,theexpectednumberoftestsforeachgroupis1+0.09607920325=1.480396016.
Consequently,all5groupscanbescreenedusinganaverageofonly1.4803960165=7.40198008tests,
whichrepresentsahugesavingofmorethan70%!
Althoughtheschemewehavejustdescribedseemstobeveryefficient,itcanstillbeimprovedconsiderably
(alwaysassumingthatthetestissufficientlysensitiveandthattherearenoadverseeffectscausedby
mixingdifferentsamples).E.g.:
Wemaystartbyrunningatestonamixtureofallthe25samples.Itcanbeverifiedthatinabout
60.35%ofthecasesthistestwillbenegative,thusnomoretestswillbeneeded.Furthertestingwill
onlyberequiredfortheremaining39.65%ofthecases.
Ifweknowthatatleastoneanimalinagroupof5isinfectedandthefirst4individualtestscomeout
negative,thereisnoneedtorunatestonthefifthanimal(weknowthatitmustbeinfected).
Wecantryadifferentnumberofgroups/differentnumberofanimalsineachgroup,adjustingthose
numbersateachlevelsothatthetotalexpectednumberoftestswillbeminimised.
Tosimplifytheverywiderangeofpossibilities,thereisonerestrictionweplacewhendevisingthemost
costefficienttestingscheme:wheneverwestartwithamixedsample,allthesheepcontributingtothat
samplemustbefullyscreened(i.e.averdictofinfected/virusfreemustbereachedforallofthem)before
westartexamininganyotheranimals.
Forthecurrentexample,itturnsoutthatthemostcostefficienttestingscheme(we'llcallittheoptimal
strategy)requiresanaverageofjust4.155452tests!
https://projecteuler.net/show=all
109/163
5/2/2015
Usingtheoptimalstrategy,letT(s,p)representtheaveragenumberoftestsneededtoscreenaflockofs
sheepforavirushavingprobabilityptobepresentinanyindividual.
Thus,roundedtosixdecimalplaces,T(25,0.02)=4.155452andT(25,0.10)=12.702124.
FindT(10000,p)forp=0.01,0.02,0.03,...0.50.
Giveyouranswerroundedtosixdecimalplaces.
Problem353:Riskymoon
AmooncouldbedescribedbythesphereC(r)withcentre(0,0,0)andradiusr.
TherearestationsonthemoonatthepointsonthesurfaceofC(r)withintegercoordinates.Thestationat
(0,0,r)iscalledNorthPolestation,thestationat(0,0,r)iscalledSouthPolestation.
Allstationsareconnectedwitheachotherviatheshortestroadonthegreatarcthroughthestations.A
journeybetweentwostationsisrisky.Ifdisthelengthoftheroadbetweentwostations,(d/(r))2isa
measurefortheriskofthejourney(letuscallittheriskoftheroad).Ifthejourneyincludesmorethantwo
stations,theriskofthejourneyisthesumofrisksoftheusedroads.
AdirectjourneyfromtheNorthPolestationtotheSouthPolestationhasthelengthrandrisk1.The
journeyfromtheNorthPolestationtotheSouthPolestationvia(0,r,0)hasthesamelength,butasmaller
risk:(r/(r))2+(r/(r))2=0.5.
TheminimalriskofajourneyfromtheNorthPolestationtotheSouthPolestationonC(r)isM(r).
YouaregiventhatM(7)=0.1784943998roundedto10digitsbehindthedecimalpoint.
FindM(2n1)for1n15.
Giveyouranswerroundedto10digitsbehindthedecimalpointintheforma.bcdefghijk.
Problem354:Distancesinabee'shoneycomb
Considerahoneybee'shoneycombwhereeachcellisaperfectregularhexagonwithsidelength1.
Oneparticularcellisoccupiedbythequeenbee.
ForapositiverealnumberL,letB(L)countthecellswithdistanceLfromthequeenbeecell(alldistances
aremeasuredfromcentretocentre)youmayassumethatthehoneycombislargeenoughto
accommodateforanydistancewewishtoconsider.
Forexample,B(3)=6,B(21)=12andB(111111111)=54.
FindthenumberofL51011suchthatB(L)=450.
Problem355:Maximalcoprimesubset
https://projecteuler.net/show=all
110/163
5/2/2015
DefineCo(n)tobethemaximalpossiblesumofasetofmutuallycoprimeelementsfrom{1,2,...,n}.
ForexampleCo(10)is30andhitsthatmaximumonthesubset{1,5,7,8,9}.
YouaregiventhatCo(30)=193andCo(100)=1356.
FindCo(200000).
Problem356:Largestrootsofcubicpolynomials
Letanbethelargestrealrootofapolynomialg(x)=x32nx2+n.
Forexample,a2=3.86619826...
Findthelasteightdigitsof
Note:
representsthefloorfunction.
Problem357:Primegeneratingintegers
Considerthedivisorsof30:1,2,3,5,6,10,15,30.
Itcanbeseenthatforeverydivisordof30,d+30/disprime.
Findthesumofallpositiveintegersnnotexceeding100000000
suchthatforeverydivisordofn,d+n/disprime.
Problem358:Cyclicnumbers
Acyclicnumberwithndigitshasaveryinterestingproperty:
Whenitismultipliedby1,2,3,4,...n,alltheproductshaveexactlythesamedigits,inthesameorder,but
rotatedinacircularfashion!
Thesmallestcyclicnumberisthe6digitnumber142857:
1428571=142857
1428572=285714
1428573=428571
1428574=571428
1428575=714285
1428576=857142
Thenextcyclicnumberis0588235294117647with16digits:
05882352941176471=0588235294117647
05882352941176472=1176470588235294
05882352941176473=1764705882352941
...
058823529411764716=9411764705882352
Notethatforcyclicnumbers,leadingzerosareimportant.
Thereisonlyonecyclicnumberforwhich,theelevenleftmostdigitsare00000000137andthefiverightmost
digitsare56789(i.e.,ithastheform00000000137...56789withanunknownnumberofdigitsinthemiddle).
Findthesumofallitsdigits.
Problem359:Hilbert'sNewHotel
Aninfinitenumberofpeople(numbered1,2,3,etc.)arelineduptogetaroomatHilbert'snewestinfinite
hotel.Thehotelcontainsaninfinitenumberoffloors(numbered1,2,3,etc.),andeachfloorcontainsan
infinitenumberofrooms(numbered1,2,3,etc.).
Initiallythehotelisempty.Hilbertdeclaresaruleonhowthenthpersonisassignedaroom:personngets
thefirstvacantroominthelowestnumberedfloorsatisfyingeitherofthefollowing:
thefloorisempty
thefloorisnotempty,andifthelatestpersontakingaroominthatfloorispersonm,thenm+nisa
https://projecteuler.net/show=all
111/163
5/2/2015
perfectsquare
Person1getsroom1infloor1sincefloor1isempty.
Person2doesnotgetroom2infloor1since1+2=3isnotaperfectsquare.
Person2insteadgetsroom1infloor2sincefloor2isempty.
Person3getsroom2infloor1since1+3=4isaperfectsquare.
Eventually,everypersoninthelinegetsaroominthehotel.
DefineP(f,r)tobenifpersonnoccupiesroomrinfloorf,and0ifnopersonoccupiestheroom.Hereare
afewexamples:
P(1,1)=1
P(1,2)=3
P(2,1)=2
P(10,20)=440
P(25,75)=4863
P(99,100)=19454
FindthesumofallP(f,r)forallpositivefandrsuchthatfr=71328803586048andgivethelast8digits
asyouranswer.
Problem360:ScarySphere
Giventwopoints(x1,y1,z1)and(x2,y2,z2)inthreedimensionalspace,theManhattandistancebetween
thosepointsisdefinedas
|x1x2|+|y1y2|+|z1z2|.
LetC(r)beaspherewithradiusrandcenterintheoriginO(0,0,0).
LetI(r)bethesetofallpointswithintegercoordinatesonthesurfaceofC(r).
LetS(r)bethesumoftheManhattandistancesofallelementsofI(r)totheoriginO.
E.g.S(45)=34518.
FindS(1010).
Problem361:SubsequenceofThueMorsesequence
TheThueMorsesequence{Tn}isabinarysequencesatisfying:
T0=0
T2n=Tn
T2n+1=1Tn
Thefirstseveraltermsof{Tn}aregivenasfollows:
01101001100101101001011001101001....
Wedefine{An}asthesortedsequenceofintegerssuchthatthebinaryexpressionofeachelementappears
asasubsequencein{Tn}.
Forexample,thedecimalnumber18isexpressedas10010inbinary.10010appearsin{Tn}(T8toT12),so
18isanelementof{An}.
Thedecimalnumber14isexpressedas1110inbinary.1110neverappearsin{Tn},so14isnotanelement
of{An}.
ThefirstseveraltermsofAnaregivenasfollows:
0 1 2 3 4 5 6 7 8
10 11 12
An 0 1 2 3 4 5 6 9 10 11 12 13 18
WecanalsoverifythatA100=3251andA1000=80852364498.
Findthelast9digitsof
Problem362:Squarefreefactors
https://projecteuler.net/show=all
112/163
5/2/2015
Considerthenumber54.
54canbefactoredin7distinctwaysintooneormorefactorslargerthan1:
54,227,318,69,336,239and2333.
Ifwerequirethatthefactorsareallsquarefreeonlytwowaysremain:336and2333.
Let'scallFsf(n)thenumberofwaysncanbefactoredintooneormoresquarefreefactorslargerthan1,so
Fsf(54)=2.
LetS(n)beFsf(k)fork=2ton.
S(100)=193.
FindS(10000000000).
Problem363:BzierCurves
AcubicBziercurveisdefinedbyfourpoints:P0,P1,P2andP3.
Thecurveisconstructedasfollows:
OnthesegmentsP0P1,P1P2andP2P3thepointsQ0,Q1and
Q2aredrawnsuchthat
P0Q0/P0P1=P1Q1/P1P2=P2Q2/P2P3=t(tin[0,1]).
OnthesegmentsQ0Q1andQ1Q2thepointsR0andR1are
drawnsuchthat
Q0R0/Q0Q1=Q1R1/Q1Q2=tforthesamevalueoft.
OnthesegmentR0R1thepointBisdrawnsuchthatR0B/
R0R1=tforthesamevalueoft.
TheBziercurvedefinedbythepointsP0,P1,P2,P3isthe
locusofBasQ0takesallpossiblepositionsonthesegment
P0P1.
(Pleasenotethatforallpointsthevalueoftisthesame.)
Atthis(external)webaddressyouwillfindanappletthatallowsyoutodragthepointsP0,P1,P2andP3to
seewhattheBziercurve(greencurve)definedbythosepointslookslike.YoucanalsodragthepointQ0
alongthesegmentP0P1.
FromtheconstructionitisclearthattheBziercurvewillbetangenttothesegmentsP0P1inP0andP2P3
inP3.
AcubicBziercurvewithP0=(1,0),P1=(1,v),P2=(v,1)andP3=(0,1)isusedtoapproximateaquartercircle.
Thevaluev>0ischosensuchthattheareaenclosedbythelinesOP0,OP3andthecurveisequalto/4
(theareaofthequartercircle).
Byhowmanypercentdoesthelengthofthecurvedifferfromthelengthofthequartercircle?
L/2
Thatis,ifListhelengthofthecurve,calculate100
/2
Giveyouranswerroundedto10digitsbehindthedecimalpoint.
Problem364:Comfortabledistance
ThereareNseatsinarow.Npeoplecomeaftereachothertofilltheseatsaccordingtothefollowingrules:
1. Ifthereisanyseatwhoseadjacentseat(s)arenotoccupiedtakesuchaseat.
2. Ifthereisnosuchseatandthereisanyseatforwhichonlyoneadjacentseatisoccupiedtakesucha
seat.
3. Otherwisetakeoneoftheremainingavailableseats.
LetT(N)bethenumberofpossibilitiesthatNseatsareoccupiedbyNpeoplewiththegivenrules.
ThefollowingfigureshowsT(4)=8.
https://projecteuler.net/show=all
113/163
5/2/2015
WecanverifythatT(10)=61632andT(1000)mod100000007=47255094.
FindT(1000000)mod100000007.
Problem365:Ahugebinomialcoefficient
ThebinomialcoeffientC(1018,109)isanumberwithmorethan9billion(9109)digits.
LetM(n,k,m)denotethebinomialcoefficientC(n,k)modulom.
CalculateM(1018,109,p*q*r)for1000<p<q<r<5000andp,q,rprime.
Problem366:StoneGameIII
Twoplayers,AntonandBernhard,areplayingthefollowinggame.
Thereisonepileofnstones.
Thefirstplayermayremoveanypositivenumberofstones,butnotthewholepile.
Thereafter,eachplayermayremoveatmosttwicethenumberofstoneshisopponenttookontheprevious
move.
Theplayerwhoremovesthelaststonewins.
E.g.n=5
Ifthefirstplayertakesanythingmorethanonestonethenextplayerwillbeabletotakeallremaining
stones.
Ifthefirstplayertakesonestone,leavingfour,hisopponentwilltakealsoonestone,leavingthreestones.
Thefirstplayercannottakeallthreebecausehemaytakeatmost2x1=2stones.Solet'ssayhetakesalso
onestone,leaving2.Thesecondplayercantakethetworemainingstonesandwins.
So5isalosingpositionforthefirstplayer.
Forsomewinningpositionsthereismorethanonepossiblemoveforthefirstplayer.
E.g.whenn=17thefirstplayercanremoveoneorfourstones.
LetM(n)bethemaximumnumberofstonesthefirstplayercantakefromawinningpositionathisfirstturn
andM(n)=0foranyotherposition.
M(n)forn100is728.
FindM(n)forn1018.Giveyouranswermodulo108.
Problem367:Bozosort
Bozosort,nottobeconfusedwiththeslightlylessefficientbogosort,consistsoutofcheckingiftheinput
sequenceissortedandifnotswappingrandomlytwoelements.Thisisrepeateduntileventuallythe
sequenceissorted.
Ifweconsiderallpermutationsofthefirst4naturalnumbersasinputtheexpectationvalueofthenumberof
swaps,averagedoverall4!inputsequencesis24.75.
Thealreadysortedsequencetakes0steps.
Inthisproblemweconsiderthefollowingvariantonbozosort.
Ifthesequenceisnotinorderwepickthreeelementsatrandomandshufflethesethreeelements
randomly.
All3!=6permutationsofthosethreeelementsareequallylikely.
Thealreadysortedsequencewilltake0steps.
Ifweconsiderallpermutationsofthefirst4naturalnumbersasinputtheexpectationvalueofthenumberof
https://projecteuler.net/show=all
114/163
5/2/2015
shuffles,averagedoverall4!inputsequencesis27.5.
Considerasinputsequencesthepermutationsofthefirst11naturalnumbers.
Averagedoverall11!inputsequences,whatistheexpectednumberofshufflesthissortingalgorithmwill
perform?
Giveyouranswerroundedtothenearestinteger.
Problem368:AKempnerlikeseries
Theharmonicseries1 +
1
1
1
+ + +...iswellknowntobedivergent.
2
3
4
Ifwehoweveromitfromthisserieseverytermwherethedenominatorhasa9init,theseriesremarkably
enoughconvergestoapproximately22.9206766193.
ThismodifiedharmonicseriesiscalledtheKempnerseries.
Letusnowconsideranothermodifiedharmonicseriesbyomittingfromtheharmonicserieseveryterm
wherethedenominatorhas3ormoreequalconsecutivedigits.Onecanverifythatoutofthefirst1200
termsoftheharmonicseries,only20termswillbeomitted.
These20omittedtermsare:
1
1
1
1
1
1
1
1
1
1
1
,
,
,
,
,
,
,
,
,
,
,
111 222 333 444 555 666 777 888 999 1000 1110
1
1
1
1
1
1
1
1
1
,
,
,
,
,
,
,
and
.
1111 1112 1113 1114 1115 1116 1117 1118
1119
Thisseriesconvergesaswell.
Findthevaluetheseriesconvergesto.
Giveyouranswerroundedto10digitsbehindthedecimalpoint.
Problem369:Badugi
Inastandard52carddeckofplayingcards,asetof4cardsisaBadugiifitcontains4cardswithnopairs
andnotwocardsofthesamesuit.
Letf(n)bethenumberofwaystochoosencardswitha4cardsubsetthatisaBadugi.Forexample,there
are2598960waystochoosefivecardsfromastandard52carddeck,ofwhich514800containa4card
subsetthatisaBadugi,sof(5)=514800.
Findf(n)for4n13.
Problem370:Geometrictriangles
Letusdefineageometrictriangleasanintegersidedtrianglewithsidesabcsothatitssidesforma
geometricprogression,i.e.b2=ac.
Anexampleofsuchageometrictriangleisthetrianglewithsidesa=144,b=156andc=169.
Thereare861805geometrictriangleswithperimeter106.
Howmanygeometrictrianglesexistwithperimeter2.51013?
Problem371:Licenceplates
Oregonlicenceplatesconsistofthreelettersfollowedbyathreedigitnumber(eachdigitcanbefrom[0..9]).
WhiledrivingtoworkSethplaysthefollowinggame:
Wheneverthenumbersoftwolicenceplatesseenonhistripaddto1000that'sawin.
E.g.MIC012andHAN988isawinandRYU500andSET500too.(aslongasheseestheminthesame
trip).
Findtheexpectednumberofplatesheneedstoseeforawin.
Giveyouranswerroundedto8decimalplacesbehindthedecimalpoint.
https://projecteuler.net/show=all
115/163
5/2/2015
Note:Weassumethateachlicenceplateseenisequallylikelytohaveanythreedigitnumberonit.
Problem372:Pencilsofrays
LetR(M,N)bethenumberoflatticepoints(x,y)whichsatisfyM<xN,M<yNand
isodd.
WecanverifythatR(0,100)=3019andR(100,10000)=29750422.
FindR(2106,109).
Note:
representsthefloorfunction.
Problem373:CircumscribedCircles
Everytrianglehasacircumscribedcirclethatgoesthroughthethreevertices.Considerallintegersided
trianglesforwhichtheradiusofthecircumscribedcircleisintegralaswell.
LetS(n)bethesumoftheradiiofthecircumscribedcirclesofallsuchtrianglesforwhichtheradiusdoes
notexceedn.
S(100)=4950andS(1200)=1653605.
FindS(107).
Problem374:MaximumIntegerPartitionProduct
Anintegerpartitionofanumbernisawayofwritingnasasumofpositiveintegers.
Partitionsthatdifferonlyintheorderoftheirsummandsareconsideredthesame.Apartitionofninto
distinctpartsisapartitionofninwhicheverypartoccursatmostonce.
Thepartitionsof5intodistinctpartsare:
5,4+1and3+2.
Letf(n)bethemaximumproductofthepartsofanysuchpartitionofnintodistinctpartsandletm(n)bethe
numberofelementsofanysuchpartitionofnwiththatproduct.
Sof(5)=6andm(5)=2.
Forn=10thepartitionwiththelargestproductis10=2+3+5,whichgivesf(10)=30andm(10)=3.
Andtheirproduct,f(10)m(10)=303=90
Itcanbeverifiedthat
f(n)m(n)for1n100=1683550844462.
Findf(n)m(n)for1n1014.
Giveyouranswermodulo982451653,the50millionthprime.
Problem375:Minimumofsubsequences
LetSnbeanintegersequenceproducedwiththefollowingpseudorandomnumbergenerator:
S0 = 290797
Sn+1 = Sn2mod50515093
LetA(i,j)betheminimumofthenumbersSi,Si+1,...,Sjforij.
LetM(N)=A(i,j)for1ijN.
WecanverifythatM(10)=432256955andM(10000)=3264567774119.
FindM(2000000000).
Problem376:Nontransitivesetsofdice
https://projecteuler.net/show=all
116/163
5/2/2015
Considerthefollowingsetofdicewithnonstandardpips:
DieA:144444
DieB:222555
DieC:333336
Agameisplayedbytwoplayerspickingadieinturnandrollingit.Theplayerwhorollsthehighestvalue
wins.
IfthefirstplayerpicksdieAandthesecondplayerpicksdieBweget
P(secondplayerwins)=7/12>1/2
IfthefirstplayerpicksdieBandthesecondplayerpicksdieCweget
P(secondplayerwins)=7/12>1/2
IfthefirstplayerpicksdieCandthesecondplayerpicksdieAweget
P(secondplayerwins)=25/36>1/2
Sowhateverdiethefirstplayerpicks,thesecondplayercanpickanotherdieandhavealargerthan50%
chanceofwinning.
Asetofdicehavingthispropertyiscalledanontransitivesetofdice.
Wewishtoinvestigatehowmanysetsofnontransitivediceexist.Wewillassumethefollowingconditions:
Therearethreesixsideddicewitheachsidehavingbetween1andNpips,inclusive.
Dicewiththesamesetofpipsareequal,regardlessofwhichsideonthediethepipsarelocated.
Thesamepipvaluemayappearonmultiplediceifbothplayersrollthesamevalueneitherplayer
wins.
Thesetsofdice{A,B,C},{B,C,A}and{C,A,B}arethesameset.
ForN=7wefindthereare9780suchsets.
HowmanyarethereforN=30?
Problem377:Sumofdigits,experience13
Thereare16positiveintegersthatdonothaveazerointheirdigitsandthathaveadigitalsumequalto5,
namely:
5,14,23,32,41,113,122,131,212,221,311,1112,1121,1211,2111and11111.
Theirsumis17891.
Letf(n)bethesumofallpositiveintegersthatdonothaveazerointheirdigitsandhaveadigitalsumequal
ton.
17
i
Find f (13 ).
i=1
Givethelast9digitsasyouranswer.
Problem378:TriangleTriples
LetT(n)bethenthtrianglenumber,soT(n)=
n(n+1)
2
LetdT(n)bethenumberofdivisorsofT(n).
E.g.:T(7)=28anddT(7)=6.
LetTr(n)bethenumberoftriples(i,j,k)suchthat1i<j<knanddT(i)>dT(j)>dT(k).
Tr(20)=14,Tr(100)=5772andTr(1000)=11174776.
FindTr(60000000).
Givethelast18digitsofyouranswer.
Problem379:Leastcommonmultiplecount
Letf(n)bethenumberofcouples(x,y)withxandypositiveintegers,xyandtheleastcommonmultiple
ofxandyequalton.
Letgbethesummatoryfunctionoff,i.e.:g(n)=f(i)for1in.
https://projecteuler.net/show=all
117/163
5/2/2015
Youaregiventhatg(106)=37429395.
Findg(1012).
Problem380:AmazingMazes!
Anmnmazeisanmnrectangulargridwithwallsplacedbetweengridcellssuchthatthereisexactlyone
pathfromthetopleftsquaretoanyothersquare.
Thefollowingareexamplesofa912mazeanda1520maze:
LetC(m,n)bethenumberofdistinctmnmazes.Mazeswhichcanbeformedbyrotationandreflection
fromanothermazeareconsidereddistinct.
ItcanbeverifiedthatC(1,1)=1,C(2,2)=4,C(3,4)=2415,andC(9,12)=2.5720e46(inscientificnotation
roundedto5significantdigits).
FindC(100,500)andwriteyouranswerinscientificnotationroundedto5significantdigits.
Whengivingyouranswer,usealowercaseetoseparatemantissaandexponent.E.g.iftheansweris
1234567891011thentheanswerformatwouldbe1.2346e12.
Problem381:(primek)factorial
ForaprimepletS(p)=((pk)!)mod(p)for1k5.
Forexample,ifp=7,
(71)!+(72)!+(73)!+(74)!+(75)!=6!+5!+4!+3!+2!=720+120+24+6+2=872.
As872mod(7)=4,S(7)=4.
ItcanbeverifiedthatS(p)=480for5p<100.
FindS(p)for5p<108.
Problem382:Generatingpolygons
Apolygonisaflatshapeconsistingofstraightlinesegmentsthatarejoinedtoformaclosedchainor
circuit.Apolygonconsistsofatleastthreesidesanddoesnotselfintersect.
AsetSofpositivenumbersissaidtogenerateapolygonPif:
notwosidesofParethesamelength,
thelengthofeverysideofPisinS,and
Scontainsnoothervalue.
Forexample:
Theset{3,4,5}generatesapolygonwithsides3,4,and5(atriangle).
Theset{6,9,11,24}generatesapolygonwithsides6,9,11,and24(aquadrilateral).
Thesets{1,2,3}and{2,3,4,9}donotgenerateanypolygonatall.
Considerthesequences,definedasfollows:
s1=1,s2=2,s3=3
sn=sn1+sn3forn>3.
LetUnbetheset{s1,s2,...,sn}.Forexample,U10={1,2,3,4,6,9,13,19,28,41}.
Letf(n)bethenumberofsubsetsofUnwhichgenerateatleastonepolygon.
Forexample,f(5)=7,f(10)=501andf(25)=18635853.
https://projecteuler.net/show=all
118/163
5/2/2015
Findthelast9digitsoff(1018).
Problem383:Divisibilitycomparisonbetweenfactorials
Letf5(n)bethelargestintegerxforwhich5xdividesn.
Forexample,f5(625000)=7.
LetT5(n)bethenumberofintegersiwhichsatisfyf5((2i1)!)<2f5(i!)and1in.
ItcanbeverifiedthatT5(103)=68andT5(109)=2408210.
FindT5(1018).
Problem384:RudinShapirosequence
Definethesequencea(n)asthenumberofadjacentpairsofonesinthebinaryexpansionofn(possibly
overlapping).
E.g.:a(5)=a(1012)=0,a(6)=a(1102)=1,a(7)=a(1112)=2
Definethesequenceb(n)=(1)a(n).
ThissequenceiscalledtheRudinShapirosequence.
Alsoconsiderthesummatorysequenceofb(n):
Thefirstcoupleofvaluesofthesesequencesare:
n 0 1 2 3 4 5 6 7
a(n) 0 0 0 1 0 0 1 2
b(n) 1 1 1 -1 1 1 -1 1
s(n) 1 2 3 2 3 4 3 4
Thesequences(n)hastheremarkablepropertythatallelementsarepositiveandeverypositiveintegerk
occursexactlyktimes.
Defineg(t,c),with1ct,astheindexins(n)forwhichtoccursforthec'thtimeins(n).
E.g.:g(3,3)=6,g(4,2)=7andg(54321,12345)=1220847710.
LetF(n)bethefibonaccisequencedefinedby:
F(0)=F(1)=1and
F(n)=F(n1)+F(n2)forn>1.
DefineGF(t)=g(F(t),F(t1)).
FindGF(t)for2t45.
Problem385:Ellipsesinsidetriangles
ForanytriangleTintheplane,itcanbeshownthatthereisauniqueellipsewithlargestareathatis
completelyinsideT.
Foragivenn,considertrianglesTsuchthat:
https://projecteuler.net/show=all
119/163
5/2/2015
theverticesofThaveintegercoordinateswithabsolutevaluen,and
thefoci1ofthelargestareaellipseinsideTare(13,0)and(13,0).
LetA(n)bethesumoftheareasofallsuchtriangles.
Forexample,ifn=8,therearetwosuchtriangles.Theirverticesare(4,3),(4,3),(8,0)and(4,3),(4,3),
(8,0),andtheareaofeachtriangleis36.ThusA(8)=36+36=72.
ItcanbeverifiedthatA(10)=252,A(100)=34632andA(1000)=3529008.
FindA(1000000000).
1Thefoci(pluraloffocus)ofanellipsearetwopointsAandBsuchthatforeverypointPontheboundary
oftheellipse,AP+PBisconstant.
Problem386:Maximumlengthofanantichain
LetnbeanintegerandS(n)bethesetoffactorsofn.
AsubsetAofS(n)iscalledanantichainofS(n)ifAcontainsonlyoneelementorifnoneoftheelementsof
AdividesanyoftheotherelementsofA.
Forexample:S(30)={1,2,3,5,6,10,15,30}
{2,5,6}isnotanantichainofS(30).
{2,3,5}isanantichainofS(30).
LetN(n)bethemaximumlengthofanantichainofS(n).
FindN(n)for1n108
Problem387:HarshadNumbers
AHarshadorNivennumberisanumberthatisdivisiblebythesumofitsdigits.
201isaHarshadnumberbecauseitisdivisibleby3(thesumofitsdigits.)
Whenwetruncatethelastdigitfrom201,weget20,whichisaHarshadnumber.
Whenwetruncatethelastdigitfrom20,weget2,whichisalsoaHarshadnumber.
Let'scallaHarshadnumberthat,whilerecursivelytruncatingthelastdigit,alwaysresultsinaHarshad
numberarighttruncatableHarshadnumber.
Also:
201/3=67whichisprime.
Let'scallaHarshadnumberthat,whendividedbythesumofitsdigits,resultsinaprimeastrongHarshad
number.
Nowtakethenumber2011whichisprime.
Whenwetruncatethelastdigitfromitweget201,astrongHarshadnumberthatisalsorighttruncatable.
Let'scallsuchprimesstrong,righttruncatableHarshadprimes.
Youaregiventhatthesumofthestrong,righttruncatableHarshadprimeslessthan10000is90619.
Findthesumofthestrong,righttruncatableHarshadprimeslessthan1014.
Problem388:DistinctLines
Consideralllatticepoints(a,b,c)with0a,b,cN.
FromtheoriginO(0,0,0)alllinesaredrawntotheotherlatticepoints.
LetD(N)bethenumberofdistinctsuchlines.
YouaregiventhatD(1000000)=831909254469114121.
FindD(1010).Giveasyouranswerthefirstninedigitsfollowedbythelastninedigits.
Problem389:PlatonicDice
Anunbiasedsingle4sideddieisthrownanditsvalue,T,isnoted.
Tunbiased6sideddicearethrownandtheirscoresareaddedtogether.Thesum,C,isnoted.
https://projecteuler.net/show=all
120/163
5/2/2015
Cunbiased8sideddicearethrownandtheirscoresareaddedtogether.Thesum,O,isnoted.
Ounbiased12sideddicearethrownandtheirscoresareaddedtogether.Thesum,D,isnoted.
Dunbiased20sideddicearethrownandtheirscoresareaddedtogether.Thesum,I,isnoted.
FindthevarianceofI,andgiveyouranswerroundedto4decimalplaces.
Problem390:Triangleswithnonrationalsidesandintegralarea
Considerthetrianglewithsides5,65and68.Itcanbeshownthatthistrianglehasarea9.
S(n)isthesumoftheareasofalltriangleswithsides(1+b2),(1+c2)and(b2+c2)(forpositiveintegersb
andc)thathaveanintegralareanotexceedingn.
Theexampletrianglehasb=2andc=8.
S(106)=18018206.
FindS(1010).
Problem391:HoppingGame
Letskbethenumberof1swhenwritingthenumbersfrom0tokinbinary.
Forexample,writing0to5inbinary,wehave0,1,10,11,100,101.Thereareseven1s,sos5=7.
ThesequenceS={sk:k0}starts{0,1,2,4,5,7,9,12,...}.
Agameisplayedbytwoplayers.Beforethegamestarts,anumbernischosen.Acountercstartsat0.At
eachturn,theplayerchoosesanumberfrom1ton(inclusive)andincreasescbythatnumber.The
resultingvalueofcmustbeamemberofS.Iftherearenomorevalidmoves,theplayerloses.
Forexample:
Letn=5.cstartsat0.
Player1chooses4,socbecomes0+4=4.
Player2chooses5,socbecomes4+5=9.
Player1chooses3,socbecomes9+3=12.
etc.
NotethatcmustalwaysbelongtoS,andeachplayercanincreasecbyatmostn.
LetM(n)bethehighestnumberthefirstplayercanchooseatherfirstturntoforceawin,andM(n)=0if
thereisnosuchmove.Forexample,M(2)=2,M(7)=1andM(20)=4.
Given(M(n))3=8150for1n20.
Find(M(n))3for1n1000.
Problem392:Enmeshedunitcircle
Arectilineargridisanorthogonalgridwherethespacingbetweenthegridlinesdoesnothavetobe
equidistant.
Anexampleofsuchgridislogarithmicgraphpaper.
ConsiderrectilineargridsintheCartesiancoordinatesystemwiththefollowingproperties:
ThegridlinesareparalleltotheaxesoftheCartesiancoordinatesystem.
ThereareN+2verticalandN+2horizontalgridlines.Hencethereare(N+1)x(N+1)rectangularcells.
Theequationsofthetwoouterverticalgridlinesarex=1andx=1.
Theequationsofthetwoouterhorizontalgridlinesarey=1andy=1.
Thegridcellsarecoloredrediftheyoverlapwiththeunitcircle,blackotherwise.
ForthisproblemwewouldlikeyoutofindthepostionsoftheremainingNinnerhorizontalandNinner
verticalgridlinessothattheareaoccupiedbytheredcellsisminimized.
E.g.hereisapictureofthesolutionforN=10:
https://projecteuler.net/show=all
121/163
5/2/2015
TheareaoccupiedbytheredcellsforN=10roundedto10digitsbehindthedecimalpointis
3.3469640797.
FindthepositionsforN=400.
Giveasyouranswertheareaoccupiedbytheredcellsroundedto10digitsbehindthedecimalpoint.
Problem393:Migratingants
Annngridofsquarescontainsn2ants,oneantpersquare.
Allantsdecidetomovesimultaneouslytoanadjacentsquare(usually4possibilities,exceptforantsonthe
edgeofthegridoratthecorners).
Wedefinef(n)tobethenumberofwaysthiscanhappenwithoutanyantsendingonthesamesquareand
withoutanytwoantscrossingthesameedgebetweentwosquares.
Youaregiventhatf(4)=88.
Findf(10).
Problem394:Eatingpie
Jeffeatsapieinanunusualway.
Thepieiscircular.Hestartswithslicinganinitialcutinthepiealongaradius.
WhilethereisatleastagivenfractionFofpieleft,heperformsthefollowingprocedure:
Hemakestwoslicesfromthepiecentretoanypointofwhatisremainingofthepieborder,anypointon
theremainingpieborderequallylikely.Thiswilldividetheremainingpieintothreepieces.
Goingcounterclockwisefromtheinitialcut,hetakesthefirsttwopiepiecesandeatsthem.
WhenlessthanafractionFofpieremains,hedoesnotrepeatthisprocedure.Instead,heeatsallofthe
remainingpie.
Forx1,letE(x)betheexpectednumberoftimesJeffrepeatstheprocedureabovewithF=1/x.
ItcanbeverifiedthatE(1)=1,E(2)1.2676536759,andE(7.5)2.1215732071.
FindE(40)roundedto10decimalplacesbehindthedecimalpoint.
Problem395:Pythagoreantree
ThePythagoreantreeisafractalgeneratedbythefollowingprocedure:
Startwithaunitsquare.Then,callingoneofthesidesitsbase(intheanimation,thebottomsideisthe
base):
1. Attacharighttriangletothesideoppositethebase,withthehypotenusecoincidingwiththatsideand
withthesidesina345ratio.Notethatthesmallersideofthetrianglemustbeonthe'right'sidewith
respecttothebase(seeanimation).
2. Attachasquaretoeachlegoftherighttriangle,withoneofitssidescoincidingwiththatleg.
3. Repeatthisprocedureforbothsquares,consideringastheirbasesthesidestouchingthetriangle.
https://projecteuler.net/show=all
122/163
5/2/2015
Theresultingfigure,afteraninfinitenumberofiterations,isthePythagoreantree.
Itcanbeshownthatthereexistsatleastonerectangle,whosesidesareparalleltothelargestsquareofthe
Pythagoreantree,whichenclosesthePythagoreantreecompletely.
Findthesmallestareapossibleforsuchaboundingrectangle,andgiveyouranswerroundedto10decimal
places.
Problem396:WeakGoodsteinsequence
Foranypositiveintegern,thenthweakGoodsteinsequence{g1,g2,g3,...}isdefinedas:
g1=n
fork>1,gkisobtainedbywritinggk1inbasek,interpretingitasabasek+1number,and
subtracting1.
Thesequenceterminateswhengkbecomes0.
Forexample,the6thweakGoodsteinsequenceis{6,11,17,25,...}:
g1=6.
g2=11since6=1102,1103=12,and121=11.
g3=17since11=1023,1024=18,and181=17.
g4=25since17=1014,1015=26,and261=25.
andsoon.
ItcanbeshownthateveryweakGoodsteinsequenceterminates.
LetG(n)bethenumberofnonzeroelementsinthenthweakGoodsteinsequence.
ItcanbeverifiedthatG(2)=3,G(4)=21andG(6)=381.
ItcanalsobeverifiedthatG(n)=2517for1n<8.
Findthelast9digitsofG(n)for1n<16.
Problem397:Triangleonparabola
Ontheparabolay=x2/k,threepointsA(a,a2/k),B(b,b2/k)andC(c,c2/k)arechosen.
LetF(K,X)bethenumberoftheintegerquadruplets(k,a,b,c)suchthatatleastoneangleofthetriangle
ABCis45degree,with1kKandXa<b<cX.
Forexample,F(1,10)=41andF(10,100)=12492.
FindF(106,109).
Problem398:Cuttingrope
Insidearopeoflengthn,n1pointsareplacedwithdistance1fromeachotherandfromtheendpoints.
Amongthesepoints,wechoosem1pointsatrandomandcuttheropeatthesepointstocreatem
segments.
https://projecteuler.net/show=all
123/163
5/2/2015
LetE(n,m)betheexpectedlengthofthesecondshortestsegment.
Forexample,E(3,2)=2andE(8,3)=16/7.
Notethatifmultiplesegmentshavethesameshortestlengththelengthofthesecondshortestsegmentis
definedasthesameastheshortestlength.
FindE(107,100).
Giveyouranswerroundedto5decimalplacesbehindthedecimalpoint.
Problem399:SquarefreeFibonacciNumbers
Thefirst15fibonaccinumbersare:
1,1,2,3,5,8,13,21,34,55,89,144,233,377,610.
Itcanbeseenthat8and144arenotsquarefree:8isdivisibleby4and144isdivisibleby4andby9.
Sothefirst13squarefreefibonaccinumbersare:
1,1,2,3,5,13,21,34,55,89,233,377and610.
The200thsquarefreefibonaccinumberis:
971183874599339129547649988289594072811608739584170445.
Thelastsixteendigitsofthisnumberare:1608739584170445andinscientificnotationthisnumbercanbe
writtenas9.7e53.
Findthe100000000thsquarefreefibonaccinumber.
Giveasyouransweritslastsixteendigitsfollowedbyacommafollowedbythenumberinscientificnotation
(roundedtoonedigitafterthedecimalpoint).
Forthe200thsquarefreenumbertheanswerwouldhavebeen:1608739584170445,9.7e53
Note:
Forthisproblem,assumethatforeveryprimep,thefirstfibonaccinumberdivisiblebypisnotdivisiblebyp2(thisispartofWall's
conjecture).Thishasbeenverifiedforprimes31015,buthasnotbeenproveningeneral.
Ifithappensthattheconjectureisfalse,thentheacceptedanswertothisproblemisn'tguaranteedtobethe100000000th
squarefreefibonaccinumber,ratheritrepresentsonlyalowerboundforthatnumber.
Problem400:Fibonaccitreegame
AFibonaccitreeisabinarytreerecursivelydefinedas:
T(0)istheemptytree.
T(1)isthebinarytreewithonlyonenode.
T(k)consistsofarootnodethathasT(k1)andT(k2)aschildren.
Onsuchatreetwoplayersplayatakeawaygame.Oneachturnaplayerselectsanodeandremovesthat
nodealongwiththesubtreerootedatthatnode.
Theplayerwhoisforcedtotaketherootnodeoftheentiretreeloses.
HerearethewinningmovesofthefirstplayeronthefirstturnforT(k)fromk=1tok=6.
Letf(k)bethenumberofwinningmovesofthefirstplayer(i.e.themovesforwhichthesecondplayerhas
nowinningstrategy)onthefirstturnofthegamewhenthisgameisplayedonT(k).
Forexample,f(5)=1andf(10)=17.
Findf(10000).Givethelast18digitsofyouranswer.
Problem401:Sumofsquaresofdivisors
Thedivisorsof6are1,2,3and6.
Thesumofthesquaresofthesenumbersis1+4+9+36=50.
Letsigma2(n)representthesumofthesquaresofthedivisorsofn.Thussigma2(6)=50.
https://projecteuler.net/show=all
124/163
5/2/2015
LetSIGMA2representthesummatoryfunctionofsigma2,thatisSIGMA2(n)=sigma2(i)fori=1ton.
Thefirst6valuesofSIGMA2are:1,6,16,37,63and113.
FindSIGMA2(1015)modulo109.
Problem402:Integervaluedpolynomials
Itcanbeshownthatthepolynomialn4+4n3+2n2+5nisamultipleof6foreveryintegern.Itcanalsobe
shownthat6isthelargestintegersatisfyingthisproperty.
DefineM(a,b,c)asthemaximummsuchthatn4+an3+bn2+cnisamultipleofmforallintegersn.For
example,M(4,2,5)=6.
Also,defineS(N)asthesumofM(a,b,c)forall0<a,b,cN.
WecanverifythatS(10)=1972andS(10000)=2024258331114.
LetFkbetheFibonaccisequence:
F0=0,F1=1and
Fk=Fk1+Fk2fork2.
Findthelast9digitsofS(Fk)for2k1234567890123.
Problem403:Latticepointsenclosedbyparabolaandline
Forintegersaandb,wedefineD(a,b)asthedomainenclosedbytheparabolay=x2andtheliney=ax
+b:
D(a,b)={(x,y)|x2yax+b}.
L(a,b)isdefinedasthenumberoflatticepointscontainedinD(a,b).
Forexample,L(1,2)=8andL(2,1)=1.
WealsodefineS(N)asthesumofL(a,b)forallthepairs(a,b)suchthattheareaofD(a,b)isarational
numberand|a|,|b|N.
WecanverifythatS(5)=344andS(100)=26709528.
FindS(1012).Giveyouranswermod108.
Problem404:CrisscrossEllipses
Eaisanellipsewithanequationoftheformx2+4y2=4a2.
Ea'istherotatedimageofEabydegreescounterclockwisearoundtheoriginO(0,0)for0<<90.
bisthedistancetotheoriginofthetwointersectionpointsclosesttotheoriginandcisthedistanceofthe
twootherintersectionpoints.
Wecallanorderedtriplet(a,b,c)acanonicalellipsoidaltripletifa,bandcarepositiveintegers.
Forexample,(209,247,286)isacanonicalellipsoidaltriplet.
https://projecteuler.net/show=all
125/163
5/2/2015
LetC(N)bethenumberofdistinctcanonicalellipsoidaltriplets(a,b,c)foraN.
ItcanbeverifiedthatC(103)=7,C(104)=106andC(106)=11845.
FindC(1017).
Problem405:Arectangulartiling
Wewishtotilearectanglewhoselengthistwiceitswidth.
LetT(0)bethetilingconsistingofasinglerectangle.
Forn>0,letT(n)beobtainedfromT(n1)byreplacingalltilesinthefollowingmanner:
ThefollowinganimationdemonstratesthetilingsT(n)fornfrom0to5:
Letf(n)bethenumberofpointswherefourtilesmeetinT(n).
Forexample,f(1)=0,f(4)=82andf(109)mod177=126897180.
Findf(10k)fork=1018,giveyouranswermodulo177.
Problem406:GuessingGame
Wearetryingtofindahiddennumberselectedfromthesetofintegers{1,2,...,n}byaskingquestions.
Eachnumber(question)weask,wegetoneofthreepossibleanswers:
"Yourguessislowerthanthehiddennumber"(andyouincuracostofa),or
"Yourguessishigherthanthehiddennumber"(andyouincuracostofb),or
"Yes,that'sit!"(andthegameends).
Giventhevalueofn,a,andb,anoptimalstrategyminimizesthetotalcostfortheworstpossiblecase.
Forexample,ifn=5,a=2,andb=3,thenwemaybeginbyasking"2"asourfirstquestion.
Ifwearetoldthat2ishigherthanthehiddennumber(foracostofb=3),thenwearesurethat"1"isthe
hiddennumber(foratotalcostof3).
Ifwearetoldthat2islowerthanthehiddennumber(foracostofa=2),thenournextquestionwillbe"4".
Ifwearetoldthat4ishigherthanthehiddennumber(foracostofb=3),thenwearesurethat"3"isthe
hiddennumber(foratotalcostof2+3=5).
Ifwearetoldthat4islowerthanthehiddennumber(foracostofa=2),thenwearesurethat"5"isthe
hiddennumber(foratotalcostof2+2=4).
Thus,theworstcasecostachievedbythisstrategyis5.Itcanalsobeshownthatthisisthelowestworst
casecostthatcanbeachieved.So,infact,wehavejustdescribedanoptimalstrategyforthegivenvalues
ofn,a,andb.
LetC(n,a,b)betheworstcasecostachievedbyanoptimalstrategyforthegivenvaluesofn,a,andb.
https://projecteuler.net/show=all
126/163
5/2/2015
Hereareafewexamples:
C(5,2,3)=5
C(500,2,3)=13.22073197...
C(20000,5,7)=82
C(2000000,5,7)=49.63755955...
LetFkbetheFibonaccinumbers:Fk=Fk1+Fk2withbasecasesF1=F2=1.
Find1k30C(1012,k,Fk),andgiveyouranswerroundedto8decimalplacesbehindthedecimalpoint.
Problem407:Idempotents
Ifwecalculatea2mod6for0a5weget:0,1,4,3,4,1.
Thelargestvalueofasuchthata2amod6is4.
Let'scallM(n)thelargestvalueofa<nsuchthata2a(modn).
SoM(6)=4.
FindM(n)for1n107.
Problem408:Admissiblepathsthroughagrid
Let'scallalatticepoint(x,y)inadmissibleifx,yandx+yareallpositiveperfectsquares.
Forexample,(9,16)isinadmissible,while(0,4),(3,1)and(9,4)arenot.
Considerapathfrompoint(x1,y1)topoint(x2,y2)usingonlyunitstepsnorthoreast.
Let'scallsuchapathadmissibleifnoneofitsintermediatepointsareinadmissible.
LetP(n)bethenumberofadmissiblepathsfrom(0,0)to(n,n).
ItcanbeverifiedthatP(5)=252,P(16)=596994440andP(1000)mod1000000007=341920854.
FindP(10000000)mod1000000007.
Problem409:NimExtreme
Letnbeapositiveinteger.Considernimpositionswhere:
Therearennonemptypiles.
Eachpilehassizelessthan2n.
Notwopileshavethesamesize.
LetW(n)bethenumberofwinningnimpositionssatisfyingtheaboveconditions(apositioniswinningifthe
firstplayerhasawinningstrategy).Forexample,W(1)=1,W(2)=6,W(3)=168,W(5)=19764360and
W(100)mod1000000007=384777056.
FindW(10000000)mod1000000007.
Problem410:Circleandtangentline
LetCbethecirclewithradiusr,x2+y2=r2.WechoosetwopointsP(a,b)andQ(a,c)sothattheline
passingthroughPandQistangenttoC.
Forexample,thequadruplet(r,a,b,c)=(2,6,2,7)satisfiesthisproperty.
LetF(R,X)bethenumberoftheintegerquadruplets(r,a,b,c)withthisproperty,andwith0<rRand0
<aX.
WecanverifythatF(1,5)=10,F(2,10)=52andF(10,100)=3384.
FindF(108,109)+F(109,108).
Problem411:Uphillpaths
https://projecteuler.net/show=all
127/163
5/2/2015
Letnbeapositiveinteger.Supposetherearestationsatthecoordinates(x,y)=(2imodn,3imodn)for0
i2n.Wewillconsiderstationswiththesamecoordinatesasthesamestation.
Wewishtoformapathfrom(0,0)to(n,n)suchthatthexandycoordinatesneverdecrease.
LetS(n)bethemaximumnumberofstationssuchapathcanpassthrough.
Forexample,ifn=22,thereare11distinctstations,andavalidpathcanpassthroughatmost5stations.
Therefore,S(22)=5.Thecaseisillustratedbelow,withanexampleofanoptimalpath:
ItcanalsobeverifiedthatS(123)=14andS(10000)=48.
FindS(k5)for1k30.
Problem412:Gnomonnumbering
Forintegersm,n(0n<m),letL(m,n)beanmmgridwiththetoprightnngridremoved.
Forexample,L(5,3)lookslikethis:
WewanttonumbereachcellofL(m,n)withconsecutiveintegers1,2,3,...suchthatthenumberinevery
cellissmallerthanthenumberbelowitandtotheleftofit.
Forexample,herearetwovalidnumberingsofL(5,3):
LetLC(m,n)bethenumberofvalidnumberingsofL(m,n).
ItcanbeverifiedthatLC(3,0)=42,LC(5,3)=250250,LC(6,3)=406029023400andLC(10,5)mod
76543217=61251715.
FindLC(10000,5000)mod76543217.
Problem413:OnechildNumbers
Wesaythataddigitpositivenumber(noleadingzeros)isaonechildnumberifexactlyoneofitssub
stringsisdivisiblebyd.
https://projecteuler.net/show=all
128/163
5/2/2015
Forexample,5671isa4digitonechildnumber.Amongallitssubstrings5,6,7,1,56,67,71,567,671
and5671,only56isdivisibleby4.
Similarly,104isa3digitonechildnumberbecauseonly0isdivisibleby3.
1132451isa7digitonechildnumberbecauseonly245isdivisibleby7.
LetF(N)bethenumberoftheonechildnumberslessthanN.
WecanverifythatF(10)=9,F(103)=389andF(107)=277674.
FindF(1019).
Problem414:Kaprekarconstant
6174isaremarkablenumberifwesortitsdigitsinincreasingorderandsubtractthatnumberfromthe
numberyougetwhenyousortthedigitsindecreasingorder,weget76411467=6174.
Evenmoreremarkableisthatifwestartfromany4digitnumberandrepeatthisprocessofsortingand
subtracting,we'lleventuallyendupwith6174orimmediatelywith0ifalldigitsareequal.
Thisalsoworkswithnumbersthathavelessthan4digitsifwepadthenumberwithleadingzeroesuntilwe
have4digits.
E.g.let'sstartwiththenumber0837:
87300378=8352
85322358=6174
6174iscalledtheKaprekarconstant.Theprocessofsortingandsubtractingandrepeatingthisuntileither
0ortheKaprekarconstantisreachediscalledtheKaprekarroutine.
WecanconsidertheKaprekarroutineforotherbasesandnumberofdigits.
Unfortunately,itisnotguaranteedaKaprekarconstantexistsinallcaseseithertheroutinecanendupina
cycleforsomeinputnumbersortheconstanttheroutinearrivesatcanbedifferentfordifferentinput
numbers.
However,itcanbeshownthatfor5digitsandabaseb=6t+39,aKaprekarconstantexists.
E.g.base15:(10,4,14,9,5)15
base21:(14,6,20,13,7)21
DefineCbtobetheKaprekarconstantinbasebfor5digits.Definethefunctionsb(i)tobe
0ifi=Cborifiwritteninbasebconsistsof5identicaldigits
thenumberofiterationsittakestheKaprekarroutineinbasebtoarriveatCb,otherwise
Notethatwecandefinesb(i)forallintegersi<b5.Ifiwritteninbasebtakeslessthan5digits,thenumber
ispaddedwithleadingzerodigitsuntilwehave5digitsbeforeapplyingtheKaprekarroutine.
DefineS(b)asthesumofsb(i)for0<i<b5.
E.g.S(15)=5274369
S(111)=400668930299
FindthesumofS(6k+3)for2k300.
Givethelast18digitsasyouranswer.
Problem415:Titanicsets
AsetoflatticepointsSiscalledatitanicsetifthereexistsalinepassingthroughexactlytwopointsinS.
AnexampleofatitanicsetisS={(0,0),(0,1),(0,2),(1,1),(2,0),(1,0)},wherethelinepassingthrough(0,
1)and(2,0)doesnotpassthroughanyotherpointinS.
Ontheotherhand,theset{(0,0),(1,1),(2,2),(4,4)}isnotatitanicsetsincethelinepassingthroughany
twopointsinthesetalsopassesthroughtheothertwo.
ForanypositiveintegerN,letT(N)bethenumberoftitanicsetsSwhoseeverypoint(x,y)satisfies0x,y
N.ItcanbeverifiedthatT(1)=11,T(2)=494,T(4)=33554178,T(111)mod108=13500401and
T(105)mod108=63259062.
FindT(1011)mod108.
Problem416:Afrog'strip
Arowofnsquarescontainsafrogintheleftmostsquare.Bysuccessivejumpsthefroggoestothe
rightmostsquareandthenbacktotheleftmostsquare.Ontheoutwardtriphejumpsone,twoorthree
https://projecteuler.net/show=all
129/163
5/2/2015
squarestotheright,andonthehomewardtriphejumpstotheleftinasimilarmanner.Hecannotjump
outsidethesquares.Herepeatstheroundtriptravelmtimes.
LetF(m,n)bethenumberofthewaysthefrogcantravelsothatatmostonesquareremainsunvisited.
Forexample,F(1,3)=4,F(1,4)=15,F(1,5)=46,F(2,3)=16andF(2,100)mod109=429619151.
Findthelast9digitsofF(10,1012).
Problem417:ReciprocalcyclesII
Aunitfractioncontains1inthenumerator.Thedecimalrepresentationoftheunitfractionswith
denominators2to10aregiven:
1/
2
1/
3
1/
4
1/
5
1/
6
1/
7
1/
8
1/
9
1/
10
= 0.5
= 0.(3)
= 0.25
= 0.2
= 0.1(6)
= 0.(142857)
= 0.125
= 0.(1)
= 0.1
Where0.1(6)means0.166666...,andhasa1digitrecurringcycle.Itcanbeseenthat1/7hasa6digit
recurringcycle.
Unitfractionswhosedenominatorhasnootherprimefactorsthan2and/or5arenotconsideredtohavea
recurringcycle.
Wedefinethelengthoftherecurringcycleofthoseunitfractionsas0.
LetL(n)denotethelengthoftherecurringcycleof1/n.YouaregiventhatL(n)for3n1000000
equals55535191115.
FindL(n)for3n100000000
Problem418:Factorisationtriples
Letnbeapositiveinteger.Anintegertriple(a,b,c)iscalledafactorisationtripleofnif:
1abc
abc=n.
Definef(n)tobea+b+cforthefactorisationtriple(a,b,c)ofnwhichminimisesc/a.Onecanshowthat
thistripleisunique.
Forexample,f(165)=19,f(100100)=142andf(20!)=4034872.
Findf(43!).
Problem419:Lookandsaysequence
Thelookandsaysequencegoes1,11,21,1211,111221,312211,13112221,1113213211,...
Thesequencestartswith1andallothermembersareobtainedbydescribingthepreviousmemberinterms
ofconsecutivedigits.
Ithelpstodothisoutloud:
1is'oneone'11
11is'twoones'21
21is'onetwoandoneone'1211
1211is'oneone,onetwoandtwoones'111221
111221is'threeones,twotwosandoneone'312211
...
DefineA(n),B(n)andC(n)asthenumberofones,twosandthreesinthen'thelementofthesequence
respectively.
https://projecteuler.net/show=all
130/163
5/2/2015
OnecanverifythatA(40)=31254,B(40)=20259andC(40)=11625.
FindA(n),B(n)andC(n)forn=1012.
Giveyouranswermodulo230andseparateyourvaluesforA,BandCbyacomma.
E.g.forn=40theanswerwouldbe31254,20259,11625
Problem420:2x2positiveintegermatrix
Apositiveintegermatrixisamatrixwhoseelementsareallpositiveintegers.
Somepositiveintegermatricescanbeexpressedasasquareofapositiveintegermatrixintwodifferent
ways.Hereisanexample:
WedefineF(N)asthenumberofthe2x2positiveintegermatriceswhichhaveatracelessthanNand
whichcanbeexpressedasasquareofapositiveintegermatrixintwodifferentways.
WecanverifythatF(50)=7andF(1000)=1019.
FindF(107).
Problem421:Primefactorsofn15+1
Numbersoftheformn15+1arecompositeforeveryintegern>1.
Forpositiveintegersnandmlets(n,m)bedefinedasthesumofthedistinctprimefactorsofn15+1not
exceedingm.
E.g.215+1=3311331.
Sos(2,10)=3ands(2,1000)=3+11+331=345.
Also1015+1=7111321124121619091.
Sos(10,100)=31ands(10,1000)=483.
Finds(n,108)for1n1011.
Problem422:Sequenceofpointsonahyperbola
LetHbethehyperboladefinedbytheequation12x2+7xy12y2=625.
Next,defineXasthepoint(7,1).ItcanbeseenthatXisinH.
NowwedefineasequenceofpointsinH,{Pi:i1},as:
P1=(13,61/4).
P2=(43/6,4).
Fori>2,PiistheuniquepointinHthatisdifferentfromPi1andsuchthatlinePiPi1isparalleltoline
Pi2X.ItcanbeshownthatPiiswelldefined,andthatitscoordinatesarealwaysrational.
https://projecteuler.net/show=all
131/163
5/2/2015
YouaregiventhatP3=(19/2,229/24),P4=(1267/144,37/12)andP7=(17194218091/143327232,
274748766781/1719926784).
FindPnforn=1114inthefollowingformat:
IfPn=(a/b,c/d)wherethefractionsareinlowesttermsandthedenominatorsarepositive,thentheanswer
is(a+b+c+d)mod1000000007.
Forn=7,theanswerwouldhavebeen:806236837.
Problem423:Consecutivediethrows
Letnbeapositiveinteger.
A6sideddieisthrownntimes.Letcbethenumberofpairsofconsecutivethrowsthatgivethesame
value.
Forexample,ifn=7andthevaluesofthediethrowsare(1,1,5,6,6,6,3),thenthefollowingpairsof
consecutivethrowsgivethesamevalue:
(1,1,5,6,6,6,3)
(1,1,5,6,6,6,3)
(1,1,5,6,6,6,3)
Therefore,c=3for(1,1,5,6,6,6,3).
DefineC(n)asthenumberofoutcomesofthrowinga6sideddientimessuchthatcdoesnotexceed
(n).1
Forexample,C(3)=216,C(4)=1290,C(11)=361912500andC(24)=4727547363281250000.
DefineS(L)asC(n)for1nL.
Forexample,S(50)mod1000000007=832833871.
FindS(50000000)mod1000000007.
1denotestheprimecountingfunction,i.e.(n)isthenumberofprimesn.
Problem424:Kakuro
https://projecteuler.net/show=all
132/163
5/2/2015
Theaboveisanexampleofacryptickakuro(alsoknownascrosssums,orevensumscross)puzzle,with
itsfinalsolutionontheright.(Thecommonrulesofkakuropuzzlescanbefoundeasilyonnumerous
internetsites.Otherrelatedinformationcanalsobecurrentlyfoundatkrazydad.comwhoseauthorhas
providedthepuzzledataforthischallenge.)
Thedownloadabletextfile(kakuro200.txt)containsthedescriptionof200suchpuzzles,amixof5x5and
6x6types.Thefirstpuzzleinthefileistheaboveexamplewhichiscodedasfollows:
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
Thefirstcharacterisanumericaldigitindicatingthesizeoftheinformationgrid.Itwouldbeeithera6(fora
5x5kakuropuzzle)ora7(fora6x6puzzle)followedbyacomma(,).Theextratoplineandleftcolumnare
neededtoinsertinformation.
Thecontentofeachcellisthendescribedandfollowedbyacomma,goinglefttorightandstartingwiththe
topline.
X=Graycell,notrequiredtobefilledbyadigit.
O(uppercaseletter)=Whiteemptycelltobefilledbyadigit.
A=OranyoneoftheuppercaselettersfromAtoJtobereplacedbyitsequivalentdigitinthesolved
puzzle.
()=Locationoftheencryptedsums.Horizontalsumsareprecededbyalowercase"h"andverticalsums
areprecededbyalowercase"v".Thosearefollowedbyoneortwouppercaselettersdependingifthesum
isasingledigitordoubledigitone.Fordoubledigitsums,thefirstletterwouldbeforthe"tens"andthe
secondoneforthe"units".Whenthecellmustcontaininformationforbothahorizontalandaverticalsum,
thefirstoneisalwaysforthehorizontalsumandthetwoareseparatedbyacommawithinthesamesetof
brackets,ex.:(hFE,vD).Eachsetofbracketsisalsoimmediatelyfollowedbyacomma.
ThedescriptionofthelastcellisfollowedbyaCarriageReturn/LineFeed(CRLF)insteadofacomma.
Therequiredanswertoeachpuzzleisbasedonthevalueofeachletternecessarytoarriveatthesolution
andaccordingtothealphabeticalorder.Asindicatedundertheexamplepuzzle,itsanswerwouldbe
8426039571.Atleast9outofthe10encryptinglettersarealwayspartoftheproblemdescription.When
only9aregiven,themissingonemustbeassignedtheremainingdigit.
Youaregiventhatthesumoftheanswersforthefirst10puzzlesinthefileis64414157580.
Findthesumoftheanswersforthe200puzzles.
Problem425:Primeconnection
TwopositivenumbersAandBaresaidtobeconnected(denotedby"AB")ifoneoftheseconditions
holds:
(1)AandBhavethesamelengthanddifferinexactlyonedigitforexample,123173.
(2)AddingonedigittotheleftofA(orB)makesB(orA)forexample,23223and12323.
WecallaprimePa2'srelativeifthereexistsachainofconnectedprimesbetween2andPandnoprimein
thechainexceedsP.
Forexample,127isa2'srelative.Oneofthepossiblechainsisshownbelow:
2313113103107127
However,11and103arenot2'srelatives.
LetF(N)bethesumoftheprimesNwhicharenot2'srelatives.
WecanverifythatF(103)=431andF(104)=78728.
FindF(107).
https://projecteuler.net/show=all
133/163
5/2/2015
Problem426:Boxballsystem
Consideraninfiniterowofboxes.Someoftheboxescontainaball.Forexample,aninitialconfigurationof2
consecutiveoccupiedboxesfollowedby2emptyboxes,2occupiedboxes,1emptybox,and2occupied
boxescanbedenotedbythesequence(2,2,2,1,2),inwhichthenumberofconsecutiveoccupiedand
emptyboxesappearalternately.
Aturnconsistsofmovingeachballexactlyonceaccordingtothefollowingrule:Transfertheleftmostball
whichhasnotbeenmovedtothenearestemptyboxtoitsright.
Afteroneturnthesequence(2,2,2,1,2)becomes(2,2,1,2,3)ascanbeseenbelownotethatwebegin
thenewsequencestartingatthefirstoccupiedbox.
AsystemlikethisiscalledaBoxBallSystemorBBSforshort.
Itcanbeshownthatafterasufficientnumberofturns,thesystemevolvestoastatewheretheconsecutive
numbersofoccupiedboxesisinvariant.Intheexamplebelow,theconsecutivenumbersofoccupied
boxesevolvesto[1,2,3]weshallcallthisthefinalstate.
Wedefinethesequence{ti}:
s0=290797
sk+1=sk2mod50515093
tk=(skmod64)+1
Startingfromtheinitialconfiguration(t0,t1,,t10),thefinalstatebecomes[1,3,10,24,51,75].
Startingfromtheinitialconfiguration(t0,t1,,t10000000),findthefinalstate.
Giveasyouranswerthesumofthesquaresoftheelementsofthefinalstate.Forexample,ifthefinalstate
is[1,2,3]then14(=12+22+32)isyouranswer.
Problem427:nsequences
AsequenceofintegersS={si}iscalledannsequenceifithasnelementsandeachelementsisatisfies1
sin.Thustherearenndistinctnsequencesintotal.Forexample,thesequenceS={1,5,5,10,7,7,7,
2,3,7}isa10sequence.
ForanysequenceS,letL(S)bethelengthofthelongestcontiguoussubsequenceofSwiththesamevalue.
Forexample,forthegivensequenceSabove,L(S)=3,becauseofthethreeconsecutive7's.
Letf(n)=L(S)forallnsequencesS.
Forexample,f(3)=45,f(7)=1403689andf(11)=481496895121.
Findf(7500000)mod1000000009.
Problem428:Necklaceofcircles
Leta,bandcbepositivenumbers.
LetW,X,Y,Zbefourcollinearpointswhere|WX|=a,|XY|=b,|YZ|=cand|WZ|=a+b+c.
LetCinbethecirclehavingthediameterXY.
LetCoutbethecirclehavingthediameterWZ.
Thetriplet(a,b,c)iscalledanecklacetripletifyoucanplacek3distinctcirclesC1,C2,...,Cksuchthat:
https://projecteuler.net/show=all
134/163
5/2/2015
CihasnocommoninteriorpointswithanyCjfor1i,jkandij,
CiistangenttobothCinandCoutfor1ik,
CiistangenttoCi+1for1i<k,and
CkistangenttoC1.
Forexample,(5,5,5)and(4,3,21)arenecklacetriplets,whileitcanbeshownthat(2,2,5)isnot.
LetT(n)bethenumberofnecklacetriplets(a,b,c)suchthata,bandcarepositiveintegers,andbn.For
example,T(1)=9,T(20)=732andT(3000)=438106.
FindT(1000000000).
Problem429:Sumofsquaresofunitarydivisors
Aunitarydivisordofanumbernisadivisorofnthathasthepropertygcd(d,n/d)=1.
Theunitarydivisorsof4!=24are1,3,8and24.
Thesumoftheirsquaresis12+32+82+242=650.
LetS(n)representthesumofthesquaresoftheunitarydivisorsofn.ThusS(4!)=650.
FindS(100000000!)modulo1000000009.
Problem430:Rangeflips
Ndisksareplacedinarow,indexed1toNfromlefttoright.
Eachdiskhasablacksideandwhiteside.Initiallyalldisksshowtheirwhiteside.
Ateachturn,two,notnecessarilydistinct,integersAandBbetween1andN(inclusive)arechosen
uniformlyatrandom.
AlldiskswithanindexfromAtoB(inclusive)areflipped.
ThefollowingexampleshowsthecaseN=8.AtthefirstturnA=5andB=2,andatthesecondturnA=4
andB=6.
LetE(N,M)betheexpectednumberofdisksthatshowtheirwhitesideafterMturns.
WecanverifythatE(3,1)=10/9,E(3,2)=5/3,E(10,4)5.157andE(100,10)51.893.
FindE(1010,4000).
Giveyouranswerroundedto2decimalplacesbehindthedecimalpoint.
https://projecteuler.net/show=all
135/163
5/2/2015
Problem431:SquareSpaceSilo
Fredthefarmerarrangestohaveanewstoragesiloinstalledonhisfarmandhavinganobsessionforall
thingssquareheisabsolutelydevastatedwhenhediscoversthatitiscircular.Quentin,therepresentative
fromthecompanythatinstalledthesilo,explainsthattheyonlymanufacturecylindricalsilos,buthepoints
outthatitisrestingonasquarebase.Fredisnotamusedandinsiststhatitisremovedfromhisproperty.
QuickthinkingQuentinexplainsthatwhengranularmaterialsaredeliveredfromaboveaconicalslopeis
formedandthenaturalanglemadewiththehorizontaliscalledtheangleofrepose.Forexampleifthe
angleofrepose, = 30 degrees,andgrainisdeliveredatthecentreofthesilothenaperfectconewill
formtowardsthetopofthecylinder.Inthecaseofthissilo,whichhasadiameterof6m,theamountof
spacewastedwouldbeapproximately32.648388556m3.However,ifgrainisdeliveredatapointonthetop
whichhasahorizontaldistanceofx metresfromthecentrethenaconewithastrangelycurvedandsloping
baseisformed.HeshowsFredapicture.
Problem432:Totientsum
LetS(n,m)=(ni)for1im.(isEuler'stotientfunction)
YouaregiventhatS(510510,106)=45480596821125120.
FindS(510510,1011).
Givethelast9digitsofyouranswer.
Problem433:StepsinEuclid'salgorithm
LetE(x0,y0)bethenumberofstepsittakestodeterminethegreatestcommondivisorofx0andy0with
Euclid'salgorithm.Moreformally:
x1=y0,y1=x0mody0
xn=yn1,yn=xn1modyn1
E(x0,y0)isthesmallestnsuchthatyn=0.
https://projecteuler.net/show=all
136/163
5/2/2015
WehaveE(1,1)=1,E(10,6)=3andE(6,10)=4.
DefineS(N)asthesumofE(x,y)for1x,yN.
WehaveS(1)=1,S(10)=221andS(100)=39826.
FindS(5106).
Problem434:Rigidgraphs
Recallthatagraphisacollectionofverticesandedgesconnectingthevertices,andthattwovertices
connectedbyanedgearecalledadjacent.
GraphscanbeembeddedinEuclideanspacebyassociatingeachvertexwithapointintheEuclidean
space.
Aflexiblegraphisanembeddingofagraphwhereitispossibletomoveoneormoreverticescontinuously
sothatthedistancebetweenatleasttwononadjacentverticesisalteredwhilethedistancesbetweeneach
pairofadjacentverticesiskeptconstant.
Arigidgraphisanembeddingofagraphwhichisnotflexible.
Informally,agraphisrigidifbyreplacingtheverticeswithfullyrotatinghingesandtheedgeswithrodsthat
areunbendingandinelastic,nopartsofthegraphcanbemovedindependentlyfromtherestofthegraph.
ThegridgraphsembeddedintheEuclideanplanearenotrigid,asthefollowinganimationdemonstrates:
However,onecanmakethemrigidbyaddingdiagonaledgestothecells.Forexample,forthe2x3grid
graph,thereare19waystomakethegraphrigid:
Notethatforthepurposesofthisproblem,wedonotconsiderchangingtheorientationofadiagonaledge
oraddingbothdiagonaledgestoacellasadifferentwayofmakingagridgraphrigid.
LetR(m,n)bethenumberofwaystomakethemngridgraphrigid.
E.g.R(2,3)=19andR(5,5)=23679901
DefineS(N)asR(i,j)for1i,jN.
E.g.S(5)=25021721.
FindS(100),giveyouranswermodulo1000000033
Problem435:PolynomialsofFibonaccinumbers
TheFibonaccinumbers{fn,n0}aredefinedrecursivelyasfn=fn1+fn2withbasecasesf0=0andf1=
1.
Definethepolynomials{Fn,n0}asFn(x)=fixifor0in.
Forexample,F7(x)=x+x2+2x3+3x4+5x5+8x6+13x7,andF7(11)=268357683.
Letn=1015.Findthesum[0x100Fn(x)]mod1307674368000(=15!).
Problem436:Unfairwager
https://projecteuler.net/show=all
137/163
5/2/2015
JulieproposesthefollowingwagertohersisterLouise.
Shesuggeststheyplayagameofchancetodeterminewhowillwashthedishes.
Forthisgame,theyshalluseageneratorofindependentrandomnumbersuniformlydistributedbetween0
and1.
ThegamestartswithS=0.
Thefirstplayer,Louise,addstoSdifferentrandomnumbersfromthegeneratoruntilS>1andrecordsher
lastrandomnumber'x'.
Thesecondplayer,Julie,continuesaddingtoSdifferentrandomnumbersfromthegeneratoruntilS>2and
recordsherlastrandomnumber'y'.
Theplayerwiththehighestnumberwinsandtheloserwashesthedishes,i.e.ify>xthesecondplayer
wins.
Forexample,ifthefirstplayerdraws0.62and0.44,thefirstplayerturnendssince0.62+0.44>1andx=
0.44.
Ifthesecondplayersdraws0.1,0.27and0.91,thesecondplayerturnendssince0.62+0.44+0.1+0.27+0.91
>2andy=0.91.Sincey>x,thesecondplayerwins.
Louisethinksaboutitforasecond,andobjects:"That'snotfair".
Whatistheprobabilitythatthesecondplayerwins?
Giveyouranswerroundedto10placesbehindthedecimalpointintheform0.abcdefghij
Problem437:Fibonacciprimitiveroots
Whenwecalculate8nmodulo11forn=0to9weget:1,8,9,6,4,10,3,2,5,7.
Asweseeallpossiblevaluesfrom1to10occur.So8isaprimitiverootof11.
Butthereismore:
Ifwetakeacloserlookwesee:
1+8=9
8+9=176mod11
9+6=154mod11
6+4=10
4+10=143mod11
10+3=132mod11
3+2=5
2+5=7
5+7=121mod11.
Sothepowersof8mod11arecyclicwithperiod10,and8n+8n+18n+2(mod11).
8iscalledaFibonacciprimitiverootof11.
NoteveryprimehasaFibonacciprimitiveroot.
Thereare323primeslessthan10000withoneormoreFibonacciprimitiverootsandthesumofthese
primesis1480491.
Findthesumoftheprimeslessthan100,000,000withatleastoneFibonacciprimitiveroot.
Problem438:Integerpartofpolynomialequation'ssolutions
Foranntupleofintegerst=(a1,...,an),let(x1,...,xn)bethesolutionsofthepolynomialequationxn+
a1xn1+a2xn2+...+an1x+an=0.
Considerthefollowingtwoconditions:
x1,...,xnareallreal.
Ifx1,...,xnaresorted,xi=ifor1in.(:floorfunction.)
Inthecaseofn=4,thereare12ntuplesofintegerswhichsatisfybothconditions.
WedefineS(t)asthesumoftheabsolutevaluesoftheintegersint.
Forn=4wecanverifythatS(t)=2087forallntuplestwhichsatisfybothconditions.
FindS(t)forn=7.
Problem439:Sumofsumofdivisors
Letd(k)bethesumofalldivisorsofk.
WedefinethefunctionS(N)=1iN1jNd(ij).
https://projecteuler.net/show=all
138/163
5/2/2015
Forexample,S(3)=d(1)+d(2)+d(3)+d(2)+d(4)+d(6)+d(3)+d(6)+d(9)=59.
YouaregiventhatS(103)=563576517282andS(105)mod109=215766508.
FindS(1011)mod109.
Problem440:GCDandTiling
Wewanttotileaboardoflengthnandheight1completely,witheither12blocksor11blockswitha
singledecimaldigitontop:
Forexample,herearesomeofthewaystotileaboardoflengthn=8:
LetT(n)bethenumberofwaystotileaboardoflengthnasdescribedabove.
Forexample,T(1)=10andT(2)=101.
LetS(L)bethetriplesuma,b,cgcd(T(ca),T(cb))for1a,b,cL.
Forexample:
S(2)=10444
S(3)=1292115238446807016106539989
S(4)mod987898789=670616280.
FindS(2000)mod987898789.
Problem441:Theinversesummationofcoprimecouples
ForanintegerM,wedefineR(M)asthesumof1/(pq)foralltheintegerpairspandqwhichsatisfyallof
theseconditions:
1p<qM
p+qM
pandqarecoprime.
WealsodefineS(N)asthesumofR(i)for2iN.
WecanverifythatS(2)=R(2)=1/2,S(10)6.9147andS(100)58.2962.
FindS(107).Giveyouranswerroundedtofourdecimalplaces.
Problem442:Elevenfreeintegers
Anintegeriscalledelevenfreeifitsdecimalexpansiondoesnotcontainanysubstringrepresentingapower
of11except1.
Forexample,2404and13431areelevenfree,while911and4121331arenot.
LetE(n)bethenthpositiveelevenfreeinteger.Forexample,E(3)=3,E(200)=213andE(500000)=
531563.
FindE(1018).
https://projecteuler.net/show=all
139/163
5/2/2015
Problem443:GCDsequence
Letg(n)beasequencedefinedasfollows:
g(4)=13,
g(n)=g(n1)+gcd(n,g(n1))forn>4.
Thefirstfewvaluesare:
10 11 12 13 14 15 16 17 18 19 20 ...
g(n) 13 14 16 17 18 27 28 29 30 31 32 33 34 51 54 55 60 ...
Youaregiventhatg(1000)=2524andg(1000000)=2624152.
Findg(1015).
Problem444:TheRoundtableLottery
Agroupofppeopledecidetositdownataroundtableandplayalotterytickettradinggame.Eachperson
startsoffwitharandomlyassigned,unscratchedlotteryticket.Eachticket,whenscratched,revealsa
wholepoundprizeranginganywherefrom1top,withnotwoticketsalike.Thegoalofthegameisfor
eachpersontomaximizehisticketwinningsuponleavingthegame.
Anarbitrarypersonischosentobethefirstplayer.Goingaroundthetable,eachplayerhasonlyoneoftwo
options:
1.Theplayercanscratchhisticketandrevealitsworthtoeveryoneatthetable.
2.Theplayercantradehisunscratchedticketforapreviousplayer'sscratchedticket,andthenleavethe
gamewiththatticket.Thepreviousplayerthenscratcheshisnewlyacquiredticketandrevealsitsworthto
everyoneatthetable.
Thegameendsonceallticketshavebeenscratched.Allplayersstillremainingatthetablemustleavewith
theircurrentlyheldtickets.
Assumethateachplayerusestheoptimalstrategyformaximizingtheexpectedvalueofhisticketwinnings.
LetE(p)representtheexpectednumberofplayersleftatthetablewhenthegameendsinagame
consistingofpplayers(e.g.E(111)=5.2912whenroundedto5significantdigits).
LetS1(N)=
E(p)
LetSk(N)=
Sk1(p)fork>1
FindS20(1014)andwritetheanswerinscientificnotationroundedto10significantdigits.Usealowercasee
toseparatemantissaandexponent(e.g.S3(100)=5.983679014e5).
Problem445:RetractionsA
Foreveryintegern>1,thefamilyoffunctionsfn,a,bisdefinedbyfn,a,b(x)ax+bmodnfora,b,xintegerand
0<a<n,0b<n,0x<n.
Wewillcallfn,a,baretractioniffn,a,b(fn,a,b(x))fn,a,b(x)modnforevery0x<n.
LetR(n)bethenumberofretractionsforn.
Youaregiventhat
R(c)forc=C(100000,k),and1k99999628701600(mod1000000007).
(C(n,k)isthebinomialcoefficient).
FindR(c)forc=C(10000000,k),and1k9999999.
Giveyouranswermodulo1000000007.
Problem446:RetractionsB
Foreveryintegern>1,thefamilyoffunctionsfn,a,bisdefinedbyfn,a,b(x)ax+bmodnfora,b,xintegerand
0<a<n,0b<n,0x<n.
https://projecteuler.net/show=all
140/163
5/2/2015
Wewillcallfn,a,baretractioniffn,a,b(fn,a,b(x))fn,a,b(x)modnforevery0x<n.
LetR(n)bethenumberofretractionsforn.
F(N)=R(n4+4)for1nN.
F(1024)=77532377300600.
FindF(107)(mod1000000007)
Problem447:RetractionsC
Foreveryintegern>1,thefamilyoffunctionsfn,a,bisdefinedbyfn,a,b(x)ax+bmodnfora,b,xintegerand
0<a<n,0b<n,0x<n.
Wewillcallfn,a,baretractioniffn,a,b(fn,a,b(x))fn,a,b(x)modnforevery0x<n.
LetR(n)bethenumberofretractionsforn.
F(N)=R(n)for2nN.
F(107)638042271(mod1000000007).
FindF(1014)(mod1000000007).
Problem448:Averageleastcommonmultiple
Thefunctionlcm(a,b)denotestheleastcommonmultipleofaandb.
LetA(n)betheaverageofthevaluesoflcm(n,i)for1in.
E.g:A(2)=(2+2)/2=2andA(10)=(10+10+30+20+10+30+70+40+90+10)/10=32.
LetS(n)=A(k)for1kn.
S(100)=122726.
FindS(99999999019)mod999999017.
Problem449:Chocolatecoveredcandy
Philtheconfectionerismakinganewbatchofchocolatecoveredcandy.Eachcandycentreisshapedlike
anellipsoidofrevolutiondefinedbytheequation:b2x2+b2y2+a2z2=a2b2.
Philwantstoknowhowmuchchocolateisneededtocoveronecandycentrewithauniformcoatof
chocolateonemillimeterthick.
Ifa=1mmandb=1mm,theamountofchocolaterequiredis
28
mm3
3
Ifa=2mmandb=1mm,theamountofchocolaterequiredisapproximately60.35475635mm3.
Findtheamountofchocolateinmm3requiredifa=3mmandb=1mm.Giveyouranswerasthenumber
roundedto8decimalplacesbehindthedecimalpoint.
Problem450:HypocycloidandLatticepoints
Ahypocycloidisthecurvedrawnbyapointonasmallcirclerollinginsidealargercircle.Theparametric
equationsofahypocycloidcenteredattheorigin,andstartingattherightmostpointisgivenby:
x(t) = (R r) cos(t) + r cos(
y(t) = (R r) sin(t) r sin(
Rr
r
Rr
r
t)
t)
WhereRistheradiusofthelargecircleandrtheradiusofthesmallcircle.
LetC (R, r) bethesetofdistinctpointswithintegercoordinatesonthehypocycloidwithradiusRandrand
forwhichthereisacorrespondingvalueoftsuchthatsin(t)andcos(t) arerationalnumbers.
LetS (R, r)
(x,y)C (R,r)
|x| + |y|
bethesumoftheabsolutevaluesofthexandycoordinatesofthe
pointsinC (R, r) .
LetT (N )
R=3
R1
2
r=1
https://projecteuler.net/show=all
2r < R
S (R, r)
and
141/163
5/2/2015
2r < R
Youaregiven:
C(3,1)={(3,0),(1,2),(1,0),(1,2)}
C(2500,1000)=
{(2500,0),(772,2376),(772,2376),(516,1792),(516,1792),(500,0),(68,504),(68,504),
(1356,1088),(1356,1088),(1500,1000),(1500,1000)}
Note:(625,0)isnotanelementofC(2500,1000)becausesin(t)isnotarationalnumberforthe
correspondingvaluesoft.
S(3,1)=(|3|+|0|)+(|1|+|2|)+(|1|+|0|)+(|1|+|2|)=10
T(3)=10T(10)=524T(100)=580442T(103)=583108600.
FindT(106).
Problem451:Modularinverses
Considerthenumber15.
Thereareeightpositivenumberslessthan15whicharecoprimeto15:1,2,4,7,8,11,13,14.
Themodularinversesofthesenumbersmodulo15are:1,8,4,13,2,11,7,14
because
1*1mod15=1
2*8=16mod15=1
4*4=16mod15=1
7*13=91mod15=1
11*11=121mod15=1
14*14=196mod15=1
LetI(n)bethelargestpositivenumbermsmallerthann1suchthatthemodularinverseofmmodulon
equalsmitself.
SoI(15)=11.
AlsoI(100)=51andI(7)=1.
FindI(n)for3n2107
Problem452:LongProducts
DefineF(m,n)asthenumberofntuplesofpositiveintegersforwhichtheproductoftheelementsdoesn't
exceedm.
F(10,10)=571.
F(106,106)mod1234567891=252903833.
FindF(109,109)mod1234567891.
Problem453:LatticeQuadrilaterals
Asimplequadrilateralisapolygonthathasfourdistinctvertices,hasnostraightanglesanddoesnotself
intersect.
LetQ(m,n)bethenumberofsimplequadrilateralswhoseverticesarelatticepointswithcoordinates(x,y)
satisfying0xmand0yn.
Forexample,Q(2,2)=94ascanbeseenbelow:
https://projecteuler.net/show=all
142/163
5/2/2015
ItcanalsobeverifiedthatQ(3,7)=39590,Q(12,3)=309000andQ(123,45)=70542215894646.
FindQ(12345,6789)mod135707531.
Problem454:DiophantinereciprocalsIII
Inthefollowingequationx,y,andnarepositiveintegers.
1
x y n
ForalimitLwedefineF(L)asthenumberofsolutionswhichsatisfyx<yL.
WecanverifythatF(15)=4andF(1000)=1069.
FindF(1012).
Problem455:PowersWithTrailingDigits
Letf(n)bethelargestpositiveintegerxlessthan109suchthatthelast9digitsofnxformthenumberx
(includingleadingzeros),orzeroifnosuchintegerexists.
Forexample:
f(4)=411728896(4411728896=...490411728896)
f(10)=0
f(157)=743757(157743757=...567000743757)
f(n),2n103=442530011399
Findf(n),2n106.
Problem456:TrianglescontainingtheoriginII
Define:
xn=(1248nmod32323)16161
yn=(8421nmod30103)15051
Pn={(x1,y1),(x2,y2),...,(xn,yn)}
Forexample,P8={(14913,6630),(10161,5625),(5226,11896),(8340,10778),(15852,5203),
(15165,11295),(1427,14495),(12407,1060)}.
LetC(n)bethenumberoftriangleswhoseverticesareinPnwhichcontaintheoriginintheinterior.
Examples:
C(8)=20
C(600)=8950634
C(40000)=2666610948988
https://projecteuler.net/show=all
143/163
5/2/2015
FindC(2000000).
Problem457:Apolynomialmodulothesquareofaprime
Letf(n)=n23n1.
Letpbeaprime.
LetR(p)bethesmallestpositiveintegernsuchthatf(n)modp2=0ifsuchanintegernexists,otherwise
R(p)=0.
LetSR(L)beR(p)forallprimesnotexceedingL.
FindSR(107).
Problem458:PermutationsofProject
ConsiderthealphabetAmadeoutofthelettersoftheword"project":A={c,e,j,o,p,r,t}.
LetT(n)bethenumberofstringsoflengthnconsistingoflettersfromAthatdonothaveasubstringthatis
oneofthe5040permutationsof"project".
T(7)=777!=818503.
FindT(1012).Givethelast9digitsofyouranswer.
Problem459:Flippinggame
TheflippinggameisatwoplayergameplayedonaNbyNsquareboard.
Eachsquarecontainsadiskwithonesidewhiteandonesideblack.
Thegamestartswithalldisksshowingtheirwhiteside.
Aturnconsistsofflippingalldisksinarectanglewiththefollowingproperties:
theupperrightcorneroftherectanglecontainsawhitedisk
therectanglewidthisaperfectsquare(1,4,9,16,...)
therectangleheightisatriangularnumber(1,3,6,10,...)
Playersalternateturns.Aplayerwinsbyturningthegridallblack.
LetW(N)bethenumberofwinningmovesforthefirstplayeronaNbyNboardwithalldiskswhite,
assumingperfectplay.
W(1)=1,W(2)=0,W(5)=8andW(102)=31395.
ForN=5,thefirstplayer'seightwinningfirstmovesare:
https://projecteuler.net/show=all
144/163
5/2/2015
FindW(106).
Problem460:Anantonthemove
OntheEuclideanplane,ananttravelsfrompointA(0,1)topointB(d,1)foranintegerd.
Ineachstep,theantatpoint(x0,y0)choosesoneofthelatticepoints(x1,y1)whichsatisfyx10andy1
1andgoesstraightto(x1,y1)ataconstantvelocityv.Thevalueofvdependsony0andy1asfollows:
Ify0=y1,thevalueofvequalsy0.
Ify0y1,thevalueofvequals(y1y0)/(ln(y1)ln(y0)).
Theleftimageisoneofthepossiblepathsford=4.FirsttheantgoesfromA(0,1)toP1(1,3)atvelocity(3
1)/(ln(3)ln(1))1.8205.Thentherequiredtimeissqrt(5)/1.82051.2283.
FromP1(1,3)toP2(3,3)theanttravelsatvelocity3sotherequiredtimeis2/30.6667.FromP2(3,3)to
B(4,1)theanttravelsatvelocity(13)/(ln(1)ln(3))1.8205sotherequiredtimeissqrt(5)/1.8205
1.2283.
Thusthetotalrequiredtimeis1.2283+0.6667+1.2283=3.1233.
Therightimageisanotherpath.Thetotalrequiredtimeiscalculatedas0.98026+1+0.98026=2.96052.It
canbeshownthatthisisthequickestpathford=4.
LetF(d)bethetotalrequiredtimeiftheantchoosesthequickestpath.Forexample,F(4)2.960516287.
WecanverifythatF(10)4.668187834andF(100)9.217221972.
FindF(10000).Giveyouranswerroundedtoninedecimalplaces.
Problem461:AlmostPi
Letfn(k)=ek/n1,forallnonnegativeintegersk.
Remarkably,f200(6)+f200(75)+f200(89)+f200(226)=3.141592644529.
Infact,itisthebestapproximationofoftheformfn(a)+fn(b)+fn(c)+fn(d)forn=200.
Letg(n)=a2+b2+c2+d2fora,b,c,dthatminimizetheerror:|fn(a)+fn(b)+fn(c)+fn(d)|
(where|x|denotestheabsolutevalueofx).
Youaregiveng(200)=62+752+892+2262=64658.
Findg(10000).
Problem462:Permutationof3smoothnumbers
A3smoothnumberisanintegerwhichhasnoprimefactorlargerthan3.ForanintegerN,wedefineS(N)
https://projecteuler.net/show=all
145/163
5/2/2015
asthesetof3smoothnumberslessthanorequaltoN.Forexample,S(20)={1,2,3,4,6,8,9,12,16,18
}.
WedefineF(N)asthenumberofpermutationsofS(N)inwhicheachelementcomesafterallofitsproper
divisors.
ThisisoneofthepossiblepermutationsforN=20.
1,2,4,3,9,8,16,6,18,12.
Thisisnotavalidpermutationbecause12comesbeforeitsdivisor6.
1,2,4,3,9,8,12,16,6,18.
WecanverifythatF(6)=5,F(8)=9,F(20)=450andF(1000)8.8521816557e21.
FindF(1018).Giveasyouransweritsscientificnotationroundedtotendigitsafterthedecimalpoint.
Whengivingyouranswer,usealowercaseetoseparatemantissaandexponent.E.g.iftheansweris
112,233,445,566,778,899thentheanswerformatwouldbe1.1223344557e17.
Problem463:Aweirdrecurrencerelation
Thefunctionf isdefinedforallpositiveintegersasfollows:
f (1) = 1
f (3) = 3
f (2n) = f (n)
f (4n + 1) = 2f (2n + 1) f (n)
f (4n + 3) = 3f (2n + 1) 2f (n)
n
andS (100)
= 3604
f (i)
Problem464:Mbiusfunctionandintervals
TheMbiusfunction,denoted(n),isdefinedas:
(n)=(1)(n)ifnissquarefree(where(n)isthenumberofdistinctprimefactorsofn)
(n)=0ifnisnotsquarefree.
LetP(a,b)bethenumberofintegersnintheinterval[a,b]suchthat(n)=1.
LetN(a,b)bethenumberofintegersnintheinterval[a,b]suchthat(n)=1.
Forexample,P(2,10)=2andN(2,10)=4.
LetC(n)bethenumberofintegerpairs(a,b)suchthat:
1abn,
99N(a,b)100P(a,b),and
99P(a,b)100N(a,b).
Forexample,C(10)=13,C(500)=16676andC(10000)=20155319.
FindC(20000000).
Problem465:Polarpolygons
Thekernelofapolygonisdefinedbythesetofpointsfromwhichtheentirepolygon'sboundaryisvisible.
Wedefineapolarpolygonasapolygonforwhichtheoriginisstrictlycontainedinsideitskernel.
Forthisproblem,apolygoncanhavecollinearconsecutivevertices.However,apolygonstillcannothave
selfintersectionandcannothavezeroarea.
Forexample,onlythefirstofthefollowingisapolarpolygon(thekernelsofthesecond,third,andfourthdo
notstrictlycontaintheorigin,andthefifthdoesnothaveakernelatall):
https://projecteuler.net/show=all
146/163
5/2/2015
Noticethatthefirstpolygonhasthreeconsecutivecollinearvertices.
LetP(n)bethenumberofpolarpolygonssuchthatthevertices(x,y)haveintegercoordinateswhose
absolutevaluesarenotgreaterthann.
Notethatpolygonsshouldbecountedasdifferentiftheyhavedifferentsetofedges,eveniftheyenclose
thesamearea.Forexample,thepolygonwithvertices[(0,0),(0,3),(1,1),(3,0)]isdistinctfromthepolygon
withvertices[(0,0),(0,3),(1,1),(3,0),(1,0)].
Forexample,P(1)=131,P(2)=1648531,P(3)=1099461296175andP(343)mod1000000007=
937293740.
FindP(713)mod1000000007.
Problem466:Distincttermsinamultiplicationtable
LetP(m,n)bethenumberofdistincttermsinanmnmultiplicationtable.
Forexample,a34multiplicationtablelookslikethis:
1
2
3
1
1
2
3
2
2
4
6
3
4
3
4
6
8
9 12
Thereare8distinctterms{1,2,3,4,6,8,9,12},thereforeP(3,4)=8.
Youaregiventhat:
P(64,64)=1263,
P(12,345)=1998,and
P(32,1015)=13826382602124302.
FindP(64,1016).
Problem467:Superinteger
Anintegersiscalledasuperintegerofanotherintegernifthedigitsofnformasubsequenceofthedigitsof
s.
Forexample,2718281828isasuperintegerof18828,while314159isnotasuperintegerof151.
Letp(n)bethenthprimenumber,andletc(n)bethenthcompositenumber.Forexample,p(1)=2,p(10)=
29,c(1)=4andc(10)=18.
{p(i):i1}={2,3,5,7,11,13,17,19,23,29,...}
{c(i):i1}={4,6,8,9,10,12,14,15,16,18,...}
LetPDthesequenceofthedigitalrootsof{p(i)}(CDisdefinedsimilarlyfor{c(i)}):
PD={2,3,5,7,2,4,8,1,5,2,...}
CD={4,6,8,9,1,3,5,6,7,9,...}
LetPnbetheintegerformedbyconcatenatingthefirstnelementsofPD(CnisdefinedsimilarlyforCD).
P10=2357248152
C10=4689135679
Letf(n)bethesmallestpositiveintegerthatisacommonsuperintegerofPnandCn.
Forexample,f(10)=2357246891352679,andf(100)mod1000000007=771661825.
https://projecteuler.net/show=all
147/163
5/2/2015
Findf(10000)mod1000000007.
Problem468:Smoothdivisorsofbinomialcoefficients
AnintegeriscalledBsmoothifnoneofitsprimefactorsisgreaterthanB.
LetSB(n)bethelargestBsmoothdivisorofn.
Examples:
S1(10)=1
S4(2100)=12
S17(2496144)=5712
DefineF(n)=1Bn0rnSB(C(n,r)).Here,C(n,r)denotesthebinomialcoefficient.
Examples:
F(11)=3132
F(1111)mod1000000993=706036312
F(111111)mod1000000993=22156169
FindF(11111111)mod1000000993.
Problem469:Emptychairs
InaroomNchairsareplacedaroundaroundtable.
Knightsentertheroomonebyoneandchooseatrandomanavailableemptychair.
Tohaveenoughelbowroomtheknightsalwaysleaveatleastoneemptychairbetweeneachother.
Whentherearen'tanysuitablechairsleft,thefractionCofemptychairsisdetermined.
WealsodefineE(N)astheexpectedvalueofC.
WecanverifythatE(4)=1/2andE(6)=5/9.
FindE(1018).Giveyouranswerroundedtofourteendecimalplacesintheform0.abcdefghijklmn.
Problem470:SuperRamvok
ConsiderasinglegameofRamvok:
Lettrepresentthemaximumnumberofturnsthegamelasts.Ift=0,thenthegameendsimmediately.
Otherwise,oneachturni,theplayerrollsadie.Afterrolling,ifi<ttheplayercaneitherstopthegameand
receiveaprizeequaltothevalueofthecurrentroll,ordiscardtherollandtryagainnextturn.Ifi=t,then
therollcannotbediscardedandtheprizemustbeaccepted.Beforethegamebegins,tischosenbythe
player,whomustthenpayanupfrontcostctforsomeconstantc.Forc=0,tcanbechosentobeinfinite
(withanupfrontcostof0).LetR(d,c)betheexpectedprofit(i.e.netgain)thattheplayerreceivesfroma
singlegameofoptimallyplayedRamvok,givenafairdsideddieandcostconstantc.Forexample,R(4,
0.2)=2.65.Assumethattheplayerhassufficientfundsforpayingany/allupfrontcosts.
NowconsideragameofSuperRamvok:
InSuperRamvok,thegameofRamvokisplayedrepeatedly,butwithaslightmodification.Aftereach
game,thedieisaltered.Thealterationprocessisasfollows:Thedieisrolledonce,andiftheresultingface
hasitspipsvisible,thenthatfaceisalteredtobeblankinstead.Ifthefaceisalreadyblank,thenitis
changedbacktoitsoriginalvalue.Afterthealterationismade,anothergameofRamvokcanbegin(and
duringsuchagame,ateachturn,thedieisrolleduntilafacewithavalueonitappears).Theplayerknows
whichfacesareblankandwhicharenotatalltimes.ThegameofSuperRamvokendsonceallfacesofthe
dieareblank.
LetS(d,c)betheexpectedprofitthattheplayerreceivesfromanoptimallyplayedgameofSuperRamvok,
givenafairdsideddietostart(withallsidesvisible),andcostconstantc.Forexample,S(6,1)=208.3.
LetF(n)=4dn0cnS(d,c).
CalculateF(20),roundedtothenearestinteger.
Problem471:Triangleinscribedinellipse
https://projecteuler.net/show=all
148/163
5/2/2015
ThetriangleABCisinscribedinanellipsewithequation
y
b
= 1
,0<2b<a,aandbintegers.
Letr(a,b)betheradiusoftheincircleofABCwhentheincirclehascenter(2b,0)andAhascoordinates
(
a
2
3
2
b)
Forexample,r(3,1)=,r(6,2)=1,r(12,3)=2.
LetG(n)
a=3
a1
2
b=1
r(a, b)
YouaregivenG(10)=20.59722222,G(100)=19223.60980(roundedto10significantdigits).
FindG(1011).
Giveyouranswerinscientificnotationroundedto10significantdigits.Usealowercaseetoseparate
mantissaandexponent.
ForG(10)theanswerwouldhavebeen2.059722222e1.
Problem472:ComfortableDistanceII
ThereareNseatsinarow.Npeoplecomeoneafteranothertofilltheseatsaccordingtothefollowing
rules:
1. Nopersonsitsbesideanother.
2. Thefirstpersonchoosesanyseat.
3. Eachsubsequentpersonchoosestheseatfurthestfromanyoneelsealreadyseated,aslongasit
doesnotviolaterule1.Ifthereismorethanonechoicesatisfyingthiscondition,thentheperson
choosestheleftmostchoice.
Notethatduetorule1,someseatswillsurelybeleftunoccupied,andthemaximumnumberofpeoplethat
canbeseatedislessthanN(forN>1).
HerearethepossibleseatingarrangementsforN=15:
https://projecteuler.net/show=all
149/163
5/2/2015
Weseethatifthefirstpersonchoosescorrectly,the15seatscanseatupto7people.
Wecanalsoseethatthefirstpersonhas9choicestomaximizethenumberofpeoplethatmaybeseated.
Letf(N)bethenumberofchoicesthefirstpersonhastomaximizethenumberofoccupantsforNseatsina
row.Thus,f(1)=1,f(15)=9,f(20)=6,andf(500)=16.
Also,f(N)=83for1N20andf(N)=13343for1N500.
Findf(N)for1N1012.Givethelast8digitsofyouranswer.
Problem473:Phigitalnumberbase
1+5
Let bethegoldenratio: = 2 .
Remarkablyitispossibletowriteeverypositiveintegerasasumofpowersof evenifwerequirethat
everypowerof isusedatmostonceinthissum.
Eventhenthisrepresentationisnotunique.
Wecanmakeituniquebyrequiringthatnopowerswithconsecutiveexponentsareusedandthatthe
representationisfinite.
E.g:2 = + 2 and3 = 2 + 2
Torepresentthissumofpowersof weuseastringof0'sand1'swithapointtoindicatewherethe
negativeexponentsstart.
Wecallthistherepresentationinthephigitalnumberbase.
So1 = 1 ,2 = 10.01 ,3 = 100.01 and14 = 100100.001001 .
Thestringsrepresenting1,2and14inthephigitalnumberbasearepalindromic,whilethestring
representating3isnot.
(thephigitalpointisnotthemiddlecharacter).
Thesumofthepositiveintegersnotexceeding1000whosephigitalrepresentationispalindromicis4345.
Findthesumofthepositiveintegersnotexceeding1010 whosephigitalrepresentationispalindromic.
Problem474:Lastdigitsofdivisors
Forapositiveintegernanddigitsd,wedefineF(n,d)asthenumberofthedivisorsofnwhoselastdigits
equald.
Forexample,F(84,4)=3.Amongthedivisorsof84(1,2,3,4,6,7,12,14,21,28,42,84),threeofthem(4,
14,84)havethelastdigit4.
WecanalsoverifythatF(12!,12)=11andF(50!,123)=17888.
FindF(106!,65432)modulo(1016+61).
Problem475:Musicfestival
https://projecteuler.net/show=all
150/163
5/2/2015
12nmusiciansparticipateatamusicfestival.Onthefirstday,theyform3nquartetsandpracticeallday.
Itisadisaster.Attheendoftheday,allmusiciansdecidetheywillneveragainagreetoplaywithany
memberoftheirquartet.
Onthesecondday,theyform4ntrios,eachmusicianavoidinghispreviousquartetpartners.
Letf(12n)bethenumberofwaystoorganizethetriosamongstthe12nmusicians.
Youaregivenf(12)=576andf(24)mod1000000007=509089824.
Findf(600)mod1000000007.
Problem476:CirclePackingII
LetR(a,b,c)bethemaximumareacoveredbythreenonoverlappingcirclesinsideatrianglewithedge
lengthsa,bandc.
LetS(n)betheaveragevalueofR(a,b,c)overallintegertriplets(a,b,c)suchthat
1abc<a+bn
YouaregivenS(2)=R(1,1,1)0.31998,S(5)1.25899.
FindS(1803)roundedto5decimalplacesbehindthedecimalpoint.
Problem477:NumberSequenceGame
ThenumbersequencegamestartswithasequenceSofNnumberswrittenonaline.
Twoplayersalternateturns.Athisturn,aplayermustselectandremoveeitherthefirstorthelastnumber
remaininginthesequence.
Theplayerscoreisthesumofallthenumbershehastaken.Eachplayerattemptstomaximizehisown
sum.
IfN=4andS={1,2,10,3},theneachplayermaximizeshisscoreasfollows:
Player1:removesthefirstnumber(1)
Player2:removesthelastnumberfromtheremainingsequence(3)
Player1:removesthelastnumberfromtheremainingsequence(10)
Player2:removestheremainingnumber(2)
Player1scoreis1+10=11.
LetF(N)bethescoreofplayer1ifbothplayersfollowtheoptimalstrategyforthesequenceS={s1,
s2,...,sN}definedas:
s1=0
si+1=(si2+45)modulo1000000007
ThesequencebeginswithS={0,45,2070,4284945,753524550,478107844,894218625,...}.
YouaregivenF(2)=45,F(4)=4284990,F(100)=26365463243,F(104)=2495838522951.
FindF(108).
Problem478:Mixtures
Letusconsidermixturesofthreesubstances:A,BandC.Amixturecanbedescribedbyaratioofthe
amountsofA,B,andCinit,i.e.,(a:b:c).Forexample,amixturedescribedbytheratio(2:3:5)contains
20%A,30%Band50%C.
Forthepurposesofthisproblem,wecannotseparatetheindividualcomponentsfromamixture.However,
wecancombinedifferentamountsofdifferentmixturestoformmixtureswithnewratios.
Forexample,saywehavethreemixtureswithratios(3:0:2),(3:6:11)and(3:3:4).Bymixing10units
ofthefirst,20unitsofthesecondand30unitsofthethird,wegetanewmixturewithratio(6:5:9),since:
https://projecteuler.net/show=all
151/163
5/2/2015
(103/5+203/20+303/10:100/5+206/20+303/10:102/5+2011/20+304/10)=(18:15:27)=(6:5:9)
However,withthesamethreemixtures,itisimpossibletoformtheratio(3:2:1),sincetheamountofBis
alwayslessthantheamountofC.
Letnbeapositiveinteger.Supposethatforeverytripleofintegers(a,b,c)with0a,b,cnandgcd(a,
b,c)=1,wehaveamixturewithratio(a:b:c).LetM(n)bethesetofallsuchmixtures.
Forexample,M(2)containsthe19mixtureswiththefollowingratios:
{(0:0:1),(0:1:0),(0:1:1),(0:1:2),(0:2:1),
(1:0:0),(1:0:1),(1:0:2),(1:1:0),(1:1:1),
(1:1:2),(1:2:0),(1:2:1),(1:2:2),(2:0:1),
(2:1:0),(2:1:1),(2:1:2),(2:2:1)}.
LetE(n)bethenumberofsubsetsofM(n)whichcanproducethemixturewithratio(1:1:1),i.e.,the
mixturewithequalpartsA,BandC.
WecanverifythatE(1)=103,E(2)=520447,E(10)mod118=82608406andE(500)mod118=13801403.
FindE(10000000)mod118.
Problem479:RootsontheRise
Letak,bk,andckrepresentthethreesolutions(realorcomplexnumbers)totheexpression1/x=
(k/x)2(k+x2)kx.
Forinstance,fork=5,weseethat{a5,b5,c5}isapproximately{5.727244,0.363622+2.057397i,
0.3636222.057397i}.
LetS(n)=(ak+bk)p(bk+ck)p(ck+ak)pforallintegersp,ksuchthat1p,kn.
Interestingly,S(n)isalwaysaninteger.Forexample,S(4)=51160.
FindS(106)modulo1000000007.
Problem480:TheLastQuestion
Considerallthewordswhichcanbeformedbyselectingletters,inanyorder,fromthephrase:
thereisasyetinsufficientdataforameaningfulanswer
Supposethosewith15lettersorlessarelistedinalphabeticalorderandnumberedsequentiallystartingat
1.
Thelistwouldinclude:
1:a
2:aa
3:aaa
4:aaaa
5:aaaaa
6:aaaaaa
7:aaaaaac
8:aaaaaacd
9:aaaaaacde
10:aaaaaacdee
11:aaaaaacdeee
12:aaaaaacdeeee
13:aaaaaacdeeeee
14:aaaaaacdeeeeee
15:aaaaaacdeeeeeef
16:aaaaaacdeeeeeeg
17:aaaaaacdeeeeeeh
...
28:aaaaaacdeeeeeey
29:aaaaaacdeeeeef
30:aaaaaacdeeeeefe
...
115246685191495242:euleoywuttttsss
115246685191495243:euler
115246685191495244:eulera
...
525069350231428029:ywuuttttssssrrr
https://projecteuler.net/show=all
152/163
5/2/2015
DefineP(w)asthepositionofthewordw.
DefineW(p)asthewordinpositionp.
WecanseethatP(w)andW(p)areinverses:P(W(p))=pandW(P(w))=w.
Examples:
W(10)=aaaaaacdee
P(aaaaaacdee)=10
W(115246685191495243)=euler
P(euler)=115246685191495243
FindW(P(legionary)+P(calorimeters)P(annihilate)+P(orchestrated)P(fluttering)).
Giveyouranswerusinglowercasecharacters(nopunctuationorspace).
Problem481:ChefShowdown
Agroupofchefs(numbered#1,#2,etc)participateinaturnbasedstrategiccookingcompetition.Oneach
chef'sturn,he/shecooksupadishtothebestofhis/herabilityandgivesittoaseparatepanelofjudgesfor
tastetesting.LetS(k)representchef#k'sskilllevel(whichispubliclyknown).Morespecifically,S(k)isthe
probabilitythatchef#k'sdishwillbeassessedfavorablybythejudges(onany/allturns).Ifthedishreceives
afavorablerating,thenthechefmustchooseoneothercheftobeeliminatedfromthecompetition.Thelast
chefremaininginthecompetitionisthewinner.
Thegamealwaysbeginswithchef#1,withtheturnorderiteratingsequentiallyovertherestofthechefsstill
inplay.Thenthecyclerepeatsfromthelowestnumberedchef.Allchefsaimtooptimizetheirchancesof
winningwithintherulesasstated,assumingthattheotherchefsbehaveinthesamemanner.Intheevent
thatachefhasmorethanoneequallyoptimaleliminationchoice,assumethatthechosenchefisalwaysthe
onewiththenextclosestturn.
DefineWn(k)astheprobabilitythatchef#kwinsinacompetitionwithnchefs.IfwehaveS(1)=0.25,S(2)
=0.5,andS(3)=1,thenW3(1)=0.29375.
Goingforward,weassignS(k)=Fk/Fn+1overall1kn,whereFkisaFibonaccinumber:Fk=Fk1+Fk2
withbasecasesF1=F2=1.Then,forexample,whenconsideringacompetitionwithn=7chefs,wehave
W7(1)=0.08965042,W7(2)=0.20775702,W7(3)=0.15291406,W7(4)=0.14554098,W7(5)=0.15905291,
W7(6)=0.10261412,andW7(7)=0.14247050,roundedto8decimalplaceseach.
LetE(n)representtheexpectednumberofdishescookedinacompetitionwithnchefs.Forinstance,E(7)=
42.28176050.
FindE(14)roundedto8decimalplaces.
Problem482:Theincenterofatriangle
ABCisanintegersidedtrianglewithincenterIandperimeterp.
ThesegmentsIA,IBandIChaveintegrallengthaswell.
LetL=p+|IA|+|IB|+|IC|.
LetS(P)=LforallsuchtriangleswherepP.Forexample,S(103)=3619.
FindS(107).
Problem483:Repeatedpermutation
Wedefineapermutationasanoperationthatrearrangestheorderoftheelements{1,2,3,...,n}.Thereare
n!suchpermutations,oneofwhichleavestheelementsintheirinitialorder.Forn=3wehave3!=6
permutations:
P1=keeptheinitialorder
P2=exchangethe1stand2ndelements
P3=exchangethe1stand3rdelements
P4=exchangethe2ndand3rdelements
P5=rotatetheelementstotheright
P6=rotatetheelementstotheleft
Ifweselectoneofthesepermutations,andwereapplythesamepermutationrepeatedly,weeventually
https://projecteuler.net/show=all
153/163
5/2/2015
restoretheinitialorder.
ForapermutationPi,letf(Pi)bethenumberofstepsrequiredtorestoretheinitialorderbyapplyingthe
permutationPirepeatedly.
Forn=3,weobtain:
f(P1)=1:(1,2,3)(1,2,3)
f(P2)=2:(1,2,3)(2,1,3)(1,2,3)
f(P3)=2:(1,2,3)(3,2,1)(1,2,3)
f(P4)=2:(1,2,3)(1,3,2)(1,2,3)
f(P5)=3:(1,2,3)(3,1,2)(2,3,1)(1,2,3)
f(P6)=3:(1,2,3)(2,3,1)(3,1,2)(1,2,3)
Letg(n)betheaveragevalueoff2(Pi)overallpermutationsPioflengthn.
g(3)=(12+22+22+22+32+32)/3!=31/65.166666667e0
g(5)=2081/1201.734166667e1
g(20)=12422728886023769167301/24329020081766400005.106136147e3
Findg(350)andwritetheanswerinscientificnotationroundedto10significantdigits,usingalowercasee
toseparatemantissaandexponent,asintheexamplesabove.
Problem484:ArithmeticDerivative
Thearithmeticderivativeisdefinedby
p'=1foranyprimep
(ab)'=a'b+ab'forallintegersa,b(Leibnizrule)
Forexample,20'=24
Findgcd(k,k')for1<k51015
Note:gcd(x,y)denotesthegreatestcommondivisorofxandy.
Problem485:Maximumnumberofdivisors
Letd(n)bethenumberofdivisorsofn.
LetM(n,k)bethemaximumvalueofd(j)fornjn+k1.
LetS(u,k)bethesumofM(n,k)for1nuk+1.
YouaregiventhatS(1000,10)=17176.
FindS(100000000,100000).
Problem486:Palindromecontainingstrings
LetF5(n)bethenumberofstringsssuchthat:
sconsistsonlyof'0'sand'1's,
shaslengthatmostn,and
scontainsapalindromicsubstringoflengthatleast5.
Forexample,F5(4)=0,F5(5)=8,F5(6)=42andF5(11)=3844.
LetD(L)bethenumberofintegersnsuchthat5nLandF5(n)isdivisibleby87654321.
Forexample,D(107)=0andD(5109)=51.
FindD(1018).
Problem487:Sumsofpowersums
Letfk(n)bethesumofthekthpowersofthefirstnpositiveintegers.
Forexample,f2(10)=12+22+32+42+52+62+72+82+92+102=385.
https://projecteuler.net/show=all
154/163
5/2/2015
LetSk(n)bethesumoffk(i)for1in.Forexample,S4(100)=35375333830.
Whatis(S10000(1012)modp)overallprimespbetween2109and2109+2000?
Problem488:UnbalancedNim
AliceandBobhaveenjoyedplayingNimeveryday.However,theyfinallygotboredofplayingordinary
threeheapNim.
So,theyaddedanextrarule:
Mustnotmaketwoheapsofthesamesize.
Thetriple(a,b,c)indicatesthesizeofthreeheaps.
Underthisextrarule,(2,4,5)isoneofthelosingpositionsforthenextplayer.
Toillustrate:
Alicemovesto(2,4,3)
Bobmovesto(0,4,3)
Alicemovesto(0,2,3)
Bobmovesto(0,2,1)
UnlikeordinarythreeheapNim,(0,1,2)anditspermutationsaretheendstatesofthisgame.
ForanintegerN,wedefineF(N)asthesumofa+b+cforallthelosingpositionsforthenextplayer,with0<
a<b<c<N.
Forexample,F(8)=42,becausethereare4losingpositionsforthenextplayer,(1,3,5),(1,4,6),(2,3,6)and
(2,4,5).
WecanalsoverifythatF(128)=496062.
Findthelast9digitsofF(1018).
Problem489:Commonfactorsbetweentwosequences
LetG(a,b)bethesmallestnonnegativeintegernforwhichgcd(n3+b,(n+a)3+b)ismaximized.
Forexample,G(1,1)=5becausegcd(n3+1,(n+1)3+1)reachesitsmaximumvalueof7forn=5,andis
smallerfor0n<5.
LetH(m,n)=G(a,b)for1am,1bn.
YouaregivenH(5,5)=128878andH(10,10)=32936544.
FindH(18,1900).
Problem490:Jumpingfrog
Therearenstonesinapond,numbered1ton.Consecutivestonesarespacedoneunitapart.
Afrogsitsonstone1.Hewishestovisiteachstoneexactlyonce,stoppingonstonen.However,hecan
onlyjumpfromonestonetoanotheriftheyareatmost3unitsapart.Inotherwords,fromstonei,hecan
reachastonejif1jnandjisintheset{i3,i2,i1,i+1,i+2,i+3}.
Letf(n)bethenumberofwayshecandothis.Forexample,f(6)=14,asshownbelow:
123456
123546
124356
124536
125346
125436
132456
132546
134256
135246
142356
142536
143256
145236
Otherexamplesaref(10)=254andf(40)=1439682432976.
https://projecteuler.net/show=all
155/163
5/2/2015
LetS(L)=f(n)3for1nL.
Examples:
S(10)=18230635
S(20)=104207881192114219
S(1000)mod109=225031475
S(1000000)mod109=363486179
FindS(1014)mod109.
Problem491:Doublepandigitalnumberdivisibleby11
Wecallapositiveintegerdoublepandigitalifitusesallthedigits0to9exactlytwice(withnoleadingzero).
Forexample,40561817703823564929isonesuchnumber.
Howmanydoublepandigitalnumbersaredivisibleby11?
Problem492:Explodingsequence
Definethesequencea1,a2,a3,...as:
a1=1
an+1=6an2+10an+3forn1.
Examples:
a3=2359
a6=269221280981320216750489044576319
a6mod1000000007=203064689
a100mod1000000007=456482974
DefineB(x,y,n)as(anmodp)foreveryprimepsuchthatxpx+y.
Examples:
B(109,103,103)=23674718882
B(109,103,1015)=20731563854
FindB(109,107,1015).
Problem493:UnderTheRainbow
70coloredballsareplacedinanurn,10foreachofthesevenrainbowcolors.
Whatistheexpectednumberofdistinctcolorsin20randomlypickedballs?
Giveyouranswerwithninedigitsafterthedecimalpoint(a.bcdefghij).
Problem494:Collatzprefixfamilies
a
i
TheCollatzsequenceisdefinedas:ai+1
= {
ifa i is even
3a i +1
ifa i is odd
TheCollatzconjecturestatesthatstartingfromanypositiveinteger,thesequenceeventuallyreachesthe
cycle1,4,2,1....
Weshalldefinethesequenceprefixp(n)fortheCollatzsequencestartingwitha1=nasthesubsequence
ofallnumbersnotapowerof2(20=1isconsideredapowerof2forthisproblem).Forexample:
p(13)={13,40,20,10,5}
p(8)={}
Anynumberinvalidatingtheconjecturewouldhaveaninfinitelengthsequenceprefix.
LetSmbethesetofallsequenceprefixesoflengthm.Twosequences{a1,a2,...,am}and{b1,b2,...,bm}in
Smaresaidtobelongtothesameprefixfamilyifai<ajifandonlyifbi<bjforall1i,jm.
Forexample,inS4,{6,3,10,5}isinthesamefamilyas{454,227,682,341},butnot{113,340,170,85}.
Letf(m)bethenumberofdistinctprefixfamiliesinSm.
https://projecteuler.net/show=all
156/163
5/2/2015
Youaregivenf(5)=5,f(10)=55,f(20)=6771.
Findf(90).
Problem495:Writingnastheproductofkdistinctpositiveintegers
LetW(n,k)bethenumberofwaysinwhichncanbewrittenastheproductofkdistinctpositiveintegers.
Forexample,W(144,4)=7.Thereare7waysinwhich144canbewrittenasaproductof4distinctpositive
integers:
144=12418
144=1289
144=12324
144=12612
144=13412
144=1368
144=2346
Notethatpermutationsoftheintegersthemselvesarenotconsidereddistinct.
Furthermore,W(100!,10)modulo1000000007=287549200.
FindW(10000!,30)modulo1000000007.
Problem496:Incenterandcircumcenteroftriangle
GivenanintegersidedtriangleABC:
LetIbetheincenterofABC.
LetDbetheintersectionbetweenthelineAIandthecircumcircleofABC(AD).
WedefineF(L)asthesumofBCforthetrianglesABCthatsatisfyAC=DIandBCL.
Forexample,F(15)=45becausethetrianglesABCwith(BC,AC,AB)=(6,4,5),(12,8,10),(12,9,7),(15,9,16)
satisfytheconditions.
FindF(109).
Problem497:DrunkenTowerofHanoi
Bobisveryfamiliarwiththefamousmathematicalpuzzle/game,"TowerofHanoi,"whichconsistsofthree
uprightrodsanddisksofdifferentsizesthatcanslideontoanyoftherods.Thegamebeginswithastackof
ndisksplacedontheleftmostrodindescendingorderbysize.Theobjectiveofthegameistomoveallof
thedisksfromtheleftmostrodtotherightmostrod,giventhefollowingrestrictions:
1. Onlyonediskcanbemovedatatime.
2. Avalidmoveconsistsoftakingthetopdiskfromonestackandplacingitontoanotherstack(oran
emptyrod).
3. Nodiskcanbeplacedontopofasmallerdisk.
Movingontoavariantofthisgame,consideralongroomkunits(squaretiles)wide,labeledfrom1tokin
ascendingorder.Threerodsareplacedatsquaresa,b,andc,andastackofndisksisplacedontherodat
squarea.
Bobbeginsthegamestandingatsquareb.HisobjectiveistoplaytheTowerofHanoigamebymovingall
ofthediskstotherodatsquarec.However,Bobcanonlypickuporsetdownadiskifheisonthesame
squareastherod/stackinquestion.
Unfortunately,Bobisalsodrunk.Onagivenmove,Bobwilleitherstumbleonesquaretotheleftorone
squaretotherightwithequalprobability,unlessBobisateitherendoftheroom,inwhichcasehecanonly
moveinonedirection.DespiteBob'sinebriatedstate,heisstillcapableoffollowingtherulesofthegame
itself,aswellaschoosingwhentopickuporputdownadisk.
Thefollowinganimationdepictsasideviewofasamplegameforn=3,k=7,a=2,b=4,andc=6:
https://projecteuler.net/show=all
157/163
5/2/2015
LetE(n,k,a,b,c)betheexpectednumberofsquaresthatBobtravelsduringasingleoptimallyplayedgame.
Agameisplayedoptimallyifthenumberofdiskpickupsisminimized.
Interestinglyenough,theresultisalwaysaninteger.Forexample,E(2,5,1,3,5)=60andE(3,20,4,9,17)=
2358.
Findthelastninedigitsof1n10000E(n,10n,3n,6n,9n).
Problem498:Remainderofpolynomialdivision
Forpositiveintegersnandm,wedefinetwopolynomialsFn(x)=xnandGm(x)=(x1)m.
WealsodefineapolynomialRn,m(x)astheremainderofthedivisionofFn(x)byGm(x).
Forexample,R6,3(x)=15x224x+10.
LetC(n,m,d)betheabsolutevalueofthecoefficientofthedthdegreetermofRn,m(x).
WecanverifythatC(6,3,1)=24andC(100,10,4)=227197811615775.
FindC(1013,1012,104)mod999999937.
Problem499:St.PetersburgLottery
Agamblerdecidestoparticipateinaspeciallottery.Inthislotterythegamblerplaysaseriesofoneormore
games.
Eachgamecostsmpoundstoplayandstartswithaninitialpotof1pound.Thegamblerflipsanunbiased
coin.Everytimeaheadappears,thepotisdoubledandthegamblercontinues.Whenatailappears,the
gameendsandthegamblercollectsthecurrentvalueofthepot.Thegambleriscertaintowinatleast1
pound,thestartingvalueofthepot,atthecostofmpounds,theinitialfee.
Thegamblercannotcontinuetoplayifhisfortunefallsbelowmpounds.
Letpm(s)denotetheprobabilitythatthegamblerwillneverrunoutofmoneyinthislotterygivenhisinitial
fortunesandthecostpergamem.
Forexamplep2(2)0.2522,p2(5)0.6873andp6(10000)0.9952(note:pm(s)=0fors<m).
Findp15(109)andgiveyouranswerroundedto7decimalplacesbehindthedecimalpointintheform
0.abcdefg.
Problem500:Problem500!!!
Thenumberofdivisorsof120is16.
Infact120isthesmallestnumberhaving16divisors.
Findthesmallestnumberwith2500500divisors.
Giveyouranswermodulo500500507.
Problem501:EightDivisors
Theeightdivisorsof24are1,2,3,4,6,8,12and24.
Thetennumbersnotexceeding100havingexactlyeightdivisorsare24,30,40,42,54,56,66,70,78and
88.
Letf(n)bethecountofnumbersnotexceedingnwithexactlyeightdivisors.
Youaregivenf(100)=10,f(1000)=180andf(106)=224427.
Findf(1012).
https://projecteuler.net/show=all
158/163
5/2/2015
Problem502:CountingCastles
Wedefineablocktobearectanglewithaheightof1andanintegervaluedlength.Letacastlebea
configurationofstackedblocks.
Givenagamegridthatiswunitswideandhunitstall,acastleisgeneratedaccordingtothefollowingrules:
1. Blockscanbeplacedontopofotherblocksaslongasnothingsticksoutpasttheedgesorhangsout
overopenspace.
2. Allblocksarealigned/snappedtothegrid.
3. Anytwoneighboringblocksonthesamerowhaveatleastoneunitofspacebetweenthem.
4. Thebottomrowisoccupiedbyablockoflengthw.
5. Themaximumachievedheightoftheentirecastleisexactlyh.
6. Thecastleismadefromanevennumberofblocks.
Thefollowingisasamplecastleforw=8andh=5:
LetF(w,h)representthenumberofvalidcastles,givengridparameterswandh.
Forexample,F(4,2)=10,F(13,10)=3729050610636,F(10,13)=37959702514,andF(100,100)mod1000
000007=841913936.
Find(F(1012,100)+F(10000,10000)+F(100,1012))mod1000000007.
Problem503:Compromiseorpersist
Aliceisplayingagamewithncardsnumbered1ton.
Agameconsistsofiterationsofthefollowingsteps.
(1)Alicepicksoneofthecardsatrandom.
(2)Alicecannotseethenumberonit.Instead,Bob,oneofherfriends,seesthenumberandtellsAlicehow
manypreviouslyseennumbersarebiggerthanthenumberwhichheisseeing.
(3)Alicecanendorcontinuethegame.Ifshedecidestoend,thenumberbecomesherscore.Ifshe
decidestocontinue,thecardisremovedfromthegameandshereturnsto(1).Ifthereisnocardleft,sheis
forcedtoendthegame.
LetF(n)betheAlice'sexpectedscoreifshetakestheoptimizedstrategytominimizeherscore.
Forexample,F(3)=5/3.Atthefirstiteration,sheshouldcontinuethegame.Attheseconditeration,she
shouldendthegameifBobsaysthatonepreviouslyseennumberisbiggerthanthenumberwhichheis
seeing,otherwisesheshouldcontinuethegame.
WecanalsoverifythatF(4)=15/8andF(10)2.5579365079.
FindF(106).Giveyouranswerroundedto10decimalplacesbehindthedecimalpoint.
Problem504:SquareontheInside
LetABCDbeaquadrilateralwhoseverticesarelatticepointslyingonthecoordinateaxesasfollows:
A(a,0),B(0,b),C(c,0),D(0,d),where1a,b,c,dmanda,b,c,d,mareintegers.
Itcanbeshownthatform=4thereareexactly256validwaystoconstructABCD.Ofthese256
quadrilaterals,42ofthemstrictlycontainasquarenumberoflatticepoints.
HowmanyquadrilateralsABCDstrictlycontainasquarenumberoflatticepointsform=100?
https://projecteuler.net/show=all
159/163
5/2/2015
Problem505:BidirectionalRecurrence
Let:
x(0)
= 0
x(1)
= 1
x(2k)
= (3x(k) + 2x(
))mod2
60
))mod2
60
x(2k + 1)
= (2x(k) + 3x(
yn (k)
= {
A(n)
= yn (1)
x(k)
2
60
ifk n
ifk < n
Youaregiven:
x(2)
= 3
x(3)
= 2
x(4)
= 11
y4 (4)
= 11
y4 (3)
= 2
60
60
y4 (2)
= 2
y4 (1)
= A(4) = 8
A(10)
= 2
A(10 )
12
FindA(10
60
12
34
= 101881
Problem506:Clocksequence
Considertheinfiniterepeatingsequenceofdigits:
1234321234321234321...
Amazingly,youcanbreakthissequenceofdigitsintoasequenceofintegerssuchthatthesumofthedigits
inthen'thvalueisn.
Thesequencegoesasfollows:
1,2,3,4,32,123,43,2123,432,1234,32123,...
Letvnbethen'thvalueinthissequence.Forexample,v2=2,v5=32andv11=32123.
LetS(n)bev1+v2+...+vn.Forexample,S(11)=36120,andS(1000)mod123454321=18232686.
FindS(1014)mod123454321.
Problem507:ShortestLatticeVector
Lettn bethetribonaccinumbersdefinedas:
t0 = t1 = 0
t2 = 1
tn = tn1 + tn2 + tn3 forn 3
7
andletrn = tn mod10 .
ForeachpairofVectorsVn
with
and
w1 = r 12n5 r 12n4 , w2 = r 12n3 + r 12n2 , w3 = r 12n1 r 12n
wedefineS (n) astheminimalvalueofthemanhattanlengthofthevectorD = k Vn + l Wn
measuredas|k v1 + l w1 | + |k v2 + l w2 | + |k v3 + l w3 | foranyintegersk andl with
(k, l) (0, 0) .
= (v1 , v2 , v3 )
andWn
= (w 1 , w 2 , w 3 )
Thefirstvectorpairis(1,3,28),(11,125,40826).
10
YouaregiventhatS (1) = 32andn=1 S (n) =
https://projecteuler.net/show=all
20000000
(
130762273722
.
160/163
5/2/2015
Findn=1
S (n)
Problem508:Integersinbasei1
ConsidertheGaussianintegeri1.Abasei1representationofaGaussianintegera+biisafinite
sequenceofdigitsdn1dn2...d1d0suchthat:
a+bi=dn1(i1)n1+dn2(i1)n2+...+d1(i1)+d0
Eachdkisin{0,1}
Therearenoleadingzeroes,i.e.dn10,unlessa+biisitself0
Herearebasei1representationsofafewGaussianintegers:
11+24i111010110001101
2411i110010110011
8+0i111000000
5+0i11001101
0+0i0
Remarkably,everyGaussianintegerhasauniquebasei1representation!
Definef(a+bi)asthenumberof1sintheuniquebasei1representationofa+bi.Forexample,f(11+24i)=9
andf(2411i)=7.
DefineB(L)asthesumoff(a+bi)forallintegersa,bsuchthat|a|Land|b|L.Forexample,B(500)=
10795060.
FindB(1015)mod1000000007.
Problem509:DivisorNim
AntonandBertrandlovetoplaythreepileNim.
However,afteralotofgamesofNimtheygotboredandchangedtherulessomewhat.
Theymayonlytakeanumberofstonesfromapilethatisaproperdivisorofthenumberofstonespresent
inthepile.
E.g.ifapileatacertainmomentcontains24stonestheymaytakeonly1,2,3,4,6,8or12stonesfromthat
pile.
Soifapilecontainsonestonetheycan'ttakethelaststonefromitas1isn'taproperdivisorof1.
Thefirstplayerthatcan'tmakeavalidmovelosesthegame.
OfcoursebothAntonandBertrandplayoptimally.
Thetriple(a,b,c)indicatesthenumberofstonesinthethreepiles.
LetS(n)bethenumberofwinningpositionsforthenextplayerfor1a,b,cn.
S(10)=692andS(100)=735494.
FindS(123456787654321)modulo1234567890.
Problem510:TangentCircles
CirclesAandBaretangenttoeachotherandtolineLatthreedistinctpoints.
CircleCisinsidethespacebetweenA,BandL,andtangenttoallthree.
LetrA,rBandrCbetheradiiofA,BandCrespectively.
https://projecteuler.net/show=all
161/163
5/2/2015
LetS(n)=rA+rB+rC,for0<rArBnwhererA,rBandrCareintegers.
Theonlysolutionfor0<rArB5isrA=4,rB=4andrC=1,soS(5)=4+4+1=9.
YouarealsogivenS(100)=3072.
FindS(109).
Problem511:Sequenceswithnicedivisibilityproperties
LetSeq(n,k)bethenumberofpositiveintegersequences{ai}1inoflengthnsuchthat:
nisdivisiblebyaifor1in,and
n+a1+a2+...+anisdivisiblebyk.
Examples:
Seq(3,4)=4,andthe4sequencesare:
{1,1,3}
{1,3,1}
{3,1,1}
{3,3,3}
Seq(4,11)=8,andthe8sequencesare:
{1,1,1,4}
{1,1,4,1}
{1,4,1,1}
{4,1,1,1}
{2,2,2,1}
{2,2,1,2}
{2,1,2,2}
{1,2,2,2}
ThelastninedigitsofSeq(1111,24)are840643584.
FindthelastninedigitsofSeq(1234567898765,4321).
Problem512:Sumsoftotientsofpowers
Let(n) beEuler'stotientfunction.
n
Letf (n)
= (
Letg(n)
i=1
n
i=1
g(100) = 2007
8
Findg(5 10
(n ))mod(n + 1)
f (i)
Problem513:Integralmedian
https://projecteuler.net/show=all
162/163
5/2/2015
ABCisanintegralsidedtrianglewithsidesabc.
mcisthemedianconnectingCandthemidpointofAB.
F(n)isthenumberofsuchtriangleswithcnforwhichmchasintegrallengthaswell.
F(10)=3andF(50)=165.
FindF(100000).
https://projecteuler.net/show=all
163/163