a,b=input("输入区间a,b:").split(",") a,b=int(a),int(b) if a>b: a,b=b,a d={} for i in range(a,b+1): c=0 n=i while n!=1: s=0 L=list(str(n)) for x in L: s=s+(int(x))**2 n=s c=c+1 if c>2000: break else: d[i]=c print(d) Lc=list(d.values()) print("平均计算次数",sum(Lc)/len(Lc))