美团数据研发岗位8.15
最后一个专项编程题没时间提交了,也不知道答案对不对,放上来,如果有ac了的可以互相讨论哟
import sys if __name__ == "__main__": n, m = map(int, sys.stdin.readline().strip().split()) count = 0 res = [] def dfs(x, tmp): if len(tmp) == m: res.append(tmp.copy()) global count count += 1 return for i in range(x, n+1): if not tmp&nbs***bsp;i % tmp[-1] == 0: tmp.append(i) dfs(x, tmp) tmp.pop() dfs(1, []) # print(res) print(count)