LittleDimamisbehavedduringamathlessonalotandthenastyteacherMr.Picklesgavehimthefollowingproblemasapunishment.Findallintegersolutions x (0 < x < 109) oftheequation:x = b·s(x)a + c, where a, b, c aresomepredeterminedconstantvaluesandfunction s(x) determinesthesumofalldigitsinthedecimalrepresentationofnumber x.TheteachergivesthisproblemtoDimaforeachlesson.Hechangeson...
Vasyahas n pairsofsocks.InthemorningofeachdayVasyahastoputonapairofsocksbeforehegoestoschool.Whenhecomeshomeintheevening,Vasyatakesofftheusedsocksandthrowsthemaway.Every m-thday(atdayswithnumbers m, 2m, 3m, ...)mombuysapairofsockstoVasya.Shedoesitlateintheevening,sothatVasyacannotputonanewpairofsocksbeforethenextday.HowmanyconsecutivedayspassuntilVasyarunsoutofsocks?InputThesin...
PashmakdecidedtogiveParmidaapairofflowersfromthegarden.Thereare n flowersinthegardenandthe i-thofthemhasabeautynumber bi.Parmidaisaverystrangegirlsoshedoesn'twanttohavethetwomostbeautifulflowersnecessarily.Shewantstohavethosepairsofflowersthattheirbeautydifferenceismaximalpossible!Yourtaskistowriteaprogramwhichcalculatestwothings:ThemaximumbeautydifferenceofflowersthatPashmakcangivetoP...
PashmakhasfalleninlovewithanattractivegirlcalledParmidasinceoneyearago...Today,Pashmaksetupameetingwithhispartnerinaromanticgarden.Unfortunately,Pashmakhasforgottenwherethegardenis.Butheremembersthatthegardenlookslikeasquarewithsidesparalleltothecoordinateaxes.Healsoremembersthatthereisexactlyonetreeoneachvertexofthesquare.Now,Pashmakknowsthepositionofonlytwoofthetrees.Helphimtofindthep...
Oneday,TwilightSparkleisinterestedinhowtosortasequenceofintegers a1, a2, ..., an innon-decreasingorder.Beingayoungunicorn,theonlyoperationshecanperformisaunitshift.Thatis,shecanmovethelastelementofthesequencetoitsbeginning:a1, a2, ..., an → an, a1, a2, ..., an - 1.HelpTwilightSparkletocalculate:whatistheminimumnumberofoperationsthatsheneedstosortthesequence?InputThefirst...
近期评论