游游拿到了一个正整数,她希望找到一对正整数,满足最小,且都不等于,感叹号表示阶乘。你能帮帮她吗?
区块链毕设网qklbishe.com为您提供问题的解答
游游拿到了一个正整数,她希望找到一对正整数,满足最小,且都不等于,感叹号表示阶乘。你能帮帮她吗?
import math
def find_xy(n):
if n == 2:
return 1, 1
min_diff = float(‘inf’)
best_x, best_y = –1, –1
for x in range(3, 15):
x_factorial = math.factorial(x)
y_approx = n // (x_factorial – 1)
for y in range(max(1, y_approx – 10), y_approx + 10):
diff = abs(x_factorial * y – y – n)
if diff == 0 and x!=2 and y!=2:
return x,y
if diff < min_diff and x!=2 and y!=2:
min_diff = diff
best_x, best_y = x, y
if x_factorial > n and min_diff < float(‘inf’):
break
return best_x, best_y
if __name__ == "__main__":
n = int(input().strip())
x, y = find_xy(n)
print(x, y)
56:07
以上就是关于问题游游拿到了一个正整数,她希望找到一对正整数,满足最小,且都不等于,感叹号表示阶乘。你能帮帮她吗?的答案
欢迎关注区块链毕设网-
web3一级市场套利打新赚钱空投教程
区块链NFT链游项目方科学家脚本开发培训