import math
import time
number = [int(input("请输入一个7位数:"))]
print(number)
t1 = time.time()
for i in number:
print(t1)
a = i % 10
b = i // 10 % 10
c = i // 100 % 10
d = i // 1000 % 10
e = i // 10000 % 10
f = i // 100000 % 10
g = i // 1000000
if (math.pow(a, 7) + math.pow(b, 7) + math.pow(c, 7) + math.pow(d, 7) + math.pow(e, 7) + math.pow(f, 7)
+ math.pow(g, 7)) == i:
print('该数为北斗七星数')
t2 = time.time()
break
else:
print('该数不是北斗七星数')
t2 = time.time()
t = t2 - t1
break
print(t2)
t = (t2 - t1)*1000
print("程序运行耗时为" +str(t)+"毫秒")
Python编写程序打印输出所有的北斗七星数,并输出程序运行时间。北斗七星数是一个7位数,它的每个位上的数字的7次幂之和等于它本身。例如:1741725=17+77+47+17+77+27+57
最新推荐文章于 2022-12-14 14:52:04 发布