Python使逻辑运算符短路.例如:
if False and Condition2:
#condition2 won't even be checked because the first condition is already false.
Run Code Online (Sandbox Code Playgroud)
有没有办法阻止这种行为.我希望它检查两个条件,然后执行和操作(如c,c ++等).当我们与条件一起执行某些操作时,它很有用.例如:
if a < p.pop() and b < p.pop():
Run Code Online (Sandbox Code Playgroud)
一种方法是先检查条件,然后比较布尔值.但这会浪费记忆力.
我使用的公式是“两个数的乘积等于它们的 GCD 和 LCM 的乘积”。
这是我的代码:
# Uses python3
import sys
def hcf(x, y):
while(y):
x, y = y, x % y
return x
a,b = map(int,sys.stdin.readline().split())
res=int(((a*b)/hcf(a,b)))
print(res)
Run Code Online (Sandbox Code Playgroud)
它适用于小数字。但是当我输入时:
输入:226553150 1023473145
我的输出:46374212988031352
正确输出:46374212988031350
谁能告诉我我哪里错了?