import sys h, w = [int(x) for x in input().split()] n = int(input()) d = [int(x) for x in input().split()] if (h % d[0]) or (w % d[0]): print("-1") sys.exit(0) current_cover = [0, 0] result = 0 for a in d[::-1]: new_to_add_x = (h - current_cover[0]) // a new_to_add_y = (w - current_cover[1]) // a result += new_to_add_x * new_to_add_y result += (current_cover[0] // a) * new_to_add_y result += (current_cover[1] // a) * new_to_add_x current_cover[0] += new_to_add_x * a current_cover[1] += new_to_add_y * a print(result)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import sys h, w = [int(x) for x in input().split()] n = int(input()) d = [int(x) for x in input().split()] if (h % d[0]) or (w % d[0]): print("-1") sys.exit(0) current_cover = [0, 0] result = 0 for a in d[::-1]: new_to_add_x = (h - current_cover[0]) // a new_to_add_y = (w - current_cover[1]) // a result += new_to_add_x * new_to_add_y result += (current_cover[0] // a) * new_to_add_y result += (current_cover[1] // a) * new_to_add_x current_cover[0] += new_to_add_x * a current_cover[1] += new_to_add_y * a print(result) |