Cooking Machine - CodeChef
Cooking Machine - CodeChef
Cooking Machine - CodeChef
CookingMachine|CodeChef
Hellosumer098!
AccountorLogOut
PRACTICE
COMPETE
DISCUSS
COMMUNITY
HELP
ABOUT
HomePractice(school)CookingMachine
CookingMachine
Problemcode:COOKMACH
Like
ALLSUBMISSIONS
MYSUBMISSIONS
SUBMIT
Share 5peoplelikethis.Bethefirstofyourfriends.
Allsubmissionsforthisproblemareavailable.
SUCCESSFULSUBMISSIONS
ReadproblemsstatementsinMandarinChineseandRussian.
Chefisonavacationthesedays,sohisfriendChefzaistryingtosolveChef'severydaytasks.
User
Score Mem
Lang
Solution
fazal
100.000 2M
View
bhavaniab
100.000 2M
View
kri1311
100.000 2M
View
krish23493
100.000 2M
View
varun0402
100.000 2M
View
rohitlien5759
100.000 2M
View
tarojung
100.000 2M
View
rishabhkatiyar
100.000 2M
View
laksh007
100.000 2M
View
shubhangipri
100.000 2M
View
Output
hemang_sarkar
100.000 2M
View
For each test case, output a single line containing minimum number of operations Chefza has to
performinordertosetupthemachine.
neeraj19
100.000 2M
View
Today's task is to make a sweet roll. Rolls are made by a newly invented cooking machine. The
machineisprettyuniversalitcanmakelotsofdishesandChefzaisthrilledaboutthis.
Tomakearoll,Chefzahastosetallthesettingstospecifiedintegervalues.Therearelotsofsettings,
eachofthemsettosomeinitialvalue.Themachineisprettycomplexandthereisalotofcookingtobe
donetoday,soChefzahasdecidedtouseonlytwoquickwaystochangethesettings.Inaunitoftime,
hecanpickonesetting(let'ssayitscurrentvalueisv)andchangeitinoneofthefollowingways.
Ifviseven,changethissettingtov/2.Ifvisodd,changeitto(v1)/2.
Changesettingto2v
Thereceiptisgivenasalistofintegervaluesthesettingsshouldbesetto.Itisguaranteedthateach
destinationsettingcanberepresentedasanintegerpowerof2.
SinceChefzahasjustchangedhisprofession,hehasalotofotherthingstodo.Pleasehelphimfind
theminimumnumberofoperationsneededtosetupaparticularsettingofthemachine.Youcanprove
thatitcanbedoneinfinitetime.
Input
ThefirstlineoftheinputcontainsanintegerTdenotingthenumberoftestcases.ThedescriptionofT
testcasesfollows.
TheonlylineofeachtestcasecontainstwointegersAandBdenotingtheinitialanddesiredvaluesof
thesetting,respectively.
Constraints
1of28
1T200
1A107
1B107 ,andBisanintegerpowerof2
HELP
Subtasks
Subtask#1[40points]:A100andB100
Subtask#2[60points]:Noadditionalconstraints
Example
Input:
6
11
24
38
416
41
14
Output:
0
1
4
2
2
2
Explanation
Inthefirsttestcase,youdon'tneedtodoanything.
https://www.codechef.com/problems/COOKMACH
1/3
8/27/2015
CookingMachine|CodeChef
Inthesecondtestcase,youneedtomultiply2by2andget4.Thisisdonein1operation.
Inthethirdtestcase,youneedtoobtain1from3andthenmultiplyitby2threetimestoobtain8.
Atotalof4operations.
Inthefourthtestcase,multiply4by2twice.
Inthefifthtestcase,divide4by2twice.
Inthesixthtestcase,multiply1by2twice.
Author:
cenadar
Tester:
laycurse
Editorial
http://discuss.codechef.com/problems/COOKMACH
Tags
cenadar
DateAdded: 26052015
TimeLimit:
1sec
SourceLimit: 50000Bytes
Languages:
ADA,ASM,BASH,BF,C,C99strict,CAML,CLOJ,CLPS,CPP4.3.2,CPP4.9.2,CPP14,
CS2,D,ERL,FORT,FS,GO,HASK,ICK,ICON,JAVA,JS,LISPclisp,LISPsbcl,LUA,
NEM,NICE,NODEJS,PASfpc,PASgpc,PERL,PERL6,PHP,PIKE,PRLG,PYPY,
PYTH,PYTH3.1.2,RUBY,SCALA,SCMchicken,SCMguile,SCMqobi,ST,TCL,TEXT,
WSPC
SUBMIT
Comments
tausif000@18Aug201505:40AM
soundsbinary
deepak12yadav@18Aug201512:59PM
WHATISWRONGINTHISPROGRAM?ITISGIVINGTHEDESIRABLEOUTPUT.#includemain(){
int T,A,B,d=0,i scanf(" %d",&T) for(i=1i<=Ti=i+1) { scanf(" %d %d",&A,&B) while(B!=A) {
if(A%2==0||A==1){if(B>A){A*=2d++}else{A/=2d++}}else{A=(A1)/2d++}}printf("%dn",d)
}}
rohitlien5759@18Aug201511:43PM
@deepak12yadavtestursolutionforA=6andB=16
gauravrana3450@19Aug201503:44PM
pleasedescribehowtocode.injava
somyasr7@19Aug201507:48PM
myprogramgivesaruntimeerror..whatshouldido?
hitman333@20Aug201505:39PM
whyitisshowingruntimeerror
hitman333@20Aug201510:13PM
https://ideone.com/D7Oqy5checkmycodeatthislink,outputiscorrect..thenwhyonsubmittingits
showingwronganswer...plzzzreply
Needhelp?Postacomment.Butbeforethatpleasespareamomenttoreadtheguidelines.
Yourname:
sumer098
Comment:*
Save
https://www.codechef.com/problems/COOKMACH
2/3
8/27/2015
CookingMachine|CodeChef
CodeChefisanoncommercialcompetitiveprogrammingcommunity
Thetimenowis:12:58:30AM
YourIp:125.20.9.248
CodeChefAPlatformforAspiringProgrammers
CodeChefwascreatedasaplatformtohelpprogrammersmakeitbigintheworldofalgorithms,computerprogrammingandprogrammingcontests.AtCodeChefweworkhardto
revivethegeekinyoubyhostingaprogrammingcontestatthestartofthemonthandanothersmallerprogrammingchallengeinthemiddleofthemonth.Wealsoaimtohave
trainingsessionsanddiscussionsrelatedtoalgorithms,binarysearch,technicalitieslikearraysizeandthelikes.Apartfromprovidingaplatformforprogrammingcompetitions,
CodeChefalsohasvariousalgorithmtutorialsandforumdiscussionstohelpthosewhoarenewtotheworldofcomputerprogramming.
PracticeSectionAPlacetohoneyour'ComputerProgrammingSkills'
Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+
programminglanguages.Preparingforcodingcontestswereneverthismuchfun!Receivepoints,andmoveupthroughtheCodeChefranks.Useourpracticesectiontobetterprepare
yourselfforthemultipleprogrammingchallengesthattakeplacethroughoutthemonthonCodeChef.
CompeteMonthlyProgrammingContestsandCookoffs
Hereiswhereyoucanshowoffyourcomputerprogrammingskills.Takepartinour10daylongmonthlycodingcontestandtheshorterformatCookoffcodingcontest.Putyourself
upforrecognitionandwingreatprizes.OurprogrammingcontestshaveprizesworthuptoINR20,000(forIndianCommunity),$700(forGlobalCommunity)andlotsmoreCodeChef
goodiesupforgrabs.
ProgrammingTools
PracticeProblems
Initiatives
OnlineIDE
Easy
GoforGold
UpcomingCodingContests
Medium
CodeChefforSchools
ContestHosting
Hard
CampusChapters
ProblemSetting
Challenge
CodeChefTutorials
Peer
CodeChefWiki
School
FAQ's
https://www.codechef.com/problems/COOKMACH
3/3