163
Problem 1: Multiples of 3 and 5 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. Problem 2: Even Fibonacci numbers Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the evenvalued terms. Problem 3: Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Problem 4: Largest palindrome product A palindromic number reads the same both ways. The largest palindrome made from the product of two 2 digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3digit numbers. Problem 5: Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? Problem 6: Sum square difference The sum of the squares of the first ten natural numbers is, 1 2 +2 2 + ... + 10 2 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10) 2 = 55 2 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum. Problem 7: 10001st prime By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number?

Archived Problems - Project Euler

Embed Size (px)

DESCRIPTION

project euler problems

Citation preview

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 1/163

    Problem1:Multiplesof3and5

    Ifwelistallthenaturalnumbersbelow10thataremultiplesof3or5,weget3,5,6and9.Thesumofthesemultiplesis23.

    Findthesumofallthemultiplesof3or5below1000.

    Problem2:EvenFibonaccinumbers

    EachnewtermintheFibonaccisequenceisgeneratedbyaddingtheprevioustwoterms.Bystartingwith1and2,thefirst10termswillbe:

    1,2,3,5,8,13,21,34,55,89,...

    ByconsideringthetermsintheFibonaccisequencewhosevaluesdonotexceedfourmillion,findthesumoftheevenvaluedterms.

    Problem3:Largestprimefactor

    Theprimefactorsof13195are5,7,13and29.

    Whatisthelargestprimefactorofthenumber600851475143?

    Problem4:Largestpalindromeproduct

    Apalindromicnumberreadsthesamebothways.Thelargestpalindromemadefromtheproductoftwo2digitnumbersis9009=9199.

    Findthelargestpalindromemadefromtheproductoftwo3digitnumbers.

    Problem5:Smallestmultiple

    2520isthesmallestnumberthatcanbedividedbyeachofthenumbersfrom1to10withoutanyremainder.

    Whatisthesmallestpositivenumberthatisevenlydivisiblebyallofthenumbersfrom1to20?

    Problem6:Sumsquaredifference

    Thesumofthesquaresofthefirsttennaturalnumbersis,

    12+22+...+102=385

    Thesquareofthesumofthefirsttennaturalnumbersis,

    (1+2+...+10)2=552=3025

    Hencethedifferencebetweenthesumofthesquaresofthefirsttennaturalnumbersandthesquareofthesumis3025385=2640.

    Findthedifferencebetweenthesumofthesquaresofthefirstonehundrednaturalnumbersandthesquareofthesum.

    Problem7:10001stprime

    Bylistingthefirstsixprimenumbers:2,3,5,7,11,and13,wecanseethatthe6thprimeis13.

    Whatisthe10001stprimenumber?

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 2/163

    Problem8:Largestproductinaseries

    Thefouradjacentdigitsinthe1000digitnumberthathavethegreatestproductare9989=5832.

    7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450

    Findthethirteenadjacentdigitsinthe1000digitnumberthathavethegreatestproduct.Whatisthevalueofthisproduct?

    Problem9:SpecialPythagoreantriplet

    APythagoreantripletisasetofthreenaturalnumbers,a

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 3/163

    Whatisthegreatestproductoffouradjacentnumbersinthesamedirection(up,down,left,right,ordiagonally)inthe2020grid?

    Problem12:Highlydivisibletriangularnumber

    Thesequenceoftrianglenumbersisgeneratedbyaddingthenaturalnumbers.Sothe7thtrianglenumberwouldbe1+2+3+4+5+6+7=28.Thefirsttentermswouldbe:

    1,3,6,10,15,21,28,36,45,55,...

    Letuslistthefactorsofthefirstseventrianglenumbers:

    1:13:1,36:1,2,3,610:1,2,5,1015:1,3,5,1521:1,3,7,2128:1,2,4,7,14,28

    Wecanseethat28isthefirsttrianglenumbertohaveoverfivedivisors.

    Whatisthevalueofthefirsttrianglenumbertohaveoverfivehundreddivisors?

    Problem13:Largesum

    Workoutthefirsttendigitsofthesumofthefollowingonehundred50digitnumbers.

    37107287533902102798797998220837590246510135740250463769376774900097126481248969700780504170182605387432498619952474105947423330951305812372661730962991942213363574161572522430563301811072406154908250230675882075393461711719803104210475137780632466768926167069662363382013637841838368417873436172675728112879812849979408065481931592621691275889832738442742289174325203219235894228767964876702721893184745144573600130643909116721685684458871160315327670386486105843025439939619828917593665686757934951621764571418565606295021572231965867550793241933316490635246274190492910143244581382266334794475817892575867718337217661963751590579239728245598838407582035653253593990084026335689488301894586282278288018119938482628201427819413994056758715117009439035398664372827112653829987240784473053190104293586865155060062958648615320752733719591914205172558297169388870771546649911559348760353292171497005693854370070576826684624621495650076471787294438377604532826541087568284431911906346940378552177792951453612327252500029607107508256381565671088525835072145876576172410976447339110607218265236877223636045174237069058518606604482076212098132878607339694128114266041808683061932846081119106155694051268969251934325451728388641918047049293215058642563049483624672216484350762017279180399446930047329563406911573244438690812579451408905770622942919710792820955037687525678773091862540744969844508330393682126183363848253301546861961243487676812975343759465158038628759287849020152168555482871720121925776695478182833757993103614740356856449095527097864797581167263201004368978425535399209318374414978068609844840309812907779179908821879532736447567559084803087086987551392711854517078544161852424320693150332599594068957565367821070749269665376763262354472106979395067965269474259770973916669376304263398708541052684708299085211399427365734116182760315001271653786073615010808570091499395125570281987460043753582903531743471732693212357815498262974255273730794953759765105305946966067683156574377167401875275889028025717332296191766687138199318110487701902712526768027607800301367868099252546340106163286652636270218540497705585629946580636237993140746255962240744869082311749777923654662572469233228109171419143028819710328859780666976089293863828502533340334413065578016127815921815005561868836468420090470230530811728164304876237919698424872550366387845831148769693215490281042402013833512446218144177347063783299490636259666498587618221225225512486764533677201869716985443124195724099139590089523100588229554825530026352078153229679624948164195386821877476085327132285723110424803456124867697064507995236377742425354112916842768655389262050249103265729672370191327572567528565324825826546309220705859652229798860272258331913126375147341994889534765745501

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 4/163

    184957014548792889848568277260777137214037988797153829820378303147352772158034814451349137322665138134829543829199918180278916522431027392251122869539409579530664052326325380441000596549391598795936352974615218550237130764225512118369380358038858490341698116222072977186158236678424689157993532961922624679571944012690438771072750481023908955235974572318970677254791506150550495392297953090112996751986188088225875314529584099251203829009407770775672113067397083047244838165338735023408456470580773088295917476714036319800818712901187549131054712658197623331044818386269515456334926366572897563400500428462801835170705278318394258821455212272512503275512160354698120058176216521282765275169129689778932238195734329339946437501907836945765883352399886755061649651847751807381688378610915273579297013376217784275219262340194239963916804498399317331273132924185707147349566916674687634660915035914677504995186714302352196288948901024233251169136196266227326746080059154747183079839286853520694694454072476841822524674417161514036427982273348055556214818971426179103425986472045168939894221798260880768528778364618279934631376775430780936333301898264209010848802521674670883215120185883543223812876952786713296124747824645386369930090493103636197638780396218407357239979422340623539380833965132740801111666627891981488087797941876876144230030984490851411606618262936828367647447792391803351109890697907148578694408955299065364044742557608365997664579509666024396409905389607120198219976047599490197230297649139826800329731560371200413779037855660850892521673093931987275027546890690370753941304265231501194809377245048795150954100921645863754710598436791786391670211874924319957006419179697775990283006991536871371193661495281130587638027841075444973307840789923115535562561142322423255033685442488917353448899115014406480203690680639606723221932041495354150312888033953605329934036800697771065056663195481234880673210146739058568557934581403627822703280826165707739483275922328459417065250945123252306082291880205877731971983945018088807242966198081119777158542502016545090413245809786882778948721859617721078384350691861554356628840622574736922845095162084960398013400172393067166682355524525280460972253503534226472524250874054075591789781264330331690

    Problem14:LongestCollatzsequence

    Thefollowingiterativesequenceisdefinedforthesetofpositiveintegers:

    nn/2(niseven)n3n+1(nisodd)

    Usingtheruleaboveandstartingwith13,wegeneratethefollowingsequence:

    134020105168421

    Itcanbeseenthatthissequence(startingat13andfinishingat1)contains10terms.Althoughithasnotbeenprovedyet(CollatzProblem),itisthoughtthatallstartingnumbersfinishat1.

    Whichstartingnumber,underonemillion,producesthelongestchain?

    NOTE:Oncethechainstartsthetermsareallowedtogoaboveonemillion.

    Problem15:Latticepaths

    Startinginthetopleftcornerofa22grid,andonlybeingabletomovetotherightanddown,thereareexactly6routestothebottomrightcorner.

    Howmanysuchroutesaretherethrougha2020grid?

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 5/163

    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,howmanyletterswouldbeused?

    NOTE:Donotcountspacesorhyphens.Forexample,342(threehundredandfortytwo)contains23lettersand115(onehundredandfifteen)contains20letters.Theuseof"and"whenwritingoutnumbersisincompliancewithBritishusage.

    Problem18:MaximumpathsumI

    Bystartingatthetopofthetrianglebelowandmovingtoadjacentnumbersontherowbelow,themaximumtotalfromtoptobottomis23.

    374

    2468593

    Thatis,3+7+4+9=23.

    Findthemaximumtotalfromtoptobottomofthetrianglebelow:

    759564

    17478218358710

    2004824765190123750334

    880277730763679965042806167092

    41412656834080703341487233473237169429

    5371446525439152975114701133287773177839681757

    917152381714914358502729486366046889536730731669874031

    046298272309709873933853600423

    NOTE:Asthereareonly16384routes,itispossibletosolvethisproblembytryingeveryroute.However,Problem67,isthesamechallengewithatrianglecontainingonehundredrowsitcannotbesolvedbybruteforce,andrequiresaclevermethod!o)

    Problem19:CountingSundays

    Youaregiventhefollowinginformation,butyoumayprefertodosomeresearchforyourself.

    1Jan1900wasaMonday.ThirtydayshasSeptember,April,JuneandNovember.Alltheresthavethirtyone,SavingFebruaryalone,Whichhastwentyeight,rainorshine.Andonleapyears,twentynine.Aleapyearoccursonanyyearevenlydivisibleby4,butnotonacenturyunlessitisdivisibleby400.

    HowmanySundaysfellonthefirstofthemonthduringthetwentiethcentury(1Jan1901to31Dec2000)?

    Problem20:Factorialdigitsum

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 6/163

    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,thenaandbareanamicablepairandeachofaandbarecalledamicablenumbers.

    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...'),a46Ktextfilecontainingoverfivethousandfirstnames,beginbysortingitintoalphabeticalorder.Thenworkingoutthealphabeticalvalueforeachname,multiplythisvaluebyitsalphabeticalpositioninthelisttoobtainanamescore.

    Forexample,whenthelistissortedintoalphabeticalorder,COLIN,whichisworth3+15+12+9+14=53,isthe938thnameinthelist.So,COLINwouldobtainascoreof93853=49714.

    Whatisthetotalofallthenamescoresinthefile?

    Problem23:Nonabundantsums

    Aperfectnumberisanumberforwhichthesumofitsproperdivisorsisexactlyequaltothenumber.Forexample,thesumoftheproperdivisorsof28wouldbe1+2+4+7+14=28,whichmeansthat28isaperfectnumber.

    Anumberniscalleddeficientifthesumofitsproperdivisorsislessthannanditiscalledabundantifthissumexceedsn.

    As12isthesmallestabundantnumber,1+2+3+4+6=16,thesmallestnumberthatcanbewrittenasthesumoftwoabundantnumbersis24.Bymathematicalanalysis,itcanbeshownthatallintegersgreaterthan28123canbewrittenasthesumoftwoabundantnumbers.However,thisupperlimitcannotbereducedanyfurtherbyanalysiseventhoughitisknownthatthegreatestnumberthatcannotbeexpressedasthesumoftwoabundantnumbersislessthanthislimit.

    Findthesumofallthepositiveintegerswhichcannotbewrittenasthesumoftwoabundantnumbers.

    Problem24:Lexicographicpermutations

    Apermutationisanorderedarrangementofobjects.Forexample,3124isonepossiblepermutationofthedigits1,2,3and4.Ifallofthepermutationsarelistednumericallyoralphabetically,wecallitlexicographicorder.Thelexicographicpermutationsof0,1and2are:

    012021102120201210

    Whatisthemillionthlexicographicpermutationofthedigits0,1,2,3,4,5,6,7,8and9?

    Problem25:1000digitFibonaccinumber

    TheFibonaccisequenceisdefinedbytherecurrencerelation:

    Fn=Fn1+Fn2,whereF1=1andF2=1.

    Hencethefirst12termswillbe:

    F1=1

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 7/163

    F2=1F3=2F4=3F5=5F6=8F7=13F8=21F9=34F10=55F11=89F12=144

    The12thterm,F12,isthefirsttermtocontainthreedigits.

    WhatistheindexofthefirsttermintheFibonaccisequencetocontain1000digits?

    Problem26:Reciprocalcycles

    Aunitfractioncontains1inthenumerator.Thedecimalrepresentationoftheunitfractionswithdenominators2to10aregiven:

    1/2 = 0.51/3 = 0.(3)1/4 = 0.251/5 = 0.21/6 = 0.1(6)1/7 = 0.(142857)1/8 = 0.1251/9 = 0.(1)1/10 = 0.1

    Where0.1(6)means0.166666...,andhasa1digitrecurringcycle.Itcanbeseenthat1/7hasa6digitrecurringcycle.

    Findthevalueofd

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 8/163

    21222324252078910196121118543121716151413

    Itcanbeverifiedthatthesumofthenumbersonthediagonalsis101.

    Whatisthesumofthenumbersonthediagonalsina1001by1001spiralformedinthesameway?

    Problem29:Distinctpowers

    Considerallintegercombinationsofabfor2a5and2b5:

    22=4,23=8,24=16,25=3232=9,33=27,34=81,35=24342=16,43=64,44=256,45=102452=25,53=125,54=625,55=3125

    Iftheyarethenplacedinnumericalorder,withanyrepeatsremoved,wegetthefollowingsequenceof15distinctterms:

    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

    Thesumofthesenumbersis1634+8208+9474=19316.

    Findthesumofallthenumbersthatcanbewrittenasthesumoffifthpowersoftheirdigits.

    Problem31:Coinsums

    InEnglandthecurrencyismadeupofpound,,andpence,p,andthereareeightcoinsingeneralcirculation:

    1p,2p,5p,10p,20p,50p,1(100p)and2(200p).

    Itispossibletomake2inthefollowingway:

    11+150p+220p+15p+12p+31p

    Howmanydifferentwayscan2bemadeusinganynumberofcoins?

    Problem32:Pandigitalproducts

    Weshallsaythatanndigitnumberispandigitalifitmakesuseofallthedigits1tonexactlyonceforexample,the5digitnumber,15234,is1through5pandigital.

    Theproduct7254isunusual,astheidentity,39186=7254,containingmultiplicand,multiplier,andproductis1through9pandigital.

    Findthesumofallproductswhosemultiplicand/multiplier/productidentitycanbewrittenasa1through9pandigital.

    HINT:Someproductscanbeobtainedinmorethanonewaysobesuretoonlyincludeitonceinyoursum.

    As1=14isnotasumitisnotincluded.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 9/163

    Problem33:Digitcancellingfractions

    Thefraction49/98isacuriousfraction,asaninexperiencedmathematicianinattemptingtosimplifyitmayincorrectlybelievethat49/98=4/8,whichiscorrect,isobtainedbycancellingthe9s.

    Weshallconsiderfractionslike,30/50=3/5,tobetrivialexamples.

    Thereareexactlyfournontrivialexamplesofthistypeoffraction,lessthanoneinvalue,andcontainingtwodigitsinthenumeratoranddenominator.

    Iftheproductofthesefourfractionsisgiveninitslowestcommonterms,findthevalueofthedenominator.

    Problem34:Digitfactorials

    145isacuriousnumber,as1!+4!+5!=1+24+120=145.

    Findthesumofallnumberswhichareequaltothesumofthefactorialoftheirdigits.

    Problem35:Circularprimes

    Thenumber,197,iscalledacircularprimebecauseallrotationsofthedigits:197,971,and719,arethemselvesprime.

    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.

    Problem37:Truncatableprimes

    Thenumber3797hasaninterestingproperty.Beingprimeitself,itispossibletocontinuouslyremovedigitsfromlefttoright,andremainprimeateachstage:3797,797,97,and7.Similarlywecanworkfromrighttoleft:3797,379,37,and3.

    Findthesumoftheonlyelevenprimesthatarebothtruncatablefromlefttorightandrighttoleft.

    Problem38:Pandigitalmultiples

    Takethenumber192andmultiplyitbyeachof1,2,and3:

    1921=1921922=3841923=576

    Byconcatenatingeachproductwegetthe1to9pandigital,192384576.Wewillcall192384576theconcatenatedproductof192and(1,2,3)

    Thesamecanbeachievedbystartingwith9andmultiplyingby1,2,3,4,and5,givingthepandigital,918273645,whichistheconcatenatedproductof9and(1,2,3,4,5).

    Whatisthelargest1to9pandigital9digitnumberthatcanbeformedastheconcatenatedproductofanintegerwith(1,2,...,n)wheren>1?

    Note:as1!=1and2!=2arenotsumstheyarenotincluded.

    (Pleasenotethatthepalindromicnumber,ineitherbase,maynotincludeleadingzeros.)

    NOTE:2,3,5,and7arenotconsideredtobetruncatableprimes.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 10/163

    Problem39:Integerrighttriangles

    Ifpistheperimeterofarightangletrianglewithintegrallengthsides,{a,b,c},thereareexactlythreesolutionsforp=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.Forexample,2143isa4digitpandigitalandisalsoprime.

    Whatisthelargestndigitpandigitalprimethatexists?

    Problem42:Codedtrianglenumbers

    Thenthtermofthesequenceoftrianglenumbersisgivenby,tn=n(n+1)sothefirsttentrianglenumbersare:

    1,3,6,10,15,21,28,36,45,55,...

    Byconvertingeachletterinawordtoanumbercorrespondingtoitsalphabeticalpositionandaddingthesevaluesweformawordvalue.Forexample,thewordvalueforSKYis19+11+25=55=t10.Ifthewordvalueisatrianglenumberthenweshallcallthewordatriangleword.

    Usingwords.txt(rightclickand'SaveLink/TargetAs...'),a16KtextfilecontainingnearlytwothousandcommonEnglishwords,howmanyaretrianglewords?

    Problem43:Substringdivisibility

    Thenumber,1406357289,isa0to9pandigitalnumberbecauseitismadeupofeachofthedigits0to9insomeorder,butitalsohasaratherinterestingsubstringdivisibilityproperty.

    Letd1bethe1stdigit,d2bethe2nddigit,andsoon.Inthisway,wenotethefollowing:

    d2d3d4=406isdivisibleby2d3d4d5=063isdivisibleby3d4d5d6=635isdivisibleby5d5d6d7=357isdivisibleby7d6d7d8=572isdivisibleby11d7d8d9=728isdivisibleby13d8d9d10=289isdivisibleby17

    Findthesumofall0to9pandigitalnumberswiththisproperty.

    Problem44:Pentagonnumbers

    Pentagonalnumbersaregeneratedbytheformula,Pn=n(3n1)/2.Thefirsttenpentagonalnumbersare:

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 11/163

    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,...Pentagonal Pn=n(3n1)/2 1,5,12,22,35,...Hexagonal Hn=n(2n1) 1,6,15,28,45,...

    ItcanbeverifiedthatT285=P165=H143=40755.

    Findthenexttrianglenumberthatisalsopentagonalandhexagonal.

    Problem46:Goldbach'sotherconjecture

    ItwasproposedbyChristianGoldbachthateveryoddcompositenumbercanbewrittenasthesumofaprimeandtwiceasquare.

    9=7+212

    15=7+222

    21=3+232

    25=7+232

    27=19+222

    33=31+212

    Itturnsoutthattheconjecturewasfalse.

    Whatisthesmallestoddcompositethatcannotbewrittenasthesumofaprimeandtwiceasquare?

    Problem47:Distinctprimesfactors

    Thefirsttwoconsecutivenumberstohavetwodistinctprimefactorsare:

    14=2715=35

    Thefirstthreeconsecutivenumberstohavethreedistinctprimefactorsare:

    644=2723645=3543646=21719.

    Findthefirstfourconsecutiveintegerstohavefourdistinctprimefactors.Whatisthefirstofthesenumbers?

    Problem48:Selfpowers

    Theseries,11+22+33+...+1010=10405071317.

    Findthelasttendigitsoftheseries,11+22+33+...+10001000.

    Problem49:Primepermutations

    Thearithmeticsequence,1487,4817,8147,inwhicheachofthetermsincreasesby3330,isunusualintwoways:(i)eachofthethreetermsareprime,and,(ii)eachofthe4digitnumbersarepermutationsofoneanother.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 12/163

    Therearenoarithmeticsequencesmadeupofthree1,2,or3digitprimes,exhibitingthisproperty,butthereisoneother4digitincreasingsequence.

    What12digitnumberdoyouformbyconcatenatingthethreetermsinthissequence?

    Problem50:Consecutiveprimesum

    Theprime41,canbewrittenasthesumofsixconsecutiveprimes:

    41=2+3+5+7+11+13

    Thisisthelongestsumofconsecutiveprimesthataddstoaprimebelowonehundred.

    Thelongestsumofconsecutiveprimesbelowonethousandthataddstoaprime,contains21terms,andisequalto953.

    Whichprime,belowonemillion,canbewrittenasthesumofthemostconsecutiveprimes?

    Problem51:Primedigitreplacements

    Byreplacingthe1stdigitofthe2digitnumber*3,itturnsoutthatsixoftheninepossiblevalues:13,23,43,53,73,and83,areallprime.

    Byreplacingthe3rdand4thdigitsof56**3withthesamedigit,this5digitnumberisthefirstexamplehavingsevenprimesamongthetengeneratednumbers,yieldingthefamily:56003,56113,56333,56443,56663,56773,and56993.Consequently56003,beingthefirstmemberofthisfamily,isthesmallestprimewiththisproperty.

    Findthesmallestprimewhich,byreplacingpartofthenumber(notnecessarilyadjacentdigits)withthesamedigit,ispartofaneightprimevaluefamily.

    Problem52:Permutedmultiples

    Itcanbeseenthatthenumber,125874,anditsdouble,251748,containexactlythesamedigits,butinadifferentorder.

    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,

    nCr=n!

    r!(nr)! ,wherern,n!=n(n1)...321,and0!=1.

    Itisnotuntiln=23,thatavalueexceedsonemillion:23C10=1144066.

    Howmany,notnecessarilydistinct,valuesofnCr,for1n100,aregreaterthanonemillion?

    Problem54:Pokerhands

    Inthecardgamepoker,ahandconsistsoffivecardsandareranked,fromlowesttohighest,inthefollowingway:

    HighCard:Highestvaluecard.OnePair:Twocardsofthesamevalue.TwoPairs:Twodifferentpairs.ThreeofaKind:Threecardsofthesamevalue.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 13/163

    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,apairofeightsbeatsapairoffives(seeexample1below).Butiftworankstie,forexample,bothplayershaveapairofqueens,thenhighestcardsineachhandarecompared(seeexample4below)ifthehighestcardstiethenthenexthighestcardsarecompared,andsoon.

    Considerthefollowingfivehandsdealttotwoplayers:

    Hand Player1 Player2 Winner1 5H5C6S7SKDPairofFives

    2C3S8S8DTDPairofEights

    Player2

    2 5D8C9SJSACHighestcardAce 2C5C7D8SQHHighestcardQueen

    Player1

    3 2D9CASAHACThreeAces 3D6D7DTDQDFlushwithDiamonds

    Player2

    44D6S9HQHQC

    PairofQueensHighestcardNine

    3D6D7HQDQS

    PairofQueensHighestcardSeven

    Player1

    52H2D4C4D4S

    FullHouseWithThreeFours

    3C3D3S9S9D

    FullHousewithThreeThrees

    Player1

    Thefile,poker.txt,containsonethousandrandomhandsdealttotwoplayers.Eachlineofthefilecontainstencards(separatedbyasinglespace):thefirstfivearePlayer1'scardsandthelastfivearePlayer2'scards.Youcanassumethatallhandsarevalid(noinvalidcharactersorrepeatedcards),eachplayer'shandisinnospecificorder,andineachhandthereisaclearwinner.

    HowmanyhandsdoesPlayer1win?

    Problem55:Lychrelnumbers

    Ifwetake47,reverseandadd,47+74=121,whichispalindromic.

    Notallnumbersproducepalindromessoquickly.Forexample,

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

    Thatis,349tookthreeiterationstoarriveatapalindrome.

    Althoughnoonehasprovedityet,itisthoughtthatsomenumbers,like196,neverproduceapalindrome.AnumberthatneverformsapalindromethroughthereverseandaddprocessiscalledaLychrelnumber.Duetothetheoreticalnatureofthesenumbers,andforthepurposeofthisproblem,weshallassumethatanumberisLychreluntilprovenotherwise.Inadditionyouaregiventhatforeverynumberbelowtenthousand,itwilleither(i)becomeapalindromeinlessthanfiftyiterations,or,(ii)noone,withallthecomputingpowerthatexists,hasmanagedsofartomapittoapalindrome.Infact,10677isthefirstnumbertobeshowntorequireoverfiftyiterationsbeforeproducingapalindrome:4668731596684224866951378664(53iterations,28digits).

    Surprisingly,therearepalindromicnumbersthatarethemselvesLychrelnumbersthefirstexampleis4994.

    HowmanyLychrelnumbersaretherebelowtenthousand?

    NOTE:Wordingwasmodifiedslightlyon24April2007toemphasisethetheoreticalnatureofLychrelnumbers.

    Problem56:Powerfuldigitsum

    Agoogol(10100)isamassivenumber:onefollowedbyonehundredzeros100100isalmostunimaginablylarge:onefollowedbytwohundredzeros.Despitetheirsize,thesumofthedigitsineachnumberisonly1.

    Consideringnaturalnumbersoftheform,ab,wherea,b

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 14/163

    Problem57:Squarerootconvergents

    Itispossibletoshowthatthesquarerootoftwocanbeexpressedasaninfinitecontinuedfraction.

    2=1+1/(2+1/(2+1/(2+...)))=1.414213...

    Byexpandingthisforthefirstfouriterations,weget:

    1+1/2=3/2=1.51+1/(2+1/2)=7/5=1.41+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,isthefirstexamplewherethenumberofdigitsinthenumeratorexceedsthenumberofdigitsinthedenominator.

    Inthefirstonethousandexpansions,howmanyfractionscontainanumeratorwithmoredigitsthandenominator?

    Problem58:Spiralprimes

    Startingwith1andspirallinganticlockwiseinthefollowingway,asquarespiralwithsidelength7isformed.

    37363534333231381716151413303918543122940196121128412078910274221222324252643444546474849

    Itisinterestingtonotethattheoddsquaresliealongthebottomrightdiagonal,butwhatismoreinterestingisthat8outofthe13numberslyingalongbothdiagonalsareprimethatis,aratioof8/1362%.

    Ifonecompletenewlayeriswrappedaroundthespiralabove,asquarespiralwithsidelength9willbeformed.Ifthisprocessiscontinued,whatisthesidelengthofthesquarespiralforwhichtheratioofprimesalongbothdiagonalsfirstfallsbelow10%?

    Problem59:XORdecryption

    EachcharacteronacomputerisassignedauniquecodeandthepreferredstandardisASCII(AmericanStandardCodeforInformationInterchange).Forexample,uppercaseA=65,asterisk(*)=42,andlowercasek=107.

    Amodernencryptionmethodistotakeatextfile,convertthebytestoASCII,thenXOReachbytewithagivenvalue,takenfromasecretkey.TheadvantagewiththeXORfunctionisthatusingthesameencryptionkeyontheciphertext,restorestheplaintextforexample,65XOR42=107,then107XOR42=65.

    Forunbreakableencryption,thekeyisthesamelengthastheplaintextmessage,andthekeyismadeupofrandombytes.Theuserwouldkeeptheencryptedmessageandtheencryptionkeyindifferentlocations,andwithoutboth"halves",itisimpossibletodecryptthemessage.

    Unfortunately,thismethodisimpracticalformostusers,sothemodifiedmethodistouseapasswordasakey.Ifthepasswordisshorterthanthemessage,whichislikely,thekeyisrepeatedcyclicallythroughoutthemessage.Thebalanceforthismethodisusingasufficientlylongpasswordkeyforsecurity,butshortenoughtobememorable.

    Yourtaskhasbeenmadeeasy,astheencryptionkeyconsistsofthreelowercasecharacters.Usingcipher.txt(rightclickand'SaveLink/TargetAs...'),afilecontainingtheencryptedASCIIcodes,andtheknowledgethattheplaintextmustcontaincommonEnglishwords,decryptthemessageandfindthesumoftheASCIIvaluesintheoriginaltext.

    Problem60:Primepairsets

    Theprimes3,7,109,and673,arequiteremarkable.Bytakinganytwoprimesandconcatenatingtheminanyordertheresultwillalwaysbeprime.Forexample,taking7and109,both7109and1097areprime.Thesumofthesefourprimes,792,representsthelowestsumforasetoffourprimeswiththisproperty.

    Findthelowestsumforasetoffiveprimesforwhichanytwoprimesconcatenatetoproduceanotherprime.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 15/163

    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,...Pentagonal P5,n=n(3n1)/2 1,5,12,22,35,...Hexagonal P6,n=n(2n1) 1,6,15,28,45,...Heptagonal P7,n=n(5n3)/2 1,7,18,34,55,...Octagonal P8,n=n(3n2) 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),isrepresentedbyadifferentnumberintheset.

    3. Thisistheonlysetof4digitnumberswiththisproperty.

    Findthesumoftheonlyorderedsetofsixcyclic4digitnumbersforwhicheachpolygonaltype:triangle,square,pentagonal,hexagonal,heptagonal,andoctagonal,isrepresentedbyadifferentnumberintheset.

    Problem62:Cubicpermutations

    Thecube,41063625(3453),canbepermutedtoproducetwoothercubes:56623104(3843)and66430125(4053).Infact,41063625isthesmallestcubewhichhasexactlythreepermutationsofitsdigitswhicharealsocube.

    Findthesmallestcubeforwhichexactlyfivepermutationsofitsdigitsarecube.

    Problem63:Powerfuldigitcounts

    The5digitnumber,16807=75,isalsoafifthpower.Similarly,the9digitnumber,134217728=89,isaninthpower.

    Howmanyndigitpositiveintegersexistwhicharealsoannthpower?

    Problem64:Oddperiodsquareroots

    Allsquarerootsareperiodicwhenwrittenascontinuedfractionsandcanbewrittenintheform:

    N=a0+ 1 a1+ 1 a2+ 1 a3+...

    Forexample,letusconsider23:

    23=4+234=4+ 1 =4+ 1

    1234 1+233

    7

    Ifwecontinuewewouldgetthefollowingexpansion:

    23=4+ 1 1+ 1 3+ 1 1+ 1 8+...

    Theprocesscanbesummarisedasfollows:

    a0=4,1

    234=23+4

    7 =1+233

    77 7(23+3) 233

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 16/163

    a1=1,233= 14 =3+ 2

    a2=3,2

    233=2(23+3)

    14 =1+234

    7a3=1,

    7234=

    7(23+4)7 =8+234

    a4=8,1

    234=23+4

    7 =1+233

    7a5=1,

    7233=

    7(23+3)14 =3+

    2332

    a6=3,2

    233=2(23+3)

    14 =1+234

    7a7=1,

    7234=

    7(23+4)7 =8+234

    Itcanbeseenthatthesequenceisrepeating.Forconciseness,weusethenotation23=[4(1,3,1,8)],toindicatethattheblock(1,3,1,8)repeatsindefinitely.

    Thefirsttencontinuedfractionrepresentationsof(irrational)squarerootsare:

    2=[1(2)],period=13=[1(1,2)],period=25=[2(4)],period=16=[2(2,4)],period=27=[2(1,1,1,4)],period=48=[2(1,4)],period=210=[3(6)],period=111=[3(3,6)],period=212=[3(2,6)],period=213=[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.Inasimilarway,23=[4(1,3,1,8)].

    Itturnsoutthatthesequenceofpartialvaluesofcontinuedfractionsforsquarerootsprovidethebestrationalapproximations.Letusconsidertheconvergentsfor2.

    1+1=3/2 21+ 1 =7/5 2+1 21+ 1 =17/12 2+ 1 2+1 21+ 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,...

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 17/163

    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=122312=192542=152622=182732=1

    Hence,byconsideringminimalsolutionsinxforD7,thelargestxisobtainedwhenD=5.

    FindthevalueofD1000inminimalsolutionsofxforwhichthelargestvalueofxisobtained.

    Problem67:MaximumpathsumII

    Bystartingatthetopofthetrianglebelowandmovingtoadjacentnumbersontherowbelow,themaximumtotalfromtoptobottomis23.

    374

    2468593

    Thatis,3+7+4+9=23.

    Findthemaximumtotalfromtoptobottomintriangle.txt(rightclickand'SaveLink/TargetAs...'),a15Ktextfilecontainingatrianglewithonehundredrows.

    NOTE:ThisisamuchmoredifficultversionofProblem18.Itisnotpossibletotryeveryroutetosolvethisproblem,asthereare299altogether!Ifyoucouldcheckonetrillion(1012)routeseveryseconditwouldtakeovertwentybillionyearstocheckthemall.Thereisanefficientalgorithmtosolveit.o)

    Problem68:Magic5gonring

    Considerthefollowing"magic"3gonring,filledwiththenumbers1to6,andeachlineaddingtonine.

    Workingclockwise,andstartingfromthegroupofthreewiththenumericallylowestexternalnode(4,3,2inthisexample),eachsolutioncanbedescribeduniquely.Forexample,theabovesolutioncanbedescribedbytheset:4,3,26,2,15,1,3.

    Itispossibletocompletetheringwithfourdifferenttotals:9,10,11,and12.Thereareeightsolutionsintotal.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 18/163

    Total SolutionSet9 4,2,35,3,16,1,29 4,3,26,2,15,1,310 2,3,54,5,16,1,310 2,5,36,3,14,1,511 1,4,63,6,25,2,411 1,6,45,4,23,2,612 1,5,62,6,43,4,512 1,6,53,5,42,4,6

    Byconcatenatingeachgroupitispossibletoform9digitstringsthemaximumstringfora3gonringis432621513.

    Usingthenumbers1to10,anddependingonarrangements,itispossibletoform16and17digitstrings.Whatisthemaximum16digitstringfora"magic"5gonring?

    Problem69:Totientmaximum

    Euler'sTotientfunction,(n)[sometimescalledthephifunction],isusedtodeterminethenumberofnumberslessthannwhicharerelativelyprimeton.Forexample,as1,2,4,5,7,and8,arealllessthannineandrelativelyprimetonine,(9)=6.

    n RelativelyPrime (n) n/(n)2 1 1 23 1,2 2 1.54 1,3 2 25 1,2,3,4 4 1.256 1,5 2 37 1,2,3,4,5,6 6 1.1666...8 1,3,5,7 4 29 1,2,4,5,7,8 6 1.510 1,3,7,9 4 2.5

    Itcanbeseenthatn=6producesamaximumn/(n)forn10.

    Findthevalueofn1,000,000forwhichn/(n)isamaximum.

    Problem70:Totientpermutation

    Euler'sTotientfunction,(n)[sometimescalledthephifunction],isusedtodeterminethenumberofpositivenumberslessthanorequaltonwhicharerelativelyprimeton.Forexample,as1,2,4,5,7,and8,arealllessthannineandrelativelyprimetonine,(9)=6.Thenumber1isconsideredtoberelativelyprimetoeverypositivenumber,so(1)=1.

    Interestingly,(87109)=79180,anditcanbeseenthat87109isapermutationof79180.

    Findthevalueofn,1

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 19/163

    Considerthefraction,n/d,wherenanddarepositiveintegers.Ifn

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 20/163

    30cm:(5,12,13)36cm:(9,12,15)40cm:(8,15,17)48cm:(12,16,20)

    Incontrast,somelengthsofwire,like20cm,cannotbebenttoformanintegersidedrightangletriangle,andotherlengthsallowmorethanonesolutiontobefoundforexample,using120cmitispossibletoformexactlythreedifferentintegersidedrightangletriangles.

    120cm:(30,40,50),(20,48,52),(24,45,51)

    GiventhatListhelengthofthewire,forhowmanyvaluesofL1,500,000canexactlyoneintegersidedrightangletrianglebeformed?

    Problem76:Countingsummations

    Itispossibletowritefiveasasuminexactlysixdifferentways:

    4+13+23+1+12+2+12+1+1+11+1+1+1+1

    Howmanydifferentwayscanonehundredbewrittenasasumofatleasttwopositiveintegers?

    Problem77:Primesummations

    Itispossibletowritetenasthesumofprimesinexactlyfivedifferentways:

    7+35+55+3+23+3+2+22+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

    Acommonsecuritymethodusedforonlinebankingistoasktheuserforthreerandomcharactersfromapasscode.Forexample,ifthepasscodewas531278,theymayaskforthe2nd,3rd,and5thcharacterstheexpectedreplywouldbe:317.

    Thetextfile,keylog.txt,containsfiftysuccessfulloginattempts.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 21/163

    Giventhatthethreecharactersarealwaysaskedforinorder,analysethefilesoastodeterminetheshortestpossiblesecretpasscodeofunknownlength.

    Problem80:Squarerootdigitalexpansion

    Itiswellknownthatifthesquarerootofanaturalnumberisnotaninteger,thenitisirrational.Thedecimalexpansionofsuchsquarerootsisinfinitewithoutanyrepeatingpatternatall.

    Thesquarerootoftwois1.41421356237309504880...,andthedigitalsumofthefirstonehundreddecimaldigitsis475.

    Forthefirstonehundrednaturalnumbers,findthetotalofthedigitalsumsofthefirstonehundreddecimaldigitsforalltheirrationalsquareroots.

    Problem81:Pathsum:twoways

    Inthe5by5matrixbelow,theminimalpathsumfromthetoplefttothebottomright,byonlymovingtotherightanddown,isindicatedinboldredandisequalto2427.

    Findtheminimalpathsum,inmatrix.txt(rightclickand"SaveLink/TargetAs..."),a31Ktextfilecontaininga80by80matrix,fromthetoplefttothebottomrightbyonlymovingrightanddown.

    Problem82:Pathsum:threeways

    NOTE:ThisproblemisamorechallengingversionofProblem81.

    Theminimalpathsuminthe5by5matrixbelow,bystartinginanycellintheleftcolumnandfinishinginanycellintherightcolumn,andonlymovingup,down,andright,isindicatedinredandboldthesumisequalto994.

    Findtheminimalpathsum,inmatrix.txt(rightclickand"SaveLink/TargetAs..."),a31Ktextfilecontaininga80by80matrix,fromtheleftcolumntotherightcolumn.

    Problem83:Pathsum:fourways

    NOTE:ThisproblemisasignificantlymorechallengingversionofProblem81.

    Inthe5by5matrixbelow,theminimalpathsumfromthetoplefttothebottomright,bymovingleft,right,up,anddown,isindicatedinboldredandisequalto2297.

    Findtheminimalpathsum,inmatrix.txt(rightclickand"SaveLink/TargetAs..."),a31Ktextfilecontaininga80by80matrix,fromthetoplefttothebottomrightbymovingleft,right,up,anddown.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 22/163

    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

    AplayerstartsontheGOsquareandaddsthescoresontwo6sideddicetodeterminethenumberofsquarestheyadvanceinaclockwisedirection.Withoutanyfurtherruleswewouldexpecttovisiteachsquarewithequalprobability:2.5%.However,landingonG2J(GoToJail),CC(communitychest),andCH(chance)changesthisdistribution.

    InadditiontoG2J,andonecardfromeachofCCandCH,thatorderstheplayertogodirectlytojail,ifaplayerrollsthreeconsecutivedoubles,theydonotadvancetheresultoftheir3rdroll.Insteadtheyproceeddirectlytojail.

    Atthebeginningofthegame,theCCandCHcardsareshuffled.WhenaplayerlandsonCCorCHtheytakeacardfromthetopoftherespectivepileand,afterfollowingtheinstructions,itisreturnedtothebottomofthepile.Therearesixteencardsineachpile,butforthepurposeofthisproblemweareonlyconcernedwithcardsthatorderamovementanyinstructionnotconcernedwithmovementwillbeignoredandtheplayerwillremainontheCC/CHsquare.

    CommunityChest(2/16cards):1. AdvancetoGO2. GotoJAIL

    Chance(10/16cards):1. AdvancetoGO2. GotoJAIL3. GotoC14. GotoE35. GotoH26. GotoR17. GotonextR(railwaycompany)8. GotonextR9. GotonextU(utilitycompany)

    10. Goback3squares.

    Theheartofthisproblemconcernsthelikelihoodofvisitingaparticularsquare.Thatis,theprobabilityoffinishingatthatsquareafteraroll.Forthisreasonitshouldbeclearthat,withtheexceptionofG2Jforwhichtheprobabilityoffinishingonitiszero,theCHsquareswillhavethelowestprobabilities,as5/8requestamovementtoanothersquare,anditisthefinalsquarethattheplayerfinishesatoneachrollthatweareinterestedin.Weshallmakenodistinctionbetween"JustVisiting"andbeingsenttoJAIL,andweshallalsoignoretheruleaboutrequiringadoubleto"getoutofjail",assumingthattheypaytogetoutontheirnextturn.

    BystartingatGOandnumberingthesquaressequentiallyfrom00to39wecanconcatenatethesetwodigitnumberstoproducestringsthatcorrespondwithsetsofsquares.

    Statisticallyitcanbeshownthatthethreemostpopularsquares,inorder,areJAIL(6.24%)=Square10,E3(3.18%)=Square24,andGO(3.09%)=Square00.Sothesethreemostpopularsquarescanbelistedwiththesixdigitmodalstring:102400.

    If,insteadofusingtwo6sideddice,two4sideddiceareused,findthesixdigitmodalstring.

    Problem85:Countingrectangles

    Bycountingcarefullyitcanbeseenthatarectangulargridmeasuring3by2containseighteenrectangles:

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 23/163

    Althoughthereexistsnorectangulargridthatcontainsexactlytwomillionrectangles,findtheareaofthegridwiththenearestsolution.

    Problem86:Cuboidroute

    Aspider,S,sitsinonecornerofacuboidroom,measuring6by5by3,andafly,F,sitsintheoppositecorner.Bytravellingonthesurfacesoftheroomtheshortest"straightline"distancefromStoFis10andthepathisshownonthediagram.

    However,thereareuptothree"shortest"pathcandidatesforanygivencuboidandtheshortestroutedoesn'talwayshaveintegerlength.

    Itcanbeshownthatthereareexactly2060distinctcuboids,ignoringrotations,withintegerdimensions,uptoamaximumsizeofMbyMbyM,forwhichtheshortestroutehasintegerlengthwhenM=100.ThisistheleastvalueofMforwhichthenumberofsolutionsfirstexceedstwothousandthenumberofsolutionswhenM=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,andprimefourthpower?

    Problem88:Productsumnumbers

    Anaturalnumber,N,thatcanbewrittenasthesumandproductofagivensetofatleasttwonaturalnumbers,{a1,a2,...,ak}iscalledaproductsumnumber:N=a1+a2+...+ak=a1a2...ak.

    Forexample,6=1+2+3=123.

    Foragivensetofsize,k,weshallcallthesmallestNwiththispropertyaminimalproductsumnumber.Theminimalproductsumnumbersforsetsofsize,k=2,3,4,5,and6areasfollows.

    k=2:4=22=2+2k=3:6=123=1+2+3k=4:8=1124=1+1+2+4k=5:8=11222=1+1+2+2+2k=6:12=111126=1+1+1+1+2+6

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 24/163

    Hencefor2k6,thesumofalltheminimalproductsumnumbersis4+6+8+12=30notethat8isonlycountedonceinthesum.

    Infact,asthecompletesetofminimalproductsumnumbersfor2k12is{4,6,8,12,15,16},thesumis61.

    Whatisthesumofalltheminimalproductsumnumbersfor2k12000?

    Problem89:Romannumerals

    ForanumberwritteninRomannumeralstobeconsideredvalidtherearebasicruleswhichmustbefollowed.Eventhoughtherulesallowsomenumberstobeexpressedinmorethanonewaythereisalwaysa"best"wayofwritingaparticularnumber.

    Forexample,itwouldappearthatthereareatleastsixwaysofwritingthenumbersixteen:

    IIIIIIIIIIIIIIIIVIIIIIIIIIIIVVIIIIIIXIIIIIIVVVIXVI

    However,accordingtotherulesonlyXIIIIIIandXVIarevalid,andthelastexampleisconsideredtobethemostefficient,asitusestheleastnumberofnumerals.

    The11Ktextfile,roman.txt(rightclickand'SaveLink/TargetAs...'),containsonethousandnumberswritteninvalid,butnotnecessarilyminimal,RomannumeralsseeAbout...RomanNumeralsforthedefinitiverulesforthisproblem.

    Findthenumberofcharacterssavedbywritingeachoftheseintheirminimalform.

    Note:YoucanassumethatalltheRomannumeralsinthefilecontainnomorethanfourconsecutiveidenticalunits.

    Problem90:Cubedigitpairs

    Eachofthesixfacesonacubehasadifferentdigit(0to9)writtenonitthesameisdonetoasecondcube.Byplacingthetwocubessidebysideindifferentpositionswecanformavarietyof2digitnumbers.

    Forexample,thesquarenumber64couldbeformed:

    Infact,bycarefullychoosingthedigitsonbothcubesitispossibletodisplayallofthesquarenumbersbelowonehundred: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}allowsforallninesquarenumberstobedisplayedotherwiseitwouldbeimpossibletoobtain09.

    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,thetwodistinctsetsinthelastexamplebothrepresenttheextendedset{1,2,3,4,5,6,9}forthepurposeofforming2digitnumbers.

    Howmanydistinctarrangementsofthetwocubesallowforallofthesquarenumberstobedisplayed?

    Problem91:Righttriangleswithintegercoordinates

    ThepointsP(x1,y1)andQ(x2,y2)areplottedatintegercoordinatesandarejoinedtotheorigin,O(0,0),to

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 25/163

    formOPQ.

    Thereareexactlyfourteentrianglescontainingarightanglethatcanbeformedwheneachcoordinateliesbetween0and2inclusivethatis,0x1,y1,x2,y22.

    Giventhat0x1,y1,x2,y250,howmanyrighttrianglescanbeformed?

    Problem92:Squaredigitchains

    Anumberchainiscreatedbycontinuouslyaddingthesquareofthedigitsinanumbertoformanewnumberuntilithasbeenseenbefore.

    Forexample,

    443213101185891454220416375889

    Thereforeanychainthatarrivesat1or89willbecomestuckinanendlessloop.WhatismostamazingisthatEVERYstartingnumberwilleventuallyarriveat1or89.

    Howmanystartingnumbersbelowtenmillionwillarriveat89?

    Problem93:Arithmeticexpressions

    Byusingeachofthedigitsfromtheset,{1,2,3,4},exactlyonce,andmakinguseofthefourarithmeticoperations(+,,*,/)andbrackets/parentheses,itispossibletoformdifferentpositiveintegertargets.

    Forexample,

    8=(4*(1+3))/214=4*(3+1/2)19=4*(2+3)136=3*4*(2+1)

    Notethatconcatenationsofthedigits,like12+34,arenotallowed.

    Usingtheset,{1,2,3,4},itispossibletoobtainthirtyonedifferenttargetnumbersofwhich36isthemaximum,andeachofthenumbers1to28canbeobtainedbeforeencounteringthefirstnonexpressiblenumber.

    Findthesetoffourdistinctdigits,a

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 26/163

    Problem94:Almostequilateraltriangles

    Itiseasilyprovedthatnoequilateraltriangleexistswithintegrallengthsidesandintegralarea.However,thealmostequilateraltriangle556hasanareaof12squareunits.

    Weshalldefineanalmostequilateraltriangletobeatriangleforwhichtwosidesareequalandthethirddiffersbynomorethanoneunit.

    Findthesumoftheperimetersofallalmostequilateraltriangleswithintegralsidelengthsandareaandwhoseperimetersdonotexceedonebillion(1,000,000,000).

    Problem95:Amicablechains

    Theproperdivisorsofanumberareallthedivisorsexcludingthenumberitself.Forexample,theproperdivisorsof28are1,2,4,7,and14.Asthesumofthesedivisorsisequalto28,wecallitaperfectnumber.

    Interestinglythesumoftheproperdivisorsof220is284andthesumoftheproperdivisorsof284is220,formingachainoftwonumbers.Forthisreason,220and284arecalledanamicablepair.

    Perhapslesswellknownarelongerchains.Forexample,startingwith12496,weformachainoffivenumbers:

    1249614288154721453614264(12496...)

    Sincethischainreturnstoitsstartingpoint,itiscalledanamicablechain.

    Findthesmallestmemberofthelongestamicablechainwithnoelementexceedingonemillion.

    Problem96:SuDoku

    SuDoku(Japanesemeaningnumberplace)isthenamegiventoapopularpuzzleconcept.Itsoriginisunclear,butcreditmustbeattributedtoLeonhardEulerwhoinventedasimilar,andmuchmoredifficult,puzzleideacalledLatinSquares.TheobjectiveofSuDokupuzzles,however,istoreplacetheblanks(orzeros)ina9by9gridinsuchthateachrow,column,and3by3boxcontainseachofthedigits1to9.Belowisanexampleofatypicalstartingpuzzlegridanditssolutiongrid.

    003900001

    020305806

    600001400

    008700006

    102000708

    900008200

    002800005

    609203010

    500009300

    483967251

    921345876

    657821493

    548729136

    132564798

    976138245

    372814695

    689253417

    514769382

    AwellconstructedSuDokupuzzlehasauniquesolutionandcanbesolvedbylogic,althoughitmaybenecessarytoemploy"guessandtest"methodsinordertoeliminateoptions(thereismuchcontestedopinionoverthis).Thecomplexityofthesearchdeterminesthedifficultyofthepuzzletheexampleaboveisconsideredeasybecauseitcanbesolvedbystraightforwarddirectdeduction.

    The6Ktextfile,sudoku.txt(rightclickand'SaveLink/TargetAs...'),containsfiftydifferentSuDokupuzzlesrangingindifficulty,butallwithuniquesolutions(thefirstpuzzleinthefileistheexampleabove).

    Bysolvingallfiftypuzzlesfindthesumofthe3digitnumbersfoundinthetopleftcornerofeachsolutiongridforexample,483isthe3digitnumberfoundinthetopleftcornerofthesolutiongridabove.

    Problem97:LargenonMersenneprime

    Thefirstknownprimefoundtoexceedonemilliondigitswasdiscoveredin1999,andisaMersenneprimeoftheform269725931itcontainsexactly2,098,960digits.SubsequentlyotherMersenneprimes,oftheform2p1,havebeenfoundwhichcontainmoredigits.

    However,in2004therewasfoundamassivenonMersenneprimewhichcontains2,357,207digits:2843327830457+1.

    Findthelasttendigitsofthisprimenumber.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 27/163

    Problem98:Anagramicsquares

    ByreplacingeachofthelettersinthewordCAREwith1,2,9,and6respectively,weformasquarenumber:1296=362.Whatisremarkableisthat,byusingthesamedigitalsubstitutions,theanagram,RACE,alsoformsasquarenumber:9216=962.WeshallcallCARE(andRACE)asquareanagramwordpairandspecifyfurtherthatleadingzeroesarenotpermitted,neithermayadifferentletterhavethesamedigitalvalueasanotherletter.

    Usingwords.txt(rightclickand'SaveLink/TargetAs...'),a16KtextfilecontainingnearlytwothousandcommonEnglishwords,findallthesquareanagramwordpairs(apalindromicwordisNOTconsideredtobeananagramofitself).

    Whatisthelargestsquarenumberformedbyanymemberofsuchapair?

    Problem99:Largestexponential

    Comparingtwonumberswritteninindexformlike211and37isnotdifficult,asanycalculatorwouldconfirmthat211=2048519432525806wouldbemuchmoredifficult,asbothnumberscontainoverthreemilliondigits.

    Usingbase_exp.txt(rightclickand'SaveLink/TargetAs...'),a22Ktextfilecontainingonethousandlineswithabase/exponentpaironeachline,determinewhichlinenumberhasthegreatestnumericalvalue.

    Problem100:Arrangedprobability

    Ifaboxcontainstwentyonecoloureddiscs,composedoffifteenbluediscsandsixreddiscs,andtwodiscsweretakenatrandom,itcanbeseenthattheprobabilityoftakingtwobluediscs,P(BB)=(15/21)(14/20)=1/2.

    Thenextsucharrangement,forwhichthereisexactly50%chanceoftakingtwobluediscsatrandom,isaboxcontainingeightyfivebluediscsandthirtyfivereddiscs.

    Byfindingthefirstarrangementtocontainover1012=1,000,000,000,000discsintotal,determinethenumberofbluediscsthattheboxwouldcontain.

    Problem101:Optimumpolynomial

    Ifwearepresentedwiththefirstktermsofasequenceitisimpossibletosaywithcertaintythevalueofthenextterm,asthereareinfinitelymanypolynomialfunctionsthatcanmodelthesequence.

    Asanexample,letusconsiderthesequenceofcubenumbers.Thisisdefinedbythegeneratingfunction,un=n3:1,8,27,64,125,216,...

    Supposewewereonlygiventhefirsttwotermsofthissequence.Workingontheprinciplethat"simpleisbest"weshouldassumealinearrelationshipandpredictthenexttermtobe15(commondifference7).Evenifwewerepresentedwiththefirstthreeterms,bythesameprincipleofsimplicity,aquadraticrelationshipshouldbeassumed.

    WeshalldefineOP(k,n)tobethenthtermoftheoptimumpolynomialgeneratingfunctionforthefirstktermsofasequence.ItshouldbeclearthatOP(k,n)willaccuratelygeneratethetermsofthesequencefornk,andpotentiallythefirstincorrectterm(FIT)willbeOP(k,k+1)inwhichcaseweshallcallitabadOP(BOP).

    Asabasis,ifwewereonlygiventhefirsttermofsequence,itwouldbemostsensibletoassumeconstancythatis,forn2,OP(1,n)=u1.

    HenceweobtainthefollowingOPsforthecubicsequence:

    OP(1,n)=1 1,1,1,1,...

    NOTE:Allanagramsformedmustbecontainedinthegiventextfile.

    NOTE:Thefirsttwolinesinthefilerepresentthenumbersintheexamplegivenabove.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 28/163

    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,suchthatatriangleisformed.

    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...'),a27Ktextfilecontainingthecoordinatesofonethousand"random"triangles,findthenumberoftrianglesforwhichtheinteriorcontainstheorigin.

    Problem103:Specialsubsetsums:optimum

    LetS(A)representthesumofelementsinsetAofsizen.Weshallcallitaspecialsumsetifforanytwononemptydisjointsubsets,BandC,thefollowingpropertiesaretrue:

    i. S(B)S(C)thatis,sumsofsubsetscannotbeequal.ii. IfBcontainsmoreelementsthanCthenS(B)>S(C).

    IfS(A)isminimisedforagivenn,weshallcallitanoptimumspecialsumset.Thefirstfiveoptimumspecialsumsetsaregivenbelow.

    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},withS(A)=117.However,thisisnottheoptimumset,aswehavemerelyappliedanalgorithmtoprovideanearoptimumset.Theoptimumsetforn=6isA={11,18,19,20,22,25},withS(A)=115andcorrespondingsetstring:111819202225.

    GiventhatAisanoptimumspecialsumsetforn=7,finditssetstring.

    NOTE:ThisproblemisrelatedtoProblem105andProblem106.

    Problem104:PandigitalFibonacciends

    TheFibonaccisequenceisdefinedbytherecurrencerelation:

    Fn=Fn1+Fn2,whereF1=1andF2=1.

    ItturnsoutthatF541,whichcontains113digits,isthefirstFibonaccinumberforwhichthelastninedigitsare19pandigital(containallthedigits1to9,butnotnecessarilyinorder).AndF2749,whichcontains575

    NOTE:Thefirsttwoexamplesinthefilerepresentthetrianglesintheexamplegivenabove.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 29/163

    digits,isthefirstFibonaccinumberforwhichthefirstninedigitsare19pandigital.

    GiventhatFkisthefirstFibonaccinumberforwhichthefirstninedigitsANDthelastninedigitsare19pandigital,findk.

    Problem105:Specialsubsetsums:testing

    LetS(A)representthesumofelementsinsetAofsizen.Weshallcallitaspecialsumsetifforanytwononemptydisjointsubsets,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}satisfiesbothrulesforallpossiblesubsetpaircombinationsandS(A)=1286.

    Usingsets.txt(rightclickand"SaveLink/TargetAs..."),a4Ktextfilewithonehundredsetscontainingseventotwelveelements(thetwoexamplesgivenabovearethefirsttwosetsinthefile),identifyallthespecialsumsets,A1,A2,...,Ak,andfindthevalueofS(A1)+S(A2)+...+S(Ak).

    NOTE:ThisproblemisrelatedtoProblem103andProblem106.

    Problem106:Specialsubsetsums:metatesting

    LetS(A)representthesumofelementsinsetAofsizen.Weshallcallitaspecialsumsetifforanytwononemptydisjointsubsets,BandC,thefollowingpropertiesaretrue:

    i. S(B)S(C)thatis,sumsofsubsetscannotbeequal.ii. IfBcontainsmoreelementsthanCthenS(B)>S(C).

    Forthisproblemweshallassumethatagivensetcontainsnstrictlyincreasingelementsanditalreadysatisfiesthesecondrule.

    Surprisingly,outofthe25possiblesubsetpairsthatcanbeobtainedfromasetforwhichn=4,only1ofthesepairsneedtobetestedforequality(firstrule).Similarly,whenn=7,only70outofthe966subsetpairsneedtobetested.

    Forn=12,howmanyofthe261625subsetpairsthatcanbeobtainedneedtobetestedforequality?

    NOTE:ThisproblemisrelatedtoProblem103andProblem105.

    Problem107:Minimalnetwork

    Thefollowingundirectednetworkconsistsofsevenverticesandtwelveedgeswithatotalweightof243.

    Thesamenetworkcanberepresentedbythematrixbelow.

    A B C D E F G

    A 16 12 21

    B 16 17 20

    C 12 28 31

    D 21 17 28 18 19 23

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 30/163

    E 20 18 11

    F 31 19 27

    G 23 11 27

    However,itispossibletooptimisethenetworkbyremovingsomeedgesandstillensurethatallpointsonthenetworkremainconnected.Thenetworkwhichachievesthemaximumsavingisshownbelow.Ithasaweightof93,representingasavingof24393=150fromtheoriginalnetwork.

    Usingnetwork.txt(rightclickand'SaveLink/TargetAs...'),a6Ktextfilecontaininganetworkwithfortyvertices,andgiveninmatrixform,findthemaximumsavingwhichcanbeachievedbyremovingredundantedgeswhilstensuringthatthenetworkremainsconnected.

    Problem108:DiophantinereciprocalsI

    Inthefollowingequationx,y,andnarepositiveintegers.

    1x +

    1y =

    1n

    Forn=4thereareexactlythreedistinctsolutions:

    15 +

    120 =

    14

    16 +

    112 =

    14

    18 +

    18 =

    14

    Whatistheleastvalueofnforwhichthenumberofdistinctsolutionsexceedsonethousand?

    NOTE:ThisproblemisaneasierversionofProblem110itisstronglyadvisedthatyousolvethisonefirst.

    Problem109:Darts

    Inthegameofdartsaplayerthrowsthreedartsatatargetboardwhichissplitintotwentyequalsizedsectionsnumberedonetotwenty.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 31/163

    Thescoreofadartisdeterminedbythenumberoftheregionthatthedartlandsin.Adartlandingoutsidethered/greenouterringscoreszero.Theblackandcreamregionsinsidethisringrepresentsinglescores.However,thered/greenouterringandmiddleringscoredoubleandtreblescoresrespectively.

    Atthecentreoftheboardaretwoconcentriccirclescalledthebullregion,orbullseye.Theouterbullisworth25pointsandtheinnerbullisadouble,worth50points.

    Therearemanyvariationsofrulesbutinthemostpopulargametheplayerswillbeginwithascore301or501andthefirstplayertoreducetheirrunningtotaltozeroisawinner.However,itisnormaltoplaya"doublesout"system,whichmeansthattheplayermustlandadouble(includingthedoublebullseyeatthecentreoftheboard)ontheirfinaldarttowinanyotherdartthatwouldreducetheirrunningtotaltooneorlowermeansthescoreforthatsetofthreedartsis"bust".

    Whenaplayerisabletofinishontheircurrentscoreitiscalleda"checkout"andthehighestcheckoutis170:T20T20D25(twotreble20sanddoublebull).

    Thereareexactlyelevendistinctwaystocheckoutonascoreof6:

    D3 D1 D2 S2 D2 D2 D1 S4 D1 S1 S1 D2S1 T1 D1S1 S3 D1D1 D1 D1D1 S2 D1S2 S2 D1

    NotethatD1D2isconsidereddifferenttoD2D1astheyfinishondifferentdoubles.However,thecombinationS1T1D1isconsideredthesameasT1S1D1.

    Inadditionweshallnotincludemissesinconsideringcombinationsforexample,D3isthesameas0D3and00D3.

    Incrediblythereare42336distinctwaysofcheckingoutintotal.

    Howmanydistinctwayscanaplayercheckoutwithascorelessthan100?

    Problem110:DiophantinereciprocalsII

    Inthefollowingequationx,y,andnarepositiveintegers.

    1x +

    1y =

    1n

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 32/163

    Itcanbeverifiedthatwhenn=1260thereare113distinctsolutionsandthisistheleastvalueofnforwhichthetotalnumberofdistinctsolutionsexceedsonehundred.

    Whatistheleastvalueofnforwhichthenumberofdistinctsolutionsexceedsfourmillion?

    NOTE:ThisproblemisamuchmoredifficultversionofProblem108andasitiswellbeyondthelimitationsofabruteforceapproachitrequiresacleverimplementation.

    Problem111:Primeswithruns

    Considering4digitprimescontainingrepeateddigitsitisclearthattheycannotallbethesame:1111isdivisibleby11,2222isdivisibleby22,andsoon.Buttherearenine4digitprimescontainingthreeones:

    1117,1151,1171,1181,1511,1811,2111,4111,8111

    WeshallsaythatM(n,d)representsthemaximumnumberofrepeateddigitsforanndigitprimewheredistherepeateddigit,N(n,d)representsthenumberofsuchprimes,andS(n,d)representsthesumoftheseprimes.

    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 2 13 67061

    1 3 9 22275

    2 3 1 2221

    3 3 12 46214

    4 3 2 8888

    5 3 1 5557

    6 3 1 6661

    7 3 9 57863

    8 3 1 8887

    9 3 7 48073

    Ford=0to9,thesumofallS(4,d)is273700.

    FindthesumofallS(10,d).

    Problem112:Bouncynumbers

    Workingfromlefttorightifnodigitisexceededbythedigittoitsleftitiscalledanincreasingnumberforexample,134468.

    Similarlyifnodigitisexceededbythedigittoitsrightitiscalledadecreasingnumberforexample,66420.

    Weshallcallapositiveintegerthatisneitherincreasingnordecreasinga"bouncy"numberforexample,155349.

    Clearlytherecannotbeanybouncynumbersbelowonehundred,butjustoverhalfofthenumbersbelowonethousand(525)arebouncy.Infact,theleastnumberforwhichtheproportionofbouncynumbersfirstreaches50%is538.

    Surprisingly,bouncynumbersbecomemoreandmorecommonandbythetimewereach21780theproportionofbouncynumbersisequalto90%.

    Findtheleastnumberforwhichtheproportionofbouncynumbersisexactly99%.

    Problem113:Nonbouncynumbers

    Workingfromlefttorightifnodigitisexceededbythedigittoitsleftitiscalledanincreasingnumberforexample,134468.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 33/163

    Similarlyifnodigitisexceededbythedigittoitsrightitiscalledadecreasingnumberforexample,66420.

    Weshallcallapositiveintegerthatisneitherincreasingnordecreasinga"bouncy"numberforexample,155349.

    Asnincreases,theproportionofbouncynumbersbelownincreasessuchthatthereareonly12951numbersbelowonemillionthatarenotbouncyandonly277032nonbouncynumbersbelow1010.

    Howmanynumbersbelowagoogol(10100)arenotbouncy?

    Problem114:CountingblockcombinationsI

    Arowmeasuringsevenunitsinlengthhasredblockswithaminimumlengthofthreeunitsplacedonit,suchthatanytworedblocks(whichareallowedtobedifferentlengths)areseparatedbyatleastoneblacksquare.Thereareexactlyseventeenwaysofdoingthis.

    Howmanywayscanarowmeasuringfiftyunitsinlengthbefilled?

    NOTE:Althoughtheexampleabovedoesnotlenditselftothepossibility,ingeneralitispermittedtomixblocksizes.Forexample,onarowmeasuringeightunitsinlengthyoucouldusered(3),black(1),andred(4).

    Problem115:CountingblockcombinationsII

    NOTE:ThisisamoredifficultversionofProblem114.

    Arowmeasuringnunitsinlengthhasredblockswithaminimumlengthofmunitsplacedonit,suchthatanytworedblocks(whichareallowedtobedifferentlengths)areseparatedbyatleastoneblacksquare.

    Letthefillcountfunction,F(m,n),representthenumberofwaysthatarowcanbefilled.

    Forexample,F(3,29)=673135andF(3,30)=1089155.

    Thatis,form=3,itcanbeseenthatn=30isthesmallestvalueforwhichthefillcountfunctionfirstexceedsonemillion.

    Inthesameway,form=10,itcanbeverifiedthatF(10,56)=880711andF(10,57)=1148904,son=57istheleastvalueforwhichthefillcountfunctionfirstexceedsonemillion.

    Form=50,findtheleastvalueofnforwhichthefillcountfunctionfirstexceedsonemillion.

    Problem116:Red,greenorbluetiles

    Arowoffiveblacksquaretilesistohaveanumberofitstilesreplacedwithcolouredoblongtileschosenfromred(lengthtwo),green(lengththree),orblue(lengthfour).

    Ifredtilesarechosenthereareexactlysevenwaysthiscanbedone.

    Ifgreentilesarechosentherearethreeways.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 34/163

    Andifbluetilesarechosentherearetwoways.

    Assumingthatcolourscannotbemixedthereare7+3+2=12waysofreplacingtheblacktilesinarowmeasuringfiveunitsinlength.

    Howmanydifferentwayscantheblacktilesinarowmeasuringfiftyunitsinlengthbereplacedifcolourscannotbemixedandatleastonecolouredtilemustbeused?

    NOTE:ThisisrelatedtoProblem117.

    Problem117:Red,green,andbluetiles

    Usingacombinationofblacksquaretilesandoblongtileschosenfrom:redtilesmeasuringtwounits,greentilesmeasuringthreeunits,andbluetilesmeasuringfourunits,itispossibletotilearowmeasuringfiveunitsinlengthinexactlyfifteendifferentways.

    Howmanywayscanarowmeasuringfiftyunitsinlengthbetiled?

    NOTE:ThisisrelatedtoProblem116.

    Problem118:Pandigitalprimesets

    Usingallofthedigits1through9andconcatenatingthemfreelytoformdecimalintegers,differentsetscanbeformed.Interestinglywiththeset{2,5,47,89,631},alloftheelementsbelongingtoitareprime.

    Howmanydistinctsetscontainingeachofthedigitsonethroughnineexactlyoncecontainonlyprimeelements?

    Problem119:Digitpowersum

    Thenumber512isinterestingbecauseitisequaltothesumofitsdigitsraisedtosomepower:5+1+2=8,and83=512.Anotherexampleofanumberwiththispropertyis614656=284.

    Weshalldefineantobethenthtermofthissequenceandinsistthatanumbermustcontainatleasttwodigitstohaveasum.

    Youaregiventhata2=512anda10=614656.

    Finda30.

    Problem120:Squareremainders

    Letrbetheremainderwhen(a1)n+(a+1)nisdividedbya2.

    Forexample,ifa=7andn=3,thenr=42:63+83=72842mod49.Andasnvaries,sotoowillr,butfora=7itturnsoutthatrmax=42.

    For3a1000,findrmax.

    Problem121:Discgameprizefund

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 35/163

    Abagcontainsonereddiscandonebluedisc.Inagameofchanceaplayertakesadiscatrandomanditscolourisnoted.Aftereachturnthediscisreturnedtothebag,anextrareddiscisadded,andanotherdiscistakenatrandom.

    Theplayerpays1toplayandwinsiftheyhavetakenmorebluediscsthanreddiscsattheendofthegame.

    Ifthegameisplayedforfourturns,theprobabilityofaplayerwinningisexactly11/120,andsothemaximumprizefundthebankershouldallocateforwinninginthisgamewouldbe10beforetheywouldexpecttoincuraloss.Notethatanypayoutwillbeawholenumberofpoundsandalsoincludestheoriginal1paidtoplaythegame,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)nisdividedbypn2.

    Forexample,whenn=3,p3=5,and43+63=2805mod25.

    Theleastvalueofnforwhichtheremainderfirstexceeds109is7037.

    Findtheleastvalueofnforwhichtheremainderfirstexceeds1010.

    Problem124:Orderedradicals

    Theradicalofn,rad(n),istheproductofthedistinctprimefactorsofn.Forexample,504=23327,sorad(504)=237=42.

    Ifwecalculaterad(n)for1n10,thensortthemonrad(n),andsortingonniftheradicalvaluesareequal,weget:

    Unsorted Sorted

    n rad(n) n rad(n) k1 1 1 1 12 2 2 2 23 3 4 2 3

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 36/163

    4 2 8 2 45 5 3 3 56 6 9 3 67 7 5 5 78 2 6 6 89 3 7 7 910 10 10 10 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+12hasnotbeenincludedasthisproblemisconcernedwiththesquaresofpositiveintegers.

    Findthesumofallthenumberslessthan108thatarebothpalindromicandcanbewrittenasthesumofconsecutivesquares.

    Problem126:Cuboidlayers

    Theminimumnumberofcubestocovereveryvisiblefaceonacuboidmeasuring3x2x1istwentytwo.

    Ifwethenaddasecondlayertothissoliditwouldrequirefortysixcubestocovereveryvisibleface,thethirdlayerwouldrequireseventyeightcubes,andthefourthlayerwouldrequireonehundredandeighteencubestocovereveryvisibleface.

    However,thefirstlayeronacuboidmeasuring5x1x1alsorequirestwentytwocubessimilarlythefirstlayeroncuboidsmeasuring5x3x1,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,sorad(504)=237=42.

    Weshalldefinethetripletofpositiveintegers(a,b,c)tobeanabchitif:

    1. GCD(a,b)=GCD(a,c)=GCD(b,c)=12. a

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 37/163

    1. GCD(5,27)=GCD(5,32)=GCD(27,32)=12. 5

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 38/163

    GiventhatnisapositiveintegerandGCD(n,10)=1,itcanbeshownthattherealwaysexistsavalue,k,forwhichR(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.

    FindthesumofthefirsttwentyfivecompositevaluesofnforwhichGCD(n,10)=1andn1isdivisiblebyA(n).

    Problem131:Primecubepartnership

    Therearesomeprimevalues,p,forwhichthereexistsapositiveinteger,n,suchthattheexpressionn3+n2pisaperfectcube.

    Forexample,whenp=19,83+8219=123.

    Whatisperhapsmostsurprisingisthatforeachprimewiththispropertythevalueofnisunique,andthereareonlyfoursuchprimesbelowonehundred.

    Howmanyprimesbelowonemillionhavethisremarkableproperty?

    Problem132:Largerepunitfactors

    Anumberconsistingentirelyofonesiscalledarepunit.WeshalldefineR(k)tobearepunitoflengthk.

    Forexample,R(10)=1111111111=11412719091,andthesumoftheseprimefactorsis9414.

    FindthesumofthefirstfortyprimefactorsofR(109).

    Problem133:Repunitnonfactors

    Anumberconsistingentirelyofonesiscalledarepunit.WeshalldefineR(k)tobearepunitoflengthkforexample,R(6)=111111.

    LetusconsiderrepunitsoftheformR(10n).

    AlthoughR(10),R(100),orR(1000)arenotdivisibleby17,R(10000)isdivisibleby17.YetthereisnovalueofnforwhichR(10n)willdivideby19.Infact,itisremarkablethat11,17,41,and73aretheonlyfourprimesbelowonehundredthatcanbeafactorofR(10n).

    FindthesumofalltheprimesbelowonehundredthousandthatwillneverbeafactorofR(10n).

    Problem134:Primepairconnection

    Considertheconsecutiveprimesp1=19andp2=23.Itcanbeverifiedthat1219isthesmallestnumbersuchthatthelastdigitsareformedbyp1whilstalsobeingdivisiblebyp2.

    Infact,withtheexceptionofp1=3andp2=5,foreverypairofconsecutiveprimes,p2>p1,thereexistvaluesofnforwhichthelastdigitsareformedbyp1andnisdivisiblebyp2.LetSbethesmallestofthesevaluesofn.

    FindSforeverypairofconsecutiveprimeswith5p11000000.

    Problem135:Samedifferences

    Giventhepositiveintegers,x,y,andz,areconsecutivetermsofanarithmeticprogression,theleastvalueofthepositiveinteger,n,forwhichtheequation,x2y2z2=n,hasexactlytwosolutionsisn=27:

    342272202=1229262=27

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 39/163

    Itturnsoutthatn=1155istheleastvaluewhichhasexactlytensolutions.

    Howmanyvaluesofnlessthanonemillionhaveexactlytendistinctsolutions?

    Problem136:Singletondifference

    Thepositiveintegers,x,y,andz,areconsecutivetermsofanarithmeticprogression.Giventhatnisapositiveinteger,theequation,x2y2z2=n,hasexactlyonesolutionwhenn=20:

    13210272=20

    Infacttherearetwentyfivevaluesofnbelowonehundredforwhichtheequationhasauniquesolution.

    Howmanyvaluesofnlessthanfiftymillionhaveexactlyonesolution?

    Problem137:Fibonaccigoldennuggets

    ConsidertheinfinitepolynomialseriesAF(x)=xF1+x2F2+x3F3+...,whereFkisthekthtermintheFibonaccisequence: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 11/2 2

    (132)/3 3(895)/8 4(343)/5 5

    WeshallcallAF(x)agoldennuggetifxisrational,becausetheybecomeincreasinglyrarerforexample,the10thgoldennuggetis74049690.

    Findthe15thgoldennugget.

    Problem138:Specialisoscelestriangles

    Considertheisoscelestrianglewithbaselength,b=16,andlegs,L=17.

    ByusingthePythagoreantheoremitcanbeseenthattheheightofthetriangle,h=(17282)=15,whichisonelessthanthebaselength.

    Withb=272andL=305,wegeth=273,whichisonemorethanthebaselength,andthisisthesecondsmallestisoscelestrianglewiththepropertythath=b1.

    FindLforthetwelvesmallestisoscelestrianglesforwhichh=b1andb,Larepositiveintegers.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 40/163

    Problem139:Pythagoreantiles

    Let(a,b,c)representthethreesidesofarightangletrianglewithintegrallengthsides.Itispossibletoplacefoursuchtrianglestogethertoformasquarewithlengthc.

    Forexample,(3,4,5)trianglescanbeplacedtogethertoforma5by5squarewitha1by1holeinthemiddleanditcanbeseenthatthe5by5squarecanbetiledwithtwentyfive1by1squares.

    However,if(5,12,13)triangleswereusedthentheholewouldmeasure7by7andthesecouldnotbeusedtotilethe13by13square.

    Giventhattheperimeteroftherighttriangleislessthanonehundredmillion,howmanyPythagoreantriangleswouldallowsuchatilingtotakeplace?

    Problem140:ModifiedFibonaccigoldennuggets

    ConsidertheinfinitepolynomialseriesAG(x)=xG1+x2G2+x3G3+...,whereGkisthekthtermofthesecondorderrecurrencerelationGk=Gk1+Gk2,G1=1andG2=4thatis,1,4,5,9,14,23,....

    ForthisproblemweshallbeconcernedwithvaluesofxforwhichAG(x)isapositiveinteger.

    Thecorrespondingvaluesofxforthefirstfivenaturalnumbersareshownbelow.

    x AG(x)(51)/4 1

    2/5 2(222)/6 3

    (1375)/14 41/2 5

    WeshallcallAG(x)agoldennuggetifxisrational,becausetheybecomeincreasinglyrarerforexample,the20thgoldennuggetis211345365.

    Findthesumofthefirstthirtygoldennuggets.

    Problem141:Investigatingprogressivenumbers,n,whicharealsosquare

    Apositiveinteger,n,isdividedbydandthequotientandremainderareqandrrespectively.Inadditiond,q,andrareconsecutivepositiveintegertermsinageometricsequence,butnotnecessarilyinthatorder.

    Forexample,58dividedby6hasquotient9andremainder4.Itcanalsobeseenthat4,6,9areconsecutivetermsinageometricsequence(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,yzareallperfectsquares.

    Problem143:InvestigatingtheTorricellipointofatriangle

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 41/163

    LetABCbeatrianglewithallinterioranglesbeinglessthan120degrees.LetXbeanypointinsidethetriangleandletXA=p,XC=q,andXB=r.

    FermatchallengedTorricellitofindthepositionofXsuchthatp+q+rwasminimised.

    TorricelliwasabletoprovethatifequilateraltrianglesAOB,BNCandAMCareconstructedoneachsideoftriangleABC,thecircumscribedcirclesofAOB,BNC,andAMCwillintersectatasinglepoint,T,insidethetriangle.MoreoverheprovedthatT,calledtheTorricelli/Fermatpoint,minimisesp+q+r.Evenmoreremarkable,itcanbeshownthatwhenthesumisminimised,AN=BM=CO=p+q+randthatAN,BMandCOalsointersectatT.

    Ifthesumisminimisedanda,b,c,p,qandrareallpositiveintegersweshallcalltriangleABCaTorricellitriangle.Forexample,a=399,b=455,c=511isanexampleofaTorricellitriangle,withp+q+r=784.

    Findthesumofalldistinctvaluesofp+q+r120000forTorricellitriangles.

    Problem144:Investigatingmultiplereflectionsofalaserbeam

    Inlaserphysics,a"whitecell"isamirrorsystemthatactsasadelaylineforthelaserbeam.Thebeamentersthecell,bouncesaroundonthemirrors,andeventuallyworksitswaybackout.

    Thespecificwhitecellwewillbeconsideringisanellipsewiththeequation4x2+y2=100

    Thesectioncorrespondingto0.01x+0.01atthetopismissing,allowingthelighttoenterandexitthroughthehole.

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 42/163

    Thelightbeaminthisproblemstartsatthepoint(0.0,10.1)justoutsidethewhitecell,andthebeamfirstimpactsthemirrorat(1.4,9.6).

    Eachtimethelaserbeamhitsthesurfaceoftheellipse,itfollowstheusuallawofreflection"angleofincidenceequalsangleofreflection."Thatis,boththeincidentandreflectedbeamsmakethesameanglewiththenormallineatthepointofincidence.

    Inthefigureontheleft,theredlineshowsthefirsttwopointsofcontactbetweenthelaserbeamandthewallofthewhitecellthebluelineshowsthelinetangenttotheellipseatthepointofincidenceofthefirstbounce.

    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+27areconsecutiveprimesis10.Thesumofallsuchintegersnbelowonemillionis1242490.

    Whatisthesumofallsuchintegersnbelow150million?

    Problem147:Rectanglesincrosshatchedgrids

    Ina3x2crosshatchedgrid,atotalof37differentrectanglescouldbesituatedwithinthatgridasindicatedinthesketch.

    Thereare5gridssmallerthan3x2,verticalandhorizontaldimensionsbeingimportant,i.e.1x1,2x1,3x1,1x2and2x2.Ifeachofthemiscrosshatched,thefollowingnumberofdifferentrectanglescouldbesituatedwithinthosesmallergrids:

    1x1:12x1:43x1:81x2:42x2:18

    Addingthosetothe37ofthe3x2grid,atotalof72differentrectanglescouldbesituatedwithin3x2andsmallergrids.

    Howmanydifferentrectanglescouldbesituatedwithin47x43andsmallergrids?

    Problem148:ExploringPascal'striangle

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 43/163

    WecaneasilyverifythatnoneoftheentriesinthefirstsevenrowsofPascal'strianglearedivisibleby7:

    1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 11 6 15 20 15 6 1

    However,ifwecheckthefirstonehundredrows,wewillfindthatonly2361ofthe5050entriesarenotdivisibleby7.

    Findthenumberofentrieswhicharenotdivisibleby7inthefirstonebillion(109)rowsofPascal'striangle.

    Problem149:Searchingforamaximumsumsubsequence

    Lookingatthetablebelow,itiseasytoverifythatthemaximumpossiblesumofadjacentnumbersinanydirection(horizontal,vertical,diagonalorantidiagonal)is16(=8+7+1).

    2 5 3 2

    9 6 5 1

    3 2 7 3

    1 8 4 8

    Now,letusrepeatthesearch,butonamuchlargerscale:

    First,generatefourmillionpseudorandomnumbersusingaspecificformofwhatisknownasa"LaggedFibonacciGenerator":

    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:Searchingatriangulararrayforasubtrianglehavingminimumsum

    Inatriangulararrayofpositiveandnegativeintegers,wewishtofindasubtrianglesuchthatthesumofthenumbersitcontainsisthesmallestpossible.

    Intheexamplebelow,itcanbeeasilyverifiedthatthemarkedtrianglesatisfiesthisconditionhavingasumof42.

    Wewishtomakesuchatriangulararraywithonethousandrows,sowegenerate500500pseudorandomnumbersskintherange219,usingatypeofrandomnumbergenerator(knownasaLinearCongruentialGenerator)asfollows:

    t:=0fork=1uptok=500500:t:=(615949*t+797807)modulo220

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 44/163

    sk:=t219

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

    Ourtriangulararrayisthenformedusingthepseudorandomnumbersthus:

    s1s2s3

    s4s5s6s7s8s9s10

    ...

    Subtrianglescanstartatanyelementofthearrayandextenddownasfaraswelike(takinginthetwoelementsdirectlybelowitfromthenextrow,thethreeelementsdirectlybelowfromtherowafterthat,andsoon).The"sumofasubtriangle"isdefinedasthesumofalltheelementsitcontains.Findthesmallestpossiblesubtrianglesum.

    Problem151:Papersheetsofstandardsizes:anexpectedvalueproblem

    Aprintingshopruns16batches(jobs)everyweekandeachbatchrequiresasheetofspecialcolourproofingpaperofsizeA5.

    EveryMondaymorning,theforemanopensanewenvelope,containingalargesheetofthespecialpaperwithsizeA1.

    Heproceedstocutitinhalf,thusgettingtwosheetsofsizeA2.ThenhecutsoneoftheminhalftogettwosheetsofsizeA3andsoonuntilheobtainstheA5sizesheetneededforthefirstbatchoftheweek.

    Alltheunusedsheetsareplacedbackintheenvelope.

    Atthebeginningofeachsubsequentbatch,hetakesfromtheenvelopeonesheetofpaperatrandom.IfitisofsizeA5,heusesit.Ifitislarger,herepeatsthe'cutinhalf'procedureuntilhehaswhatheneedsandanyremainingsheetsarealwaysplacedbackintheenvelope.

    Excludingthefirstandlastbatchoftheweek,findtheexpectednumberoftimes(duringeachweek)thattheforemanfindsasinglesheetofpaperintheenvelope.

    Giveyouranswerroundedtosixdecimalplacesusingtheformatx.xxxxxx.

    Problem152:Writing1/2asasumofinversesquares

    Thereareseveralwaystowritethenumber1/2asasumofinversesquaresusingdistinctintegers.

    Forinstance,thenumbers{2,3,4,5,7,12,15,20,28,35}canbeused:

    Infact,onlyusingintegersbetween2and45inclusive,thereareexactlythreewaystodoit,theremainingtwobeing:{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/2asasumofinversesquaresusingdistinctintegersbetween2and80inclusive?

    Problem153:InvestigatingGaussianIntegers

  • 5/2/2015 Archived Problems - Project Euler

    https://projecteuler.net/show=all 45/163

    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:

    n GaussianintegerdivisorswithpositiverealpartSums(n)ofthesedivisors

    1 1 12 1,1+i,1i,2 53 1,3 44 1,1+i,1i,2,2+2i,22i,4 135 1,1+2i,12i,2+i,2i,5 12

    Fordivisorswithpositiverealparts,then,wehave: .

    For1n105,s(n)=17924657155.

    Whatiss(n)for1n108?

    Problem154:ExploringPascal'spyramid

    Atriangularpyramidisconstructedusingsphericalballssothateachballrestsonexactlythreeballsofthenextlowerlevel.