对于较大的输入,例如x = 23,执行代码时需要花费很长时间!而y = 5 !!!!!代码的输出应该是x和y之间的比较。关于输入的一个小例子是,如果输入是3 !!,这意味着(3!)!)= 6! = 720.
def large()
t = int(input())
i = 0
fact_str = ""
fact_stry = ""
res, resy = 1, 1
counter = 0
countery = 0
while(i < t):
x = input()
y = input()
for char in x:
if char == '!' and counter == 0:
fact_str = int(fact_str)
for num in range(fact_str, 0, -1):
res = res * num
counter = counter + 1
elif counter > 0:
for num in range(res-1, 0, -1):
res = res * num
else:
fact_str = str(fact_str)
fact_str = fact_str + char
for chary in y:
if chary == '!' and countery == 0:
fact_stry = int(fact_stry)
for numy in range(fact_stry, 0, -1):
resy = resy * numy
countery = countery + 1
elif countery > 0:
for num in range(resy-1, 0, -1):
resy = resy * numy
else:
print("at esle", resy)
fact_stry = str(fact_stry)
fact_stry = fact_stry + chary
if len(str(x)) == len(str(fact_str)):
fact_str = int(fact_str)
x = fact_str
else:
x = res
if len(str(y)) == len(str(fact_stry)):
fact_stry = int(fact_stry)
y = fact_stry
else:
y = res
x = int(x)
y = int(y)
if x == y:
print("x=y")
elif x > y:
print("x>y")
else:
print("x<y")
i = i + 1
large()
可以优化此代码,以便在输入值较大时可以更快地执行吗?或者python仅限于较小的输入?