~cpp
def TreeNPlusOne(aNumber, aMin, aMax, aBinaryMap):
count = 1
while(aNumber != 1):
if(IsInRange(aMin, aMax, aNumber) and aBinaryMap[aNumber-aMin]):
aBinaryMap[aNumber-aMin] = False
if(aNumber%2 == 0):
aNumber = aNumber/2
else:
aNumber = aNumber*3+1
count = count + 1
return count
def InputRange():
min, max = input('최소, 최대: ')
while IsCorrectInput(min, max) == False:
min, max = input('최소, 최대: ')
return min, max
def MakeBinaryMap(aMin, aMax):
rangeOfMap = aMax - aMin + 1
binaryMap = range(rangeOfMap)
for i in range(rangeOfMap):
binaryMap[i] = True
return binaryMap
def FindMaxCycleLength(aMin, aMax, aBinaryMap):
maxCycleLength = 0
for i in range(aMin, aMax+1):
if(aBinaryMap[i-aMin]):
cycleLength = TreeNPlusOne(i, aMin, aMax, aBinaryMap)
if(maxCycleLength < cycleLength):
maxCycleLength = cycleLength
return maxCycleLength
def OutputResult(aMin, aMax, aMaxCycleLength):
print aMin, aMax, aMaxCycleLength
def IsInRange(aMin, aMax, aNumber):
if(aMin <= aNumber and aMax >= aNumber):
return True
else:
return False
def PreInspection(aMin, aMax, aBinaryMap):
for i in range(aMin, aMax/2+1):
tempI = i
while(IsInRange(aMin, aMax, 2*tempI)):
aBinaryMap[tempI-aMin] = False
tempI = 2*tempI
def IsCorrectInput(aMin, aMax):
if(aMin > 0 and aMax < 1000000 and aMin < aMax):
return True
else:
print 'Not Accept'
return False
if __name__ == '__main__':
min, max = InputRange()
binaryMap = MakeBinaryMap(min, max)
PreInspection(min, max, binaryMap)
OutputResult(min, max, FindMaxCycleLength(min, max, binaryMap))