#39231: python 利用lista[i]存取計算過的數值


mu0975353917@gmail.com (Moon Chan)

學校 : 國立雲林科技大學
編號 : 188583
來源 : [36.235.71.91]
最後登入時間 :
2024-04-28 23:39:27
c039. 00100 - The 3n + 1 problem -- UVa100 | From: [123.192.202.177] | 發表日期 : 2024-01-24 22:08

a = [1]*1000000


def w(i):
if i == 1:
return 1
elif i % 2 != 0:
result = 1 + w(3 * i + 1)
return result
else:
result = 1 + w(i // 2)
return result


while True:
try:
m = 0 # 記最大的
c = 1 # 計算次數
d, b = map(int, input().split())
cycle_length = []
print(d, b, end=" ")
temp = 0
for i in range(min(d, b), max(d, b)+1):
if a[i] > 1:
if a[i] > temp:
temp = a[i]
continue
count = 0
a[i] = w(i) # w[22]=9 將9存入a[22]
if a[i] > temp:
temp = a[i]
print(temp)
# print(a)
except:
break
 
ZeroJudge Forum