100 The 3n + 1 problem - UVa Online Judge
100 The 3n + 1 problem - UVa Online Judge
100 The 3n + 1 problem - UVa Online Judge
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
ProblemsinComputerScienceareoftenclassiedasbelongingtoacertainclassof<strong>problem</strong>s(e.g., Background NP,Unsolvable,Recursive).Inthis<strong>problem</strong>youwillbeanalyzingapropertyofanalgorithmwhose <strong>100</strong><strong>The</strong><strong>3n</strong>+1<strong>problem</strong> ACMContestProblemsArchive UniversityofValladolid(SPAIN)<br />
classicationisnotknownforallpossibleinputs. <strong>The</strong>Problem Considerthefollowingalgorithm: 1.inputn 2.printn 4. 3.ifn=1thenSTOP<br />
Itisconjecturedthatthealgorithmabovewillterminate(whena1isprinted)foranyintegralinput Giventheinput22,thefollowingsequenceofnumberswillbeprinted 5. 6.GOTO2 elsen ifnisoddthenn n=2221134175226134020105168421<br />
<strong>3n</strong>+1<br />
thanthis.) the1isprinted.Foragivennthisiscalledthecycle-lengthofn.Intheexampleabove,thecyclelength veried,however,forallintegersnsuchthat0
110 <strong>100</strong>200 201210 SampleInput ACMContestProblemsArchive UniversityofValladolid(SPAIN)<br />
11020 <strong>100</strong>200125 20121089 900<strong>100</strong>0174 900<strong>100</strong>0 SampleOutput