往年题:
实习中遇到的一道题:
自己有问题的代码:
import sys def main(argv): # このコードは引数と標準出力を用いたサンプルコードです。 # このコードは好きなように編集・削除してもらって構いません。 # --- # This is a sample code to use arguments and outputs. # Edit and remove this code as you like. argv = [int(i) for i in argv] start = argv[0] end = argv[1] m = argv[2] nums = argv[3:] length = end - start + 1 result = [0]*len(nums) for k in range(len(nums)): k1 = start//nums[k] k2 = end//nums[k] result[k] = k2-k1 return length-loop(m, result, nums, start, end) def loop(m, result, nums, start, end): if m == 1: return max(result) else: m -= 1 list1 = [] for i in range(len(result)): for j in range(i+1, len(result)): a = end//(nums[i]*nums[j]) b = start//(nums[i]*nums[j]) list1.append(result[i] + result[j] - a+b) return loop(m, list1) if __name__ == '__main__': print(main(sys.argv[1:]))