- python
- 枚举 找规律
def main():
n, m = list(map(int, input().split()))
nums = []
for i in range(1000):
for j in range(1000):
num = n * i + m * j
nums.append(num)
res = 2
for i in range(2, 2000):
if i not in nums:
res = max(res, i)
print(res)
if __name__ == '__main__':
main()
- python
- dfs 打表找规律
# dfs 打表法找规律
def main():
n, m = list(map(int, input().split()))
#dfs暴搜
#给定k,看p, q能不能组合出来
def dfs(k, p, q):
if k == 0: return True
if k >= p and dfs(k-p, p, q): return True
if k >= q and dfs(k-q, p, q): return True
return False
res = 0
for i in range(1, 1000):
if dfs(i, n, m) == False:
res = i
print(res)
if __name__ == '__main__':
main()
python
# 规律:num = n * m - n - m
def main():
n, m = list(map(int, input().split()))
num = n * m - n - m
print(num)
if __name__ == '__main__':
main()