|
发表于 2019-9-26 17:13:04
|
显示全部楼层
import re
import math
import time
method = re.compile("[^0-9]")
def forma(miao):
tim = list()
ge_m = float("{:.10f}".format(miao))
ge_h = float("{:.10f}".format(ge_m / 3600))
ge_h_guo = float("{:.10f}".format(miao % 3600))
ge_f = float("{:.10f}".format(ge_h_guo / 60))
ge_miao = float("{:.10f}".format(ge_h_guo % 60))
if ge_h > 1:
tim.append(int(ge_h))
if ge_f > 1 or len(tim) != 0:
tim.append(int(ge_f))
tim.append(ge_miao)
return tim
da = int()
ran = input("请输入一个整数 , 求最大的质数因子:")
tex = method.search(ran)
if not tex:
ship = int(ran)#600851475143
chu = int(math.sqrt(ship))
time_start = time.perf_counter()
tiger_chu = sorted([each for each in range(chu , 0 , -1) if ship % each == 0] , reverse = True)
rabbit_zhi = [[car for car in range(2 , int(each)) if each % car == 0] for each in sorted(tiger_chu , reverse = True)]
da = tiger_chu[rabbit_zhi.index([])]
miao = time.perf_counter() - time_start
lai = forma(miao)
if len(lai) == 1:
print("最大值为:" + str(da) + "\n运行时间为:{:.2f}秒".format(lai[0]))
elif len(lai) == 2:
print("最大值为:" + str(da) + "\n运行时间为:{}分{}秒".format(lai[0] , lai[1]))
else:
print("最大值为:" + str(da) + "\n运行时间为:{}时{}分{}秒".format(lai[0] , lai[1] , lai[2]))
else:
print("您输入的数值运行不了~~")
#我感觉我的效率还不错,欢迎大家来copy~~ |
|