And heres the algorithm in Python:
------------------------------------------------------
#ciclu
def ciclu(nr):
contor=0;
while nr!=1:
if nr%2==1:
nr=3*nr+1
else:
nr=nr/2
contor=contor+1
contor=contor+1
return contor
#parcurgere
def parcurgere(i,j):
n=0
maxim=ciclu(i)
for k in range (i+1,j):
n=ciclu(k)
if maxim<=n:
maxim=n
print(i,j,maxim)
#main
sw=1
while sw==1:
i=int(input())
j=int(input())
parcurgere(i,j)
print("Continue? 1=Yes 0=No")
sw=int(input())
------------------------------------------------------
0 comments:
Post a Comment